【发布时间】:2019-12-26 07:25:03
【问题描述】:
我在我的 Flutter Web 应用上使用 Firebase 身份验证,但在刷新期间会话未保持。
这是我正在使用的包。
https://pub.dev/packages/firebase
这就是我使用 Firebase 进行身份验证的方式
static Future<User> handleSignInEmail(String email, String password) async {
await init();
final UserCredential userCredential =
await auth().signInWithEmailAndPassword(email.trim(), password);
assert(userCredential.user != null);
assert(await userCredential.user.getIdToken() != null);
final User currentUser = await userCredential.user;
assert(userCredential.user.uid == currentUser.uid);
print('signInEmail succeeded: $userCredential.user');
return userCredential.user;
}
如果我刷新页面并调用如下方法,返回的用户为null:
static Future<User> getFirebaseUser() async {
await init();
return await auth().currentUser;
}
使用 Flutter Mobile 的类似实现按预期工作。我在 Flutter Web 实现中缺少什么?
【问题讨论】:
-
嘿@dazza5000,我也有同样的问题。你找到解决办法了吗?
-
@wottpal - 下面的解决方案有效
标签: firebase-authentication flutter-web