【发布时间】:2018-01-28 15:58:12
【问题描述】:
我对如何在登录时重定向用户感到困惑
场景:
-> 填写登录详细信息并提交后,用户被重定向到考试测试。填写完成后,用户现在将被重定向到主页。当用户决定退出,然后再次登录时,用户必须被重定向到主页。
我计划在我的auth.ts 上,在第一次登录时,在我的 firebase 上,我将设置一个检查器,例如 1(如果用户完成测试)和 0(如果用户没有完成测试)
User
|_UID
|_Checker:"1/0" // Either 1 or 0
下面是登录代码:
loginUser() {
if (!this.loginForm.valid) {
console.log(this.loginForm.value);
} else {
this.authData.loginUser(this.loginForm.value.email, this.loginForm.value.password)
.then(authData => {
//if user is done with the test
this.navCtrl.push(HomePage);
//else
this.navCtrl.push(TestPage);
}, error => {
this.loading.dismiss().then(() => {
let alert = this.alertCtrl.create({
message: error.message,
buttons: [
{
text: "Ok",
role: 'Cancel'
}
]
});
alert.present();
});
})
Auth.ts
loginUser(newEmail: string, newPassword: string): firebase.Promise<any> {
return this.afAuth.auth.signInWithEmailAndPassword(newEmail, newPassword)
.then(newUser => {
const x = this.afAuth.auth.currentUser.uid;
if (x != null) {
firebase.database().ref('/Users').child(newUser.uid).set({
email: newEmail,
})
} else {
firebase.database().ref('/Users').child(newUser.uid)
}
})}
【问题讨论】:
标签: angular firebase ionic-framework routes