fix: improve server connection handling during authentication
- Updated AuthStateManager to clear the active server ID upon logout, ensuring a proper return to the server connection page. - Enhanced RouterNotifier to allow users to stay on the server connection page if authenticated, improving navigation flow. - Modified AuthenticationPage to navigate back to the server connection page instead of popping the navigation stack, enhancing user experience during server setup.
This commit is contained in:
@@ -562,6 +562,10 @@ class AuthStateManager extends _$AuthStateManager {
|
|||||||
await storage.clearAuthData();
|
await storage.clearAuthData();
|
||||||
_updateApiServiceToken(null);
|
_updateApiServiceToken(null);
|
||||||
|
|
||||||
|
// Clear active server to force return to server connection page
|
||||||
|
await storage.setActiveServerId(null);
|
||||||
|
ref.invalidate(activeServerProvider);
|
||||||
|
|
||||||
// Update state
|
// Update state
|
||||||
_update(
|
_update(
|
||||||
(current) => current.copyWith(
|
(current) => current.copyWith(
|
||||||
@@ -577,6 +581,10 @@ class AuthStateManager extends _$AuthStateManager {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
DebugLogger.error('logout-failed', scope: 'auth/state', error: e);
|
DebugLogger.error('logout-failed', scope: 'auth/state', error: e);
|
||||||
// Even if logout fails, clear local state
|
// Even if logout fails, clear local state
|
||||||
|
final storage = ref.read(optimizedStorageServiceProvider);
|
||||||
|
await storage.setActiveServerId(null);
|
||||||
|
ref.invalidate(activeServerProvider);
|
||||||
|
|
||||||
_update(
|
_update(
|
||||||
(current) => current.copyWith(
|
(current) => current.copyWith(
|
||||||
status: AuthStatus.unauthenticated,
|
status: AuthStatus.unauthenticated,
|
||||||
|
|||||||
@@ -87,10 +87,13 @@ class RouterNotifier extends ChangeNotifier {
|
|||||||
final authState = ref.read(authNavigationStateProvider);
|
final authState = ref.read(authNavigationStateProvider);
|
||||||
final connectivityService = ref.read(connectivityServiceProvider);
|
final connectivityService = ref.read(connectivityServiceProvider);
|
||||||
|
|
||||||
|
// Allow staying on server connection page
|
||||||
if (location == Routes.serverConnection) {
|
if (location == Routes.serverConnection) {
|
||||||
|
// If authenticated but on server connection page, go to chat
|
||||||
|
// Otherwise stay on server connection page (for back navigation)
|
||||||
return authState == AuthNavigationState.authenticated
|
return authState == AuthNavigationState.authenticated
|
||||||
? Routes.chat
|
? Routes.chat
|
||||||
: Routes.authentication;
|
: null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check connectivity status to determine if we should show connection issue
|
// Check connectivity status to determine if we should show connection issue
|
||||||
|
|||||||
@@ -205,7 +205,7 @@ class _AuthenticationPageState extends ConsumerState<AuthenticationPage> {
|
|||||||
children: [
|
children: [
|
||||||
ConduitIconButton(
|
ConduitIconButton(
|
||||||
icon: Platform.isIOS ? CupertinoIcons.back : Icons.arrow_back,
|
icon: Platform.isIOS ? CupertinoIcons.back : Icons.arrow_back,
|
||||||
onPressed: () => Navigator.pop(context),
|
onPressed: () => context.go(Routes.serverConnection),
|
||||||
tooltip: AppLocalizations.of(context)!.backToServerSetup,
|
tooltip: AppLocalizations.of(context)!.backToServerSetup,
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
|
|||||||
Reference in New Issue
Block a user