Angular with Wordpress API and JWT Authentication not Working properly in code even though It Works on PostMan

745 views Asked by At

I'm facing the below error. I tried multiple solutions but adding "Access-Control-Allow-Origin" to web.config does not alter the outcome in a positive way.

On the other hand, I used PostMan, as a test alternative, and it works flawlessly.

Based on the above evidence, I'm thinking the error is on the authentication code somewhere.

Here's the authentication function snippet.

    auth() {
    this.http.post('http://*****.*****.com/two/wp-json/jwt-auth/v1/token', {
      username: this.user.login,
      password: this.user.password
    }).subscribe((data) => {
      if (data['token']) {
        this.token = data['token'];
        this.tokenChange.emit(this.token);
      }
    });
}

Setup: Windows Server shared-hosting(godaddy) Angular 7.0.4, Wordpress with "JWT Authentication for WP-API" plugin.

Figure 1. The JS console showing the error. "Access-Control-Allow-Origin" is not the problem as I tested it on PostMan and it works normally. Angular and Wordpress error with JWT authentication plugin

0

There are 0 answers