我是 Flutter Web 的新手,如何使用 Firebase 电话身份验证对用户进行身份验证,有没有办法让用户保持登录状态?
Posted
技术标签:
【中文标题】我是 Flutter Web 的新手,如何使用 Firebase 电话身份验证对用户进行身份验证,有没有办法让用户保持登录状态?【英文标题】:I am new to flutter web, how to authenticate users using firebase phone authentication, is there a way to keep user logged in? 【发布时间】:2021-05-22 09:08:37 【问题描述】:这是使用firebase电话认证登录的基本代码,可以从基本的flutter-fire文档中理解,实际上并没有解释如何在flutter web中实现firebase电话认证。 Flutter Native 手机认证很简单:)
另外,如何记住特定日期的已签名用户?
FirebaseAuth auth = FirebaseAuth.instance;
ConfirmationResult confirmationResult = await auth.signInWithPhoneNumber('+44 7123 123 456');
UserCredential userCredential = await confirmationResult.confirm('123456');
【问题讨论】:
【参考方案1】:用户会自动保持登录 Firebase。要在应用程序重新启动时获取用户的身份验证状态,请查看authentication state 上的文档,其中有这个方便的示例:
FirebaseAuth.instance
.authStateChanges()
.listen((User user)
if (user == null)
print('User is currently signed out!');
else
print('User is signed in!');
);
另请参阅我刚刚给出的答案:Anonymous User not detecting by firebase code error
【讨论】:
嘿弗兰克,我需要为网络应用程序使用 firebase_auth 或 firebase_auth_web 包吗?以上是关于我是 Flutter Web 的新手,如何使用 Firebase 电话身份验证对用户进行身份验证,有没有办法让用户保持登录状态?的主要内容,如果未能解决你的问题,请参考以下文章
如何在Dart / flutter中映射和显示嵌套的JSON?