July 2018
Intermediate to advanced
420 pages
8h 46m
English
The Login function follows almost the same structure as the Register function. The difference here is that we are just sending the email address and password to the server.
Add the following code right after the onRegister() function:
onLogin(user: User): Observable<User> {
const request = JSON.stringify(
{ email: user.email, password: user.password }
);
return this.http.post(this.registerUrl, request, httpOptions)
.pipe(
map((response: User) => {
// Receive jwt token in the response
const token: string = response['access_token'];
// If we have a token, proceed
if (token) {
this.setToken(token);
this.getUser().subscribe();
}
return response;
}),
catchError(error => this.handleError(error))
);
}
Note that we ...
Read now
Unlock full access