Issue
Here’s a basic code for sign-in using firebase phone authentication, which can be understood from basic flutter-fire documentation, which doesn’t explain practically how to implement firebase phone authentication in flutter web. Flutter Native mobile phone authentication is easy 🙂
Also, how to remember the signed user for certain days?
FirebaseAuth auth = FirebaseAuth.instance;
ConfirmationResult confirmationResult = await auth.signInWithPhoneNumber('+44 7123 123 456');
UserCredential userCredential = await confirmationResult.confirm('123456');
Solution
Users automatically stay signed in to Firebase. To pick up the user’s authentication state when the app is restarted, check the documentation on authentication state, which has this handy example:
FirebaseAuth.instance
.authStateChanges()
.listen((User user) {
if (user == null) {
print('User is currently signed out!');
} else {
print('User is signed in!');
}
});
Also see the answer I just gave to: Anonymous User not detecting by firebase code error
Answered By – Frank van Puffelen
Answer Checked By – Mildred Charles (FlutterFixes Admin)