In mi Authentication Service i have:
@Injectable()
export class AuthenticationService {
constructor(private http: HttpClient) { }
login(username: string, password: string) {
return this.http.post<any>
(`${environment.apiUrl}/token`, "grant_type=password&username="+username+"&password="+password).pipe(map(user => {
// login successful if there's a jwt token in the response
if (user && user.token) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
localStorage.setItem('currentUser', JSON.stringify(user));
}
return user;
}));
}
In the: if (user && user.token) ... user.token returns undefined and then not create the currentUser localStorage.
If i write only: if (user) ... it works and generates the access_token like this:
access_token:"eiGcvwEa0SsL0xml2Y5BcnR5W1g-vTniUB96YPFsnWe7AwG-pEmtLaOf1nurnYOFFJ-qpax5QceWD9qkEtXJIWU91DFvDwEOrrRqIrb1-gBFnspTk6dE6YjIXpZqkcA1JHWJezQx0dfqBINhZ08qocfIrqK0IqqOvguRh9-PUJCPRMg4JaYh3CJGAZVqbFi8WiO4OwRwrBVqXXGWSHqoCUgHxWDYolCZE7axCLDdbTcbCz2IluemsA0kdmvyQ2laub3iELFN-5m7dAvpCYtFvHjt2qkYijH_v2E3uV5dux5e_txj4XSTzoT8kikoCn7I"
expires_in:59
refresh_token:"c723ec64-c90e-482d-8292-390214d5324b"
token_type:"bearer"
I need to get the token from user.token but I don't know where I'm wrong.
Can someone help me?
Aucun commentaire:
Enregistrer un commentaire