如何在Flutter中允许用户创建多个帐户并在多个帐户之间切换? [英] How to allow user to create and switch between multiple accounts in Flutter?

查看:87
本文介绍了如何在Flutter中允许用户创建多个帐户并在多个帐户之间切换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个Flutter应用程序,用户可以在该应用程序中登录多个帐户(不同的电子邮件ID),并可以从 UserAccounsDrawerHeader 在它们之间进行切换.例如,在Gmail应用程序中,用户可以在多个Gmail帐户之间切换.使用Firebase Flutter Auth可以做到这一点吗?

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. For example, in Gmail app, users can switch between multiple Gmail accounts. Is this possible using Firebase Auth for Flutter?

推荐答案

在默认情况下,Firebase Auth通常不支持允许用户同时使用多个帐户登录.如果您想增加支持,则必须使用 initailizeApp()初始化一个新的 App 实例-一个对于每个用户帐户,然后将用户登录到每个用户帐户.然后,您必须将该应用程序实例传递给其他Firebase API,才能使用该帐户进行身份验证的访问(例如,Firestore查询).

In the default scenario, Firebase Auth generally does not support allowing a user to be signed in with multiple accounts at the same time. 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. 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).

说实话,从提供的API中我不清楚如何完成最后一部分.但也许 Firestore.getInstance(app)可以做到.

To be honest, it's not clear to me from the provided APIs how to do that last part. but perhaps Firestore.getInstance(app) might do it.

无论如何,实现起来并不容易.没有简单的配置或技巧可以同时进行多个登录.通常,应用程序只会使用户退出,然后使用另一个帐户再次登录.

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.

这篇关于如何在Flutter中允许用户创建多个帐户并在多个帐户之间切换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆