July 2018
Intermediate to advanced
420 pages
8h 46m
English
Now, we will see how to get the information of the logged-in user. Remember that our API has an endpoint that gives us the information of the logged-in user based on the authentication token.
Let's see how we can do this in a simple way.
Add the following code right after the getToken() function:
getUser(): Observable<User> {
return this.http.get(this.apiUrl + '/me').pipe(
tap(
(user: User) => {
this.currentUser = user;
}
)
);
}
The previous code receives the user's information from the API and applies this to the currentUser property.
Read now
Unlock full access