firebase - 如何提高 Flutter 应用中 Firebase 身份验证的速度
问题描述
我已经构建了一个具有登录和注册功能的应用程序。我还添加了注销功能,并且当用户关闭并重新打开应用程序 firebase 时会检查用户是否注销,但问题是当我打开应用程序 firebase 时需要花费大量时间至少 8-10 秒来检查用户是否是否已经登录,那么如何提高火力基地的速度,使用户无需等待 8-10 秒。
void initState() {
super.initState();
pageController = PageController();
// Detects when user signed in
googleSignIn.onCurrentUserChanged.listen((account) {
handleSignIn(account);
}, onError: (err) {
print('Error signing in: $err');
});
// Reauthenticate user when app is opened
googleSignIn.signInSilently(suppressErrors: false).then((account) {
handleSignIn(account);
}).catchError((err) {
print('Error signing in: $err');
});
}
handleSignIn(GoogleSignInAccount account) async {
if (account != null) {
await createUserInFirestore();
setState(() {
isAuth = true;
});
configurePushNotifications();
} else {
setState(() {
isAuth = false;
});
}
}
解决方案
我正在使用这种方式来检查用户是否登录应用程序
Auth auth = Auth();
await auth.getCurrentUser().then((user) async {
runApp(MaterialApp(
theme: _themeData(),
home: user != null
? Home(
userId: user.uid
)
: Login(),
debugShowCheckedModeBanner: false,
routes: routes,
));
}).catchError((error) {
print("Here is ERROR $error");
});
}
告诉用户 uid 几乎不需要一两秒钟。我希望它能解决你的问题。
推荐阅读
- python - 对象在矢量运动中表现怪异
- ios - 在 UISplitViewController 中仅隐藏 .supplementary 列
- scala - 在二维数组中搜索单个元素 - Scala
- numpy - 4d 数组中的连续差异
- python - 在 PyCharm 中调试 Python 时获取函数调用的中间结果
- git - 是否可以转义 git 提交消息中的哈希 (#) 注释字符?
- python - 从列表中随机选择这些数字的百分比
- github-actions - GitHub Actions 能否从私有仓库创建发布到公共仓库?
- javascript - jquery 不能使用动态添加的元素
- php - PHP Unlink 不会完全删除文件,而是将其转换为 0kb 文件