注销错误 Cloud Firestore。调用者没有权限执行指定的操作

2024-03-08

我有一个 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 查询的流订阅,这些查询在您注销后无法访问,因为您使用规则正确地阻止了这些查询。

检查您的项目代码并查找在用户注销之前未取消的任何最终订阅。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

注销错误 Cloud Firestore。调用者没有权限执行指定的操作 的相关文章

随机推荐