From 7387e285a00c187d12289dce489bbf99128fd968 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 2 Jul 2025 22:48:53 +0200 Subject: [PATCH] Fix missing redirect after login --- moneymgr_mobile/lib/providers/auth_state.dart | 5 +++-- .../lib/routes/login/manual_auth_screen.dart | 12 +++++++++--- moneymgr_mobile/lib/services/router/router.dart | 2 +- moneymgr_mobile/lib/services/router/routes_list.dart | 5 ++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/moneymgr_mobile/lib/providers/auth_state.dart b/moneymgr_mobile/lib/providers/auth_state.dart index 4979bcf..c1c24d8 100644 --- a/moneymgr_mobile/lib/providers/auth_state.dart +++ b/moneymgr_mobile/lib/providers/auth_state.dart @@ -1,10 +1,11 @@ import 'package:moneymgr_mobile/services/api/api_client.dart'; import 'package:moneymgr_mobile/services/api/api_token.dart'; import 'package:moneymgr_mobile/services/api/auth_api.dart'; -import 'package:moneymgr_mobile/services/router/routes_list.dart'; import 'package:moneymgr_mobile/services/storage/secure_storage.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart'; +import '../services/router/routes_list.dart'; + part 'auth_state.g.dart'; /// The current authentication state of the app. @@ -27,7 +28,7 @@ class CurrentAuthState extends _$CurrentAuthState { await ApiClient(token: token).authInfo(); final secureStorage = ref.read(secureStorageProvider).requireValue; - secureStorage.setToken(token); + await secureStorage.setToken(token); ref // Invalidate the state so the auth state will be updated to authenticated. diff --git a/moneymgr_mobile/lib/routes/login/manual_auth_screen.dart b/moneymgr_mobile/lib/routes/login/manual_auth_screen.dart index 23db5b9..47f55e0 100644 --- a/moneymgr_mobile/lib/routes/login/manual_auth_screen.dart +++ b/moneymgr_mobile/lib/routes/login/manual_auth_screen.dart @@ -1,11 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_gutter/flutter_gutter.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; +import 'package:go_router/go_router.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:logging/logging.dart'; +import 'package:moneymgr_mobile/providers/auth_state.dart'; import 'package:moneymgr_mobile/routes/login/base_auth_page.dart'; import 'package:moneymgr_mobile/services/api/api_token.dart'; -import 'package:moneymgr_mobile/providers/auth_state.dart'; +import 'package:moneymgr_mobile/services/router/routes_list.dart'; import 'package:moneymgr_mobile/utils/extensions.dart'; import 'package:moneymgr_mobile/widgets/app_button.dart'; @@ -29,6 +31,11 @@ class ManualAuthScreen extends HookConsumerWidget { tokenValue: tokenValueController.text, ), ); + + if (context.mounted) { + if (context.canPop()) context.pop(); + context.replace(profilePage); + } } catch (e, s) { Logger.root.severe("Failed to authenticate user! $e $s"); if (context.mounted) { @@ -51,8 +58,7 @@ class ManualAuthScreen extends HookConsumerWidget { keyboardType: TextInputType.url, decoration: const InputDecoration( labelText: 'API URL', - helperText: - "Format: http://moneymgr.corp.com/api", + helperText: "Format: http://moneymgr.corp.com/api", ), textInputAction: TextInputAction.next, ), diff --git a/moneymgr_mobile/lib/services/router/router.dart b/moneymgr_mobile/lib/services/router/router.dart index d25631f..752b420 100644 --- a/moneymgr_mobile/lib/services/router/router.dart +++ b/moneymgr_mobile/lib/services/router/router.dart @@ -47,7 +47,7 @@ GoRouter router(Ref ref) { ], ), NavigationItem( - path: '/profile', + path: profilePage, body: (_) => const Text("Profile"), icon: Icons.person_outline, selectedIcon: Icons.person, diff --git a/moneymgr_mobile/lib/services/router/routes_list.dart b/moneymgr_mobile/lib/services/router/routes_list.dart index dc0b12e..c18f6a3 100644 --- a/moneymgr_mobile/lib/services/router/routes_list.dart +++ b/moneymgr_mobile/lib/services/router/routes_list.dart @@ -8,4 +8,7 @@ const authPage = "/login"; const manualAuthPage = "/login/manual"; /// Settings path -const settingsPage = "/settings"; \ No newline at end of file +const settingsPage = "/settings"; + +// Profile path +const profilePage = "/profile"; \ No newline at end of file