From 521924b3a493f837dffb2bbb4e4b6986f2317808 Mon Sep 17 00:00:00 2001 From: Dmitry Date: Sun, 20 Sep 2026 10:46:40 +0300 Subject: [PATCH] =?UTF-8?q?fix(app):=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B0=20=D1=81=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=86=D1=8B=20=D0=B2=D0=BE=D0=B7=D0=B2=D1=80?= =?UTF-8?q?=D0=B0=D1=89=D0=B0=D0=B5=D1=82=20=D0=BD=D0=B0=20=D0=BE=D1=82?= =?UTF-8?q?=D0=BA=D1=80=D1=8B=D1=82=D1=8B=D0=B9=20=D1=8D=D0=BA=D1=80=D0=B0?= =?UTF-8?q?=D0=BD,=20=D0=B0=20=D0=BD=D0=B5=20=D0=BD=D0=B0=20=D0=B3=D0=BB?= =?UTF-8?q?=D0=B0=D0=B2=D0=BD=D1=83=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Пока сессия восстанавливается, адрес запоминается в /login?from=…, после входа роутер возвращает на него. Принимаются только пути внутри приложения. --- app/lib/router.dart | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/app/lib/router.dart b/app/lib/router.dart index cebfefd..9048991 100644 --- a/app/lib/router.dart +++ b/app/lib/router.dart @@ -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((ref) { final auth = ValueNotifier(ref.read(authControllerProvider)); ref.listen(authControllerProvider, (_, next) => auth.value = next); @@ -38,9 +44,19 @@ final routerProvider = Provider((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: [