angular - Redirecting user if that user if done with that page Ionic -


i'm confused on how redirect user while on login

scenario:

-> after filling login details , submitting, user redirected examination test. after filling up, user redirected home page. when user decides log out, , login again, user must redirected home page.

i'm planning on auth.ts, upon first login, on firebase, set checker 1's(if user done test) , 0's (if user not done test)

user |_uid   |_checker:"1/0" // either 1 or 0 

below code login:

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 done 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)     }   })} 

if add checker , add conditional

user._checker ? this.navctrl.push(homepage) : this.navctrl.push(testpage); 

this under assumption checker field custom field created under user auth data. , _checker boolean

update

so if uid checker field not exists need either create custom field in authdata not sure can or create field in database when user first completes signup process. think pretty common if want add additional user information.

.then(newuser => { const x = this.afauth.auth.currentuser.uid;  if (x != null) {   firebase.database().ref('/users').child(newuser.uid).set({     email: newemail,     _checked:true // <- added   }) } else {   firebase.database().ref('/users').child(newuser.uid) } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -