【发布时间】:2018-01-27 16:00:43
【问题描述】:
我试图让用户在首次登录其帐户时转到个人资料设置页面。我正在使用 if 语句来执行此操作,该语句检查用户的 id 是否在 firebase 数据库中以及是否与配置文件相关联。如果没有,用户将被带到个人资料制作页面,那么一旦他们制作了个人资料,他们就会被发送到他们的个人资料,如果他们有个人资料,他们会被直接带到他们的个人资料。
问题是,一旦他们制作了个人资料,即使在登录页面关闭后,个人资料页面仍会从登录页面中的 if 语句加载。为什么会这样?
login.ts
login(user: User){
this.afAuth.auth.signInWithEmailAndPassword(user.email,user.password)
.then(res => {
//check if user has made profile if not send to profile setup page
let user = firebase.auth().currentUser;
if(user.emailVerified){
this.afAuth.authState.take(1).subscribe(data => {
let profileCollection = this.afs.collection('profiles').doc(`${data.uid}`).valueChanges();
profileCollection.subscribe(userProfile => {
if (userProfile == null){
console.log(userProfile);
this.navCtrl.setRoot('ProfileSetupPage');
}else{
console.log('LoginPage Load Tabs Page');
this.navCtrl.setRoot('ProfilePage');
}
})
});
}
}
profile-setup.ts
createProfile(){
if(this.profileForm.valid){
this.afAuth.authState.take(1).subscribe(auth => {
this.afs.collection('profiles').doc(`${auth.uid}`).set(this.profile)
.then(res => {
this.navCtrl.setRoot('ProfilePage');
})
})
}
【问题讨论】:
标签: angular typescript firebase ionic-framework