简体   繁体   English

如何在flutter应用程序中使用相同的firebase匿名用户

[英]How to use the same firebase anonymous user in a flutter app

I'm currently developing a Flutter app for in a internal project whose process is :我目前正在为一个内部项目开发一个 Flutter 应用程序,其过程是:

  • You can log in as an authenticated user (mail / passwd) and complete some actions / tasks / validate things您可以作为经过身份验证的用户(邮件/密码)登录并完成一些操作/任务/验证事情
  • You can log anonymously and complete some actions, BUT you need to validate these actions through an authenticated user (AU).您可以匿名登录并完成一些操作,但您需要通过经过身份验证的用户 (AU) 来验证这些操作。

By doing so, each time an AU log himself, he can validate and then switch back to anonymous mode.通过这样做,每次 AU 自己登录时,他都可以验证然后切换回匿名模式。 The problem is that Firebase creates a new anonymous user each time.问题是 Firebase 每次都会创建一个新的匿名用户。

The app could be utilized on multiple devices across the company, which could create 100's of anonymous users a day, while in fact it was only 6-7 users, so what can I do to avoid this ?该应用程序可以在整个公司的多个设备上使用,每天可以创建 100 名匿名用户,而实际上只有 6-7 个用户,那么我该怎么做才能避免这种情况呢?

I've read about customIdToken but I haven't come to a solution for my problem.我已经阅读了 customIdToken 但我还没有找到解决我的问题的方法。

Here is the code I'm using:这是我正在使用的代码:

Future<FirebaseUser> signInAnonToken(String token) async {
    FirebaseUser user = await _firebaseAuth.signInWithCustomToken(token: token);
    return user;
}

FirebaseUser userAnon = await widget.auth.signInAnonToken("useranonuid");

Where "useranonuid" is the uid of the anonymous user but also the token I get by using the getIdToken(refresh:true) method其中“useranonuid”是匿名用户的 uid,也是我使用getIdToken(refresh:true)方法获得的令牌

Thanks in advance.提前致谢。

The problem is that Firebase creates a new anonymous user each time.问题是 Firebase 每次都会创建一个新的匿名用户。

The workaround that I did on my end is to add deleting the anonymous user on the end of each workflow.我最后做的解决方法是在每个工作流的末尾添加删除匿名用户。 This should prevent the Firebase project hitting the 100 million anonymous user account limit .这应该可以防止 Firebase 项目达到1 亿匿名用户帐户的限制

There's no way to restore previous Firebase Anonymous Auth instance.无法恢复之前的 Firebase Anonymous Auth 实例。 That would defeat the purpose of being "anonymous" in the first place.这首先会破坏“匿名”的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Firebase 上使用相同的匿名用户? - How to use the same Anonymous user on Firebase? 有什么方法可以在主应用程序和扩展中对Firebase使用相同的匿名身份验证? - Is there any way to use the same anonymous authentification for Firebase in main App and extension? 如何使用Firebase在应用程序和网站上使用同一用户登录名 - How to use the same user login on app and website with Firebase 使用 firebase 匿名用户保护 flutter 应用程序 - Secure flutter application with firebase anonymous user 如何保持用户登录 Flutter Firebase 应用程序? - How to keep user signed in Flutter Firebase app? 在 Firebase 中使用匿名登录在 Firestore 上对用户进行身份验证 - Use Anonymous Login in Firebase to Auth a user on Firestore 在Ionic App中使用Firebase匿名身份验证安全吗? - Is it safe to use firebase anonymous authentication in Ionic App? 从匿名 firebase 覆盖用户,但不会刷新屏幕抖动 - Coverting user from anonymous firebase, but won't refresh screen flutter Flutter Firebase 身份验证:恢复为特定匿名用户 - Flutter Firebase authentication: reverting back to a specific anonymous user 使用 flutter (windows) 应用程序进行 firebase 匿名登录时出现 MissingPluginException 异常 - MissingPluginException exception when a firebase anonymous sign-in with flutter (windows) app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM