Sam*_*oon 6 dart firebase-authentication flutter flutter-web
我正在开发一个 FLutter Web 应用程序,并使用 Firebase 身份验证以及电子邮件和密码登录来登录用户
await FirebaseAuth.instance
.signInWithEmailAndPassword(email: email, password: password);
Run Code Online (Sandbox Code Playgroud)
成功登录后,代码会将用户重定向到主页。
Navigator.of(context).pushReplacementNamed('/HomePage');
Run Code Online (Sandbox Code Playgroud)
但当用户刷新网页或尝试再次访问该网站时,它已注销,必须重新登录。
以下是我用来检查登录用户的代码
StreamBuilder<User?>(
stream: FirebaseAuth.instance.userChanges(),
initialData: FirebaseAuth.instance.currentUser,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.data == null){
Navigator.of(context).pushReplacementNamed('/HomePage');
}else{
Navigator.of(context).pushReplacementNamed('/signup');
}
}
Run Code Online (Sandbox Code Playgroud)
如何让用户在使用注销时保持登录状态?我希望该解决方案专门适用于 flutter web。
| 归档时间: |
|
| 查看次数: |
1235 次 |
| 最近记录: |