当我尝试注册我的一个用户时,我不断收到这个令人讨厌的错误:
<块引用>未捕获(承诺)FirebaseError:注册客户端时权限缺失或不足
这是促进我注册过程的代码:
const user = await db.collection("public").doc(username).get();
if (user.data()) {
}
try {
const authUser = await auth.createUserWithEmailAndPassword(
email,
password
);
if (authUser) {
await db.collection("private").doc(authUser.user.uid).set({
username: username,
});
await db
.collection("public")
.doc(username)
.set({
userId: authUser.user.uid,
profileInfo: {
imageUrl: "",
displayName: username,
bio: "",
location: "",
},
});
await dispatch({
type: "SET_USER",
user: {
uid: authUser.uid,
username,
},
});
history.push("/dashboard");
}
} catch (error) {
}
};
这是我的 Firebase 规则:
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow write, update, delete, create, read: if false;
}
match /public/{username} {
match /{document=**} {
allow create, write, update, delete: if request.auth != null &&
get(/databases/$(database)/documents/private/$(request.auth.uid)).data.username == username;
allow read: if true;
}
}
match /private {
match /{uid}/{document=**} {
allow write, update, delete, create, read: if request.auth != null &&
request.auth.uid == uid;
}
}
}
}
知道此特定代码导致此错误的原因吗?
奇怪的是,当我刷新页面时,我可以访问 /dashboard
并进行所有正常更新,就像登录用户应该做的一样。
答案 0 :(得分:0)
我相信它来自
allow write, update, delete, create, read: if false;
暂时将其设置为 true,然后您可以在您的产品为公众准备好时对其进行编辑(可能仅更改为特定的 uid)。