flutter - 如何让用户登录 Google [英] flutter - How to keep user signed-in with Google
问题描述
我已使用 Google Sign In 通过 Firebase Auth 对用户进行身份验证,并且成功找回了我的 Firebase 用户.当他们回到应用程序时,我想保持用户的身份验证.我怎样才能做同样的事情?
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?
推荐答案
用户已通过身份验证.重新启动应用程序后,Firebase 从磁盘读取凭据,并刷新用户的令牌.由于这需要到服务器的往返,所以它是异步发生的.所以一定要await _auth.currentUser()
以获得用户状态的通知.
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.
每当我想知道如何做这些事情时,我都会查看 FlutterFire 示例应用.可以在此处找到此特定行.
Whenever I'm wondering how to do such things, I look at the FlutterFire sample app. This specific line can be found here.
这篇关于flutter - 如何让用户登录 Google的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!