January 2019
Intermediate to advanced
460 pages
10h 33m
English
The JWT gives us the opportunity to query for the currently logged-in user. Then, we can display the correct authenticated user in the top bar. To request the logged-in user, we require a new query called currentUser on our back end. In the schema, you simply have to add the following line to the RootQuery queries:
currentUser: User @auth
Like the postsFeed and chats queries, we also need the @auth directive to extract the user from the request context.
Similarly, in the resolver functions, you only need to insert the following three lines:
currentUser(root, args, context) { return context.user;},
We return the user from the context right away, because it is already a user model instance with all the appropriate ...
Read now
Unlock full access