我有一个使用Firebase身份验证和Firestore的有角度的Web应用程序。登录时,用户将看到具有添加和删除功能的相册列表。但是,退出后,我返回到登录屏幕。如果我使用第二个帐户登录,则会显示一个帐户中的相册列表。我无法添加任何内容,因为我的安全规则阻止了它。如果刷新页面,则会显示第二个帐户的正确相册列表。
我不确定是什么原因引起的?我需要在退出方法中做些额外的工作来确保立即登录到另一个帐户是“新鲜的”吗?
login(email: string, password: string) {
this.errorMessage = "";
firebase.auth().signInWithEmailAndPassword(email, password).then(value => {
if (this.authGuardService.authGuardStateURL != undefined) {
this.router.navigate([this.authGuardService.authGuardStateURL]);
this.fetchUserEmail();
return of(true);
} else {
this.router.navigate(['home']);
this.fetchUserEmail();
return of(true);
}
})
.catch(err => {
this.errorMessage = ErroAuthEn.convertMessage(err['code']);
return of(false);
});
}
signOut() {
this.afAuth.auth.signOut().then(() => {
this.router.navigate(['login']);
})
}
相册查询
以下是从Firestore日期数据库中获取专辑列表的查询。此代码段是我的服务之一。它返回位于已登录用户ID下方的所有相册。如您所见,将user_id发送到此函数,以便它可以执行正确的查询。这工作得很好。但是,如上所述,如果我从帐户1注销到帐户2,则此查询产生的结果将在刷新之前显示帐户1的详细信息...
注意:尽管键入此内容,但让我意识到此功能是在服务加载时在服务中调用的,而不是从组件中调用的,因此当用户注销时,该服务不会再次启动,直到页面刷新。我认为这可能是造成它的原因。我需要测试。
getAlbums(user_id) {
this.albumsCollection = this.afs.collection<album>(`users/${user_id}/albums`, ref => {
return ref.orderBy('album_title');
});
this.albums = this.albumsCollection.valueChanges({ idField: 'id' });
}