I am trying to get the details of user by passing the token stored in storage to a laravel passport api. Request works fine when I test with postman but requesting from the app, I keep getting 401 unauthorised. The app is with ionic 3 and angular 4. My laravel backend is already configured with Barryvdh Laravel CORS package and there are no problems with CORS. I have read nearly all similar problems with no answer.
Frontend
this.storage.get('token').then((value)=>{
this.token = value;
let headers = new HttpHeaders()
.set('Content-Type','application/json')
.set('Authorization',"Bearer "+this.token);;
console.log(this.token);
this.http.post(this.apiUrl+'/check-login-status',{headers:headers})
.subscribe(res => {
resolve(res);
},(err) => {
reject(err);
});//end http post
});//end this.storage.get
Laravel routes/api.php
Route::group(['middleware' => 'auth:api'], function(){
Route::post('/check-login-status', 'Mobile\Auth\LoginController@checkLoginStatus');
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire