如何清除Firebase签名的先前用户数据?

发布于 2025-02-09 17:45:45 字数 301 浏览 1 评论 0原文

如果我以用户的身份登录,然后使用

  Future<void> _signOut() async {
    await FirebaseAuth.instance.signOut();
  }

以其他用户为单位登录,但它仍然显示以前的用户凭据。

有没有办法清除登录时的缓存,以免发生这种情况?

我有针对不同用户的特定用户页面,因此不可能登录以前的用户非常重要。如果我登录并点击vscode,然后登录,那么它不会登录其他用户并正确登录,因此我认为这绝对是缓存中的某些东西,尽管登录了。

If I sign in as a user, and then log out using

  Future<void> _signOut() async {
    await FirebaseAuth.instance.signOut();
  }

but then log back in as a different user, it still shows the previous users credentials.

Is there a way to clear cache on log out so this cannot happen?

I have specific user pages for different users so it's really important that it isn't possible to sign in as the previous user. If I sign out and hit restart on vscode and then log in then it doesn't log in as the other user, and logs in correctly, so I think it's definitely something being held in the cache and carrying over despite logging out.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

牵你手 2025-02-16 17:45:45

为了显示有关登录用户的正确信息,您可以使用firebaseauth.instance.authstatechanges() stream,更多信息此处。每次验证状态更改时,例如,当调用firebaseauth.instance.signout();时,该流将发出一个新事件,如果未签署用户,则使用已登录的用户或null发出新事件。然后,您可以相应地更新您的UI。

In order to display the correct information about the logged in user, you could use the FirebaseAuth.instance.authStateChanges() stream, more info here. Every time the auth state changes, for instance when calling FirebaseAuth.instance.signOut();, the stream will emit a new event with either the logged in user or null if the user is not signed in. You can then update your UI accordingly.

萌面超妹 2025-02-16 17:45:45

好吧,我有同样的问题。如果您在每个步骤中打印用户凭据,您将看到您正在从Firebase Auth中获得正确的用户。但是,如果您使用的是提供商,那么当您再次登录时,提供商将不会更新。为了解决这个问题,我使用了StreamBuilder小部件。

StreamBuilder(
stream: FirebaseFirestore.instance.collection("users").doc(FirebaseAuth.instance.currentUser!.uid).snapshots(),
builder: (context, snapshot){
    // return something based on what you get..
  }
)

Well, I was having kinda the same problem. If you print user credentials in every step, you will see you are getting right user from Firebase Auth. But, if you are using provider, the providers are not being updated when you are loggin in again. To solve this, I used the StreamBuilder widget.

StreamBuilder(
stream: FirebaseFirestore.instance.collection("users").doc(FirebaseAuth.instance.currentUser!.uid).snapshots(),
builder: (context, snapshot){
    // return something based on what you get..
  }
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文