繁体   English   中英

Firestore:FirebaseError:缺少权限或权限不足

[英]Firestore: FirebaseError: Missing or insufficient permissions

我有以下规则:

rules_version = '2';
service cloud.firestore {

    match /documents/{any} {
        allow read, write: if request.auth.uid != null
    }

    match /users/{any} {
        allow read, write: if request.auth.uid != null
    }
}

所以基本上,我希望经过身份验证的用户能够读/写usersdocuments collections。 但是我在创建用户并登录时尝试编写:

                const registerRes = await firebase
                    .auth()
                    .createUserWithEmailAndPassword(email, password);
                await registerRes.user.updateProfile({
                    displayName: fullName
                });
                registerRes.user.sendEmailVerification();
                await firebase.firestore().collection('users').doc(registerRes?.user?.uid).set({...someStuff});

但我收到一个错误:

FirebaseError: Missing or insufficient permissions.

不知道我做错了什么。 任何帮助将不胜感激 - 谢谢!

文档中所述,您需要在match /databases/{database}/documents块中包含特定于路径的规则,例如:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {

    match /documents/{any} {
        allow read, write: if request.auth.uid != null
    }

    match /users/{any} {
        allow read, write: if request.auth.uid != null
    }


  }
}

旁注:请注意,基于request.auth.uid != null的规则并不能真正保护您的数据库,请参阅此SO 答案

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM