问题已“登录” 状态为非持久性, 刷新页面 时,也会在更改 firebase安全规则
时发生用户登录来自
match /posts/{document} {
allow read;
allow write:if request.auth!=null;
}
到 (稍后会变得更加复杂)
match /posts/{document} {
allow read: if request.auth!=null && get(/databases/$(database)/documents/users/$(request.auth.uid)).data.admin == true;
allow write:if true;
}
我的Auth.service是
this.user=this.afAuth.authState.pipe(
switchMap(user=>{
if(user){
this.router.navigate(['/posts'])
return this.afs.doc<User>(`users/${user.uid}`).valueChanges();
}
else{this.router.navigate(['/']);return of(null)}
})
)
和我的posts.component
this.instAuth.user.subscribe(
(commingUser)=>{
this.user2=commingUser;
this.myCollection=this.afs.collection<Item>('posts')
this.items2=this.myCollection.valueChanges();
}
);