firebase - 注销错误 Cloud Firestore。调用者无权执行指定操作

标签 firebase flutter dart google-cloud-firestore firebase-authentication

我有一个 Flutter 应用程序,我已成功登录用户,并且没有抛出任何错误。但是,当我在我的一个按钮中尝试 FirebaseAuth.instance.signOut() 时,它会将用户注销但会抛出此错误。我在下面附上了我的云 Firestore 规则。

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
  
    match /merchants/{document=**} {
      allow read;
    }
    match /all_merchants/{document=**} {
      allow read;
    }
    match /Types/{document=**} {
      allow read;
    }
    match /Promotions/{document=**} {
      allow read;
    }
    match /search_types/{document=**} {
      allow read;
    }

    
    match /users/{userId} {
      allow read, update, delete: if request.auth.uid == userId;
      allow create: if request.auth.uid != null;
      
      match /{document=**}{
        allow read, update, create, delete: if request.auth.uid == userId;
      }
    }
    
     match /users/{email} {
      allow read, update, delete: if request.auth.token.email == email;
      allow create: if request.auth.token.email != null;
      
      match /{document=**}{
        allow read, update, create, delete: if request.auth.token.email == email;
      }
    }
    
    
  }
}
(编辑):我的按钮 flutter 代码如下:
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter/material.dart';


class SignOut extends StatelessWidget {

  FirebaseAuth auth = FirebaseAuth.instance;


  @override
  Widget build(BuildContext context) {

GestureDetector(
      onTap: (){
          setState(() {
                auth.signOut();
               });
            },
      child: ListTile(
        dense: true,
        leading: Icon(Icons.exit_to_app, color: Colors.red[600], size: 25,),
        title: Text('Sign Out',
                    style: TextStyle(fontFamily: 'Lato', fontSize: 18, fontWeight: FontWeight.w500),),
        trailing: Icon(Icons.arrow_forward_ios, color: Colors.black, size: 19,),
      ),
    );
}
}

最佳答案

发生这种情况是因为在您的应用程序中的某个地方,您可能仍在对某些退出后无法访问的 Firestore 查询保留流订阅,因为您正确地使用规则阻止了它。
检查您的项目代码并查找在用户退出之前未取消的任何最终订阅。

关于firebase - 注销错误 Cloud Firestore。调用者无权执行指定操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64922374/

相关文章:

Flutter,复选框状态没有改变,怎么办?

dart - 如何从json结构生成Dart代码

flutter - 业务逻辑和 UI 逻辑有什么区别?

reactjs - 如何检查 firebase 中的嵌套文档和集合是否存在,如果不存在,如何在 native react 中创建

android - 具有多个 "EqualTo"的 Firebase android 查询

javascript - Angular 滤波器在移动设备上的性能限制

Flutter:列对齐项目以具有相同的宽度

sql-server - 如何在flutter中连接easypaisa/jazzcash支付网关?

android - 如何在flutter中更改agora rtc视频聊天布局?

javascript - 用于循环异步等待的 Firebase 函数