I’m trying to do that using firebase ui auth. But initially trying to get it working just using signInWithEmailPassword().
It seems like I can use SharedPreferences to save email and password after FirebaseAuth.instance.signInWithEmailAndPassword(), but how would I feed that back since the app listens to FirebaseAuth.instance.authStateChanges()?
2
Answers
Firebase Authentication, by design, requires an internet connection to authenticate users since it relies on the Firebase server to validate the user’s credentials. So, it is not possible to re-login without an internet connection using FirebaseAuth.
However, you can implement offline authentication using a custom solution. One common approach is to use a secure local storage to store a token or a flag indicating the user’s authentication state.
Create a custom authentication state stream that combines the Firebase auth state with your local storage’s auth state. This way, your app can still listen to auth state changes and work seamlessly with both online and offline authentication.
Example:
To stay logged in till you logout by your self, you have to check that is the user logged in before or not on your Splash Screen or LoginPage.
First, enable Firebase Authentication Persistence inside your main() void:
After that make a bool variable to check the User State:
Then, Add this to your initState() void to check if the User is authenticated on app launch or page initial:
and Finally, use the bool as a condition before your Pages Widget:
That’s way to check a user to see if he/she logged in or not, I use this way for a long time hope it helps you well…
and for using your app without internet you and use this:
and check this link to see more about it, it’s very useful for me 😉
The Link of Access data offline
StaySafe