[英]How to allow user to create and switch between multiple accounts in Flutter?
I am trying to make a Flutter app where the user can sign in into multiple accounts (different email IDs) and can switch between them from the UserAccounsDrawerHeader
.我正在尝试制作一个 Flutter 应用程序,用户可以在其中登录多个帐户(不同的 email ID)并可以从
UserAccounsDrawerHeader
在它们之间切换。 For example, in Gmail app, users can switch between multiple Gmail accounts.例如,在 Gmail 应用程序中,用户可以在多个 Gmail 帐户之间切换。 Is this possible using Firebase Auth for Flutter?
这是否可以使用 Flutter 的 Firebase Auth?
In the default scenario, Firebase Auth generally does not support allowing a user to be signed in with multiple accounts at the same time.默认情况下,Firebase Auth 一般不支持用户同时登录多个账号。 If you want to add support, what you will have to do is use initailizeApp() to initialize a new App instance - one for each user account, and sign in the user to each one of them.
如果您想添加支持,您需要做的是使用initializeApp()来初始化一个新的App实例 - 每个用户帐户一个,然后将用户登录到其中的每个帐户。 You will then have to pass that app instance around to the other Firebase APIs to use that account for authenticated access (for example, Firestore queries).
然后,您必须将该应用程序实例传递给其他 Firebase API 以使用该帐户进行身份验证访问(例如,Firestore 查询)。
To be honest, it's not clear to me from the provided APIs how to do that last part.老实说,我从提供的 API 中不清楚如何完成最后一部分。 but perhaps Firestore.getInstance(app) might do it.
但也许Firestore.getInstance(app)可能会这样做。
In any event, it is not trivial to implement.无论如何,实施起来并非易事。 There is not a simple configuration or trick that will allow multiple simultaneous sign-ins.
没有允许多个同时登录的简单配置或技巧。 Usually apps just make the user sign out, then in again with another account.
通常应用程序只是让用户退出,然后再次使用另一个帐户登录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.