flutter - How to keep user signed-in with Google
Solution 1
Users already stay authenticated. After you restart the app, Firebase reads the credentials from disk, and refreshes the user's token. Since this requires a roundtrip to the server, it happens asynchronously. So be sure to await _auth.currentUser()
to get notified of the user's status.
Whenever I'm wondering how to do such things, I look at the FlutterFire sample app. This specific line can be found here.
Solution 2
Yes you need to do the auth.currentUser()
function in order to keep users authenticated and the best part is that this function will work even if the user is offline, which makes it very versatile.
Comments
-
Ayush Shekhar over 1 year
I have used Google Sign In to authenticate users with Firebase Auth, and I successfully get back my Firebase User. I want to keep the user authenticated, when they come back to the app. How can I do the same?
-
alter123 over 4 yearsit looks live developers have removed several packages from the plugins repository, along with FlutterFire at a certain commit. All those packages were great resources to refer the implementation.
-
Frank van Puffelen over 4 yearsThe packages were moved to a new location: github.com/FirebaseExtended/flutterfire
-
chitgoks over 4 yearsi have this line but unfortunately, using the token in for example Google Drive APIs wont work.