我有一个正在进行的 flutter 项目,它将使用 AWS 作为后端服务。首先,我尝试使用 AWS Cognito 完成用户身份验证。我想为用户提供通过 Google 登录的选项。所以我需要在用户池中设置社交身份提供者。在 console.developers.google.com 上设置控制台时,我们必须选择它是 Android 应用程序还是 iOS 应用程序(以及网络服务器或网站等...)由于 Flutter 是一个跨平台框架应用程序将被两个平台使用。所以我的问题是我是否必须为 android 和 iOS 设置两次谷歌注册。如果我再次这样做,则会引发另一个问题。如何在 Cognito 的一个应用程序客户端中为两个平台应用两个不同的客户端 ID。AWS 和 Google 的文档对这些问题没有帮助/明确。
google-authentication amazon-web-services oauth-2.0 amazon-cognito flutter
我正在开发一个 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。