Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have login page in my app with token base authorization. In this app I have component called sessions. To view sessions I have to give access token.

here is my login.component.ts

this.authService.login(this.formGroup.value).subscribe(results => {
    const tokens = JSON.parse(results.tokens.replace(/'/g,'"'));
       localStorage.setItem('userTokens',tokens.access);
        console.log(tokens.access);
        this._router.navigate(['/sessions'])
     }

This is my authService.ts where I have pass token to the header.

getSessions(){
  return this.http.get('http://localhost:8000/api/sessions/all/'
  ,{headers : new HttpHeaders({'Authorization' : 'JWT ' + localStorage.getItem('userTokens')})});
}

This is my home.component.ts

this.authService.getSessions().subscribe((data : any )=>{
  this.Sessions = data;
});

But this gives me unauthorized error. I tried same token in postman. It works finely in postman. Can someone help me for this.

question from:https://stackoverflow.com/questions/66060545/angular-authorization-with-jwt-token

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
421 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...