Get User Profile

I have in my database two profiles: Lawyer and Citizen
Follow my tables
/----------- Table User -----------/
User
id
name
email
password

/----------- Table Profile_User-----------/
User
user_id
profile_id

/----------- Table Profile-----------/
User
id
name

bellow my ioniv view imagens

I can do it login
service-provider.ts

logar(user) {
    let creds = 'email=' + user.email + "&password=" + user.password;
    let headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded');

    return new Promise(resolve => {
        this.http.post(this.api+'auth', creds, {
          headers: headers,
          method: 'POST'
        }).subscribe( data => {
            if(data.json().token){
                resolve(true);
            } else {
              this.estaLogado = false;
              resolve(false);
            }
        });
    });
  }

and in my login.ts

  logar(user) {
    this.authService.logar(user).then( data => {
      if(data){
        this.navCtrl.setRoot(HomePage);
      }
    });
  }

but I have before to make login, get profile something like this:
if(authenticated && user.profile == ‘lawyer’)
this.navCtrl.setRoot(LawyerPage);
if(authenticatedd && user.profile == ‘citizen’)
this.navCtrl.setRoot(CitizenPage);

any idea ?

where do you have the information about the profile?
Do you get back it after the login?

If yes, then you can return it into your resolve

resolve(data)

and validate

logar(user) {
   let profilePages = {
       'lawyer' : LawyerPage,
       'citizen' : CitizenPage
   }

    this.authService.logar(user).then( response => {
      try {
         if(response === false){
            throw('access denied');
         } else {
            if (response.hasOwnProperty('profile') && profilePages.hasOwnProperty(response.profile.toLowerCase())) { 
              this.navCtrl.setRoot(profilePages[response.profile.toLowerCase()]);
            } else {
              throw('access denied');
            }
         }
      } catch(err) {
         // access denied
         this.navCtrl.setRoot(HomePage);
      }
        
    });
}


hope it helps :smile:

@fishi Sorry, so, I have 2 button with parameters login.html

  <ion-row>
    <button ion-button color="danger" full large *ngIf="profile == 'Citizen'" (click)="navigateTo(profile)">New Citizen</button>
  </ion-row>

  <ion-row>
    <button ion-button color="danger" full large *ngIf="profile == 'Lawyer'" (click)="navigateTo(profile)">New Lawer</button>
  </ion-row>

Where I pass the user profile Login.ts

constructor(public formB: FormBuilder, public navCtrl: NavController, public navParams: NavParams, public authService: ServiceProvider, public alertCtrl: AlertController) {
    this.profile = this.navParams.get('profile');
    this.dataForm();
  }

I want that the User Lawer make login and to be redirect to PageLawer and Citize to be redirect for CitizenPage for example
Ex: if(authenticated && this.profile == user.profile)
redirect (userPage)

well my solution is working without the templates ngIf …
So you can you use one single “login” button.