I want to process a token. But get the message:
Property 'token' does not exist on type 'Promise '
I have the following code. I get a json with the property token. Incidentally, I am guided by a tutorial that uses Angular 2. I already tried it without ['token']. But without success. I also had an interface for the post, but I did not use it to eliminate errors. It also does not work with the interface.
Here is my code:
signin(email: string, password: string) {
return this.http.post<any>('http://127.0.0.1:8000/api/userLogin',
{ email: email, password: password },
this.httpOptions).map((response: Response) => {
const token = response.json()['token'];
const base64Url = token.split('.')[1];
const base64 = base64Url.replace('-', '+').replace('_', '/');
return JSON.parse(window.atob(base64));
});
}
The Tutorial:
https://www.youtube.com/watch?v=pT9_FngJuzY&t=321s
By the way, in this case I use laravel / passport.
success:
{token: "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6IjllOW…lsJiIWVmiiNY1Ft02MSWGS-Thx7_warYrUucP8bPHHnyMCfnU"}