Flutter Firebase 权限被拒绝
Flutter Firebase Permission Denied
我注销后,我尝试再次登录,是的,它成功登录,但问题是,我开始收到错误 [cloud_firestore/permission-denied] 但是当我重新启动我的应用程序时,它再次运行良好.我错过了什么?
PS:我使用 Google 登录。
这是我的登录码:
Future signInWithGoogle() async {
// Trigger the authentication flow
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth =
await googleUser!.authentication;
// Create a new credential
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Once signed in, return the UserCredential
await _auth.signInWithCredential(credential);
}
这是我的退出代码:
await _googleSignIn.signOut().then((value) async {
await widget.firebaseAuth.signOut().then((value) {
Navigator.pop(context);
});
}).onError((error, stackTrace) {
print(error);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("ERROR!! TRY AGAIN"),
));
});
cloud_firestore/permission-denied
错误来自 Firestore(数据库),而不是来自 Firebase 身份验证。
很可能您的代码中有一些实时侦听器需要用户登录,而一旦您注销用户,这些侦听器就会被数据库拒绝。
您可以取消订阅,也可以忽略错误,因为发生此错误后侦听器也会自动取消。
就我而言,我忘记在 firebase 中激活“google-sign in”作为身份验证方法。
我注销后,我尝试再次登录,是的,它成功登录,但问题是,我开始收到错误 [cloud_firestore/permission-denied] 但是当我重新启动我的应用程序时,它再次运行良好.我错过了什么?
PS:我使用 Google 登录。
这是我的登录码:
Future signInWithGoogle() async {
// Trigger the authentication flow
final GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
// Obtain the auth details from the request
final GoogleSignInAuthentication googleAuth =
await googleUser!.authentication;
// Create a new credential
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
// Once signed in, return the UserCredential
await _auth.signInWithCredential(credential);
}
这是我的退出代码:
await _googleSignIn.signOut().then((value) async {
await widget.firebaseAuth.signOut().then((value) {
Navigator.pop(context);
});
}).onError((error, stackTrace) {
print(error);
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text("ERROR!! TRY AGAIN"),
));
});
cloud_firestore/permission-denied
错误来自 Firestore(数据库),而不是来自 Firebase 身份验证。
很可能您的代码中有一些实时侦听器需要用户登录,而一旦您注销用户,这些侦听器就会被数据库拒绝。
您可以
就我而言,我忘记在 firebase 中激活“google-sign in”作为身份验证方法。