javascript - 在 Angular + AngularFire 应用程序中登录后权限被拒绝
问题描述
当我成功登录用户后尝试访问数据库时,我收到错误
permission_denied at /profiles/N97wiXBCMxhB06qQXJ2Bvhcjnts1:客户端无权访问所需数据。
因为,我刚刚对用户进行了身份验证,所以我不明白用户如何没有权限。另一个奇怪的行为是它在我第二次按下调用函数signIn(singInForm)的“登录”按钮时起作用。
登录页面.ts
signIn(signInForm) {
this.authService.signInWithEmailAndPassword(signInForm.email, signInForm.password)
.then(res => {
const userID = res.user.uid;
this.fbBackendService.fetchUserProfile(userID).subscribe(userProfile => {
// DO SOMETHING using the userID
}, error => {
// DO SOMETHING
});
}).catch(error => {
// DO SOMETHING
});
}
fb-backend.service.ts
constructor(private db: AngularFireDatabase) { }
fetchUserProfile(userID): Observable<IUserProfile> {
return this.db.object(`/profiles/${userID}`)
.valueChanges()
.pipe((take(1), map((response: any) => response as IUserProfile)));
}
以下是相关的规则集:
{
"rules": {
".write": false,
".read": false,
"profiles": {
"$uid": {
".read": "auth.uid === $uid",
".write": "auth.uid === $uid",
".indexOn": "company_id"
}
}
}
}
解决方案
您可以尝试降级到 firebase 8.3.0。新版本似乎有问题。
推荐阅读
- c++ - 计算 6 x 6 矩阵中每个沙漏的沙漏总和(其中条目只能从 0 到 9),然后打印最大沙漏总和
- css - 表单元素忽略正文 CSS
- php - 集成 PHP、SSH 和 ssh-agent
- c - 使用 ARM Neon Intrinsics 实现重叠的 memmove 循环
- .net - 如何让 Visual Studio Community Edition 2019 与 Web 应用程序一起使用
- android - Android 应用程序在设置 minifyEnabled true 时崩溃
- python - 在 Anaconda 中更新张量流?
- java - JasperReport 对象中的 InputStream 对象何时关闭?
- windows - TBitmapImage 在 Inno Setup 6 中的缩放显示上呈现大于其大小
- python - PyMongo 查询给了我一个嵌套的 DataFrame