[英]flutter - How to keep user signed-in with Google
I have used Google Sign In to authenticate users with Firebase Auth, and I successfully get back my Firebase User.我已使用 Google Sign In 通过 Firebase Auth 对用户进行身份验证,并成功找回了我的 Firebase 用户。 I want to keep the user authenticated, when they come back to the app.
当他们回到应用程序时,我想保持用户的身份验证。 How can I do the same?
我怎样才能做同样的事情?
Users already stay authenticated.用户已经保持身份验证。 After you restart the app, Firebase reads the credentials from disk, and refreshes the user's token.
重新启动应用程序后,Firebase 从磁盘读取凭据,并刷新用户的令牌。 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.所以一定要
await _auth.currentUser()
以获取用户状态的通知。
Whenever I'm wondering how to do such things, I look at the FlutterFire sample app .每当我想知道如何做这些事情时,我都会查看FlutterFire 示例应用程序。 This specific line can be found here .
可以在此处找到此特定行。
是的,您需要执行auth.currentUser()
函数以保持用户身份验证,最好的部分是即使用户离线,该函数也能工作,这使得它非常通用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.