From b41497090488dced66854bd9198222a49f0995bf Mon Sep 17 00:00:00 2001 From: Sharjeel Yunus Date: Thu, 13 Aug 2026 01:29:35 +0500 Subject: [PATCH] feat(auth_manager): enhance user session management by storing provider information and refining sign-in checks --- modules/auth/lib/signin/auth_manager.dart | 39 +++++++---------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/modules/auth/lib/signin/auth_manager.dart b/modules/auth/lib/signin/auth_manager.dart index 3aaeaa7d3..9a14f8a1a 100644 --- a/modules/auth/lib/signin/auth_manager.dart +++ b/modules/auth/lib/signin/auth_manager.dart @@ -200,6 +200,8 @@ class AuthManager with UserAuthentication { Future updateCurrentFirebaseUser(BuildContext context, User newUser) async { await StorageManager() .writeToSystemStorage(UserAuthentication._idKey, newUser.uid); + await StorageManager().writeToSystemStorage( + UserAuthentication._providerKey, SignInProvider.firebase.name); await StorageManager() .writeToSystemStorage(UserAuthentication._isAnonymous, newUser.isAnonymous); } @@ -325,33 +327,6 @@ class AuthManager with UserAuthentication { /// check if the user is current signed in or not. Future isSignedIn() { return getSignedInUser().then((user) => user != null); - - // AuthenticatedUser? user = getCurrentUser(); - // if (user != null) { - // // use the Provider to check sign in status - // if (user.provider == SignInProvider.firebase) { - // if (customFirebaseApp != null) { - // return Future.value( - // FirebaseAuth.instanceFor(app: customFirebaseApp!).currentUser != - // null); - // } - // } else if (user.provider == SignInProvider.auth0) { - // return Future.value(Auth0CredentialsManager().hasCredentials()); - // } - // - // // fallback to using the client to check for status - // if (user.client == SignInClient.google) { - // return GoogleAuthManager().isSignedIn(); - // } else if (user.client == SignInClient.apple) { - // // nothing to do - // } else if (user.client == SignInClient.microsoft) { - // // TODO - // } - // - // // TODO: we have the current user in memory, does that mean signed in still? - // return Future.value(true); - // } - // return Future.value(false); } Future getSignedInUser() async { @@ -360,6 +335,16 @@ class AuthManager with UserAuthentication { if (user.client == SignInClient.google) { return _getSignedInUserFromGoogle(user.provider); } + // Storage can outlive the Firebase session — confirm Auth still has a user. + if (user.provider == SignInProvider.firebase || + (user.provider == null && user.client == null)) { + final app = customFirebaseApp ?? + (Firebase.apps.isNotEmpty ? Firebase.apps.first : null); + if (app == null || + FirebaseAuth.instanceFor(app: app).currentUser == null) { + return null; + } + } } return user; }