chrisleekr / yii2-angular-boilerplate

Yii2 REST API + Angular 12 Boilerplate (Frontend/Backend)

Home Page:https://yam-boilerplate.chrislee.kr/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AuthHttp Not working in request

pankajk2934 opened this issue · comments

public login(username, password) {
let headers = new Headers();
headers.append('Content-Type', 'application/json; charset=UTF-8');

    return this._authHttp
        .post(
            this._globalService.apiHost + '/user/login',
            JSON.stringify({
                "LoginForm": {
                    "username": username,
                    "password": password
                }
            }),
            {headers: headers}
        )
        .map(response => response.json())
        .map((response) => {
            if (response.success) {
                localStorage.setItem('frontend-token', response.data.access_token);
                this.loggedIn = true;
            } else {
                localStorage.removeItem('frontend-token');
                this.loggedIn = false;
            }
            return response;
        })
        .catch(this.handleError);
}

In this code authhttp not working when i replace authhttp to http it's working fine
can you please tell what is the processor of angular-jwt ?

Hi @pankajk2934,

_authHttp:AuthHttp must be defined in constructor() and imported from 'angular2-jwt'.

The code snippet for import angular2-jwt:

import {AuthHttp, JwtHelper} from 'angular2-jwt';

The code snippet for constructor():

constructor(private _globalService: GlobalService,
                private _router: Router,
                private _authHttp: AuthHttp) {
        this.loggedIn = this.isLoggedIn();
}

If above code is present and still not working, then can you provide full code?
And what is the error message?