刷新后即使使用localStorage,

时间:2019-10-26 08:03:17

标签: javascript angular firebase firebase-authentication firebase-security

问题已“登录” 状态为非持久性, 刷新页面 时,也会在更改 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();
        }
      ); 

我遵循了其他类似问题的答案,例如:firstsecondthird

0 个答案:

没有答案