0

I have developed an API in php which contains a Login method. When I run the API in postman with parameters such as email and password, the correct user is returned along with a JWT token that has been generated. However in my code in when I use a post method with the API the user seems to be returned but when I use navCtrl.navigateForward the page wont move from the login page to my dashboard.

auth-servie.ts

login(email, pw) {
  if (email === '' || pw === '') {
    this.presentAlert();
  } else {
  const params = new HttpParams()
  .set('email', email)
  .set('pw', pw);
  return this.http.post<any>(apiUrl + 'login', {email, pw}, 
{params});
  }
}



login.ts

login() {
    this.authService.login(this.email, this.pw).subscribe(res => {
          if (res) {
            // store jwt
            // move to dashboard
            console.log('Valid User');
            this.navCtrl.navigateForward('/menu/first');
          }
      },  error => {
          if (error.status === 401) {
            console.log('Authorisation Required');
          }
        }
      );
  }
Dharman
  • 30,962
  • 25
  • 85
  • 135
c-mac
  • 83
  • 1
  • 9

1 Answers1

0

If you get a correct response from your api with the auth token so the problem is in your ionic code, I have never used ionic but take a look to the second answer in the below post:

enter link description here

Regards

Daniel Luna
  • 341
  • 2
  • 9