[英]Does firebase store current user data automatically on phone in flutter?
I just saw a tutorial, where the author although was using shared-ref to store the user name, email etc locally, but he didn't use anything to store currentUser on a flutter app, which was connected to firebase.我刚刚看到一个教程,作者虽然在本地使用 shared-ref 来存储用户名,email 等,但是他没有使用任何东西来将 currentUser 存储在 flutter 应用程序上,该应用程序连接到 ZBF12E1515C25C7D8C0352F1413AB9。 and hence in splash screen, he used if currentUser,= null, then goto Home Screen.
因此在初始屏幕中,他使用 if currentUser,= null,然后转到主屏幕。 and it worked fine on restarting the app, hence to log out.
并且在重新启动应用程序时效果很好,因此可以注销。 again he used firebaseAuth.signOut(), so?
他再次使用了firebaseAuth.signOut(),所以呢? does firebase stores currentUser automatically on the local storage of the app?
firebase 是否将 currentUser 自动存储在应用程序的本地存储中?
I don't think it's stored locally in terms of shared preferences/ user defaults.我不认为它是根据共享偏好/用户默认值存储在本地的。 I had an issue where without logging out, but uninstalling and reinstalling the app resulted in the app already knowing who I was.
我有一个问题,没有注销,但卸载并重新安装应用程序导致应用程序已经知道我是谁。 Turns out, it was stored in keychain (on iOS, I don't know the android counterpart).
原来,它存储在钥匙串中(在 iOS 上,我不知道 android 对应物)。 See this answer for more detail on my particular understanding of how firebase saves the user:
有关我对 firebase 如何节省用户的特殊理解的更多详细信息,请参阅此答案:
https://stackoverflow.com/a/69621552/12132021 https://stackoverflow.com/a/69621552/12132021
Firebase Authentication SDKs store the credentials of the user in local storage, and then restore the user from there when the app restarts/page reloads. Firebase 身份验证 SDK 将用户的凭据存储在本地存储中,然后在应用程序重新启动/页面重新加载时从那里恢复用户。
Note that this doesn't always means that currentUser != null
will work on app startup/page load, as restoring the credentials requires an asynchronous call to the server and currentUser
will be null
until that call completes.请注意,这并不总是意味着
currentUser != null
将在应用程序启动/页面加载时起作用,因为恢复凭据需要对服务器进行异步调用,并且currentUser
将是null
直到该调用完成。 For the best results listen/respond to authStateChanges
as shown in the documentation on authentication state .为了获得最佳结果,请收听/响应
authStateChanges
,如身份验证 state文档中所示。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.