I have a Flutter Web App where the user is logged in via Firebase. The Problem is that every time the page is refreshed, the user is logged out.
Similiar for iOS: User stays logged in after refresh but is being logged out when completely closing the app.
I know there is this issue which says that it should be fixed with the latest version, but I am already on the supposedly fixed version:
firebase_core: ^1.20.0
firebase_auth: ^3.6.0
cloud_firestore: ^3.4.1
I am using the go_router and redirect the user if he is not logged in:
final GoRouter router = GoRouter(
key: Get.key,
urlPathStrategy: UrlPathStrategy.path,
redirect: (state) {
final String destination = state.location;
final bool isOnStartView = destination == '/start';
final bool isOnEmailFlow = state.subloc.contains('/email');
if (!isOnStartView && !isOnEmailFlow && !AuthService.isLoggedIn()) {
return '/start';
}
return null;
},
...
And this is my AuthService.isLoggedIn():
static final FirebaseAuth _firebaseAuth = FirebaseAuth.instance;
static User? get currentUser => FirebaseAuth.instance.currentUser;
static bool isLoggedIn() {
return _firebaseAuth.currentUser != null;
}
What am I missing here? It says everywhere that it should be fixed but it's not working for me.. Let me know if you need any more details!