未捕获(承诺)FirebaseError:权限缺失或不足。在新的 Rr

时间:2021-04-05 05:03:08

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

我检查了 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 很陌生。

1 个答案:

答案 0 :(得分:0)

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.
});