fix(app): перезагрузка страницы возвращает на открытый экран, а не на главную

Пока сессия восстанавливается, адрес запоминается в /login?from=…, после входа роутер возвращает на него. Принимаются только пути внутри приложения.
This commit is contained in:
Dmitry
2026-09-20 10:46:40 +03:00
parent 2645e56197
commit 521924b3a4
+18 -2
View File
@@ -26,6 +26,12 @@ import 'features/shell/app_shell.dart';
import 'features/tax/tax_page.dart';
import 'features/transactions/transactions_page.dart';
/// Where to go after signing in: the page the user was on, if `from` is an in-app path.
String _returnTo(String? from) {
final inApp = from != null && from.startsWith('/') && !from.startsWith('//');
return inApp && !from.startsWith('/login') ? from : '/';
}
final routerProvider = Provider<GoRouter>((ref) {
final auth = ValueNotifier<AuthState>(ref.read(authControllerProvider));
ref.listen(authControllerProvider, (_, next) => auth.value = next);
@@ -38,9 +44,19 @@ final routerProvider = Provider<GoRouter>((ref) {
final status = auth.value.status;
final atLogin = state.matchedLocation == '/login';
return switch (status) {
AuthStatus.unknown => atLogin ? null : '/login',
// A reload starts here while the stored session is still being restored: the address
// is kept in `from` so signing back in lands on it instead of on the home page. A
// deliberate sign-out is `signedOut` from the start and carries no `from`.
AuthStatus.unknown =>
atLogin
? null
: Uri(
path: '/login',
queryParameters: {'from': state.uri.toString()},
).toString(),
AuthStatus.signedOut => atLogin ? null : '/login',
AuthStatus.signedIn => atLogin ? '/' : null,
AuthStatus.signedIn =>
atLogin ? _returnTo(state.uri.queryParameters['from']) : null,
};
},
routes: [