【问题标题】:Uncaught (in promise) FirebaseError: Missing or insufficient permissions. at new Rr未捕获(承诺中) FirebaseError:缺少权限或权限不足。在新 Rr
【发布时间】:2021-07-01 01:05:08
【问题描述】:

我检查了我在 firebase 中的规则和我项目中的 firestore.rules 文件,但我不知道是什么原因造成的。

我的 HTML 代码。

 <form id="Login" class="input-group">
                    <input id="firstName" type="text" class="input-field" placeholder="First Name" required>
                    <input id="lastName" type="text" class="input-field" placeholder="Last Name" required>
                    <input id="Major" type="text" class="input-field" placeholder="Major" required>
                    <input id="Academicyearr" type="text" class="input-field" placeholder="Academic Year" required>
                    <button id="write_Test" type="submit" class="submit-buton"> Test Write </button>
                </form>

这是java脚本代码

const db = firebase.firestore();
const updateForm = document.querySelector('#Login');
updateForm.addEventListener('submit', (e) => {
    e.preventDefault();

    firebase.auth().onAuthStateChanged(user => {
        console.log(user.uid);
        if(user) {
            db.collection('Users').doc(user.uid).set({

                // email: updateForm['update-email'].value,
                name: updateForm['firstName'].value,
                // dob: updateForm['update-dob'].value,
                // phone: updateForm['update-phone'].value

            })
        } 
    });
});

这就是我的 Firestore 中的规则

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

        //match logged in user doc in users collection
    match /Users/{userId} {
      allow read, write, update: if request.auth.uid == userId;
      allow create: if request.auth.uid != null;
    }
  }
}

错误是

未捕获(承诺)FirebaseError:权限缺失或不足

当我在本地运行我的 web 应用程序时,它会出现在控制台中。

任何帮助将不胜感激,对我来说放轻松,我是 firebase 的新手。

【问题讨论】:

  • console.log(user.uid); 显示什么?
  • 我登录用户的uid
  • 我不是在问它要显示什么,我是在问它实际上在显示什么
  • 还要注意你的两条规则是重叠的,create包含在write

标签: javascript html firebase google-cloud-firestore firebase-security


【解决方案1】:

documentation for user management,您可以找到有关如何管理用户的信息。

这是根据example in the documentation更新用户的方法:

var user = firebase.auth().currentUser;

user.updateProfile({
  displayName: "Jane Q. User",
  photoURL: "https://example.com/jane-q-user/profile.jpg"
}).then(function() {
  // Update successful.
}).catch(function(error) {
  // An error happened.
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2021-04-22
    • 2023-02-24
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    相关资源
    最近更新 更多