Skip to Main Content
React Projects
book

React Projects

by Roy Derks
December 2019
Intermediate to advanced content levelIntermediate to advanced
474 pages
10h 3m
English
Packt Publishing
Content preview from React Projects

Passing JWT to the GraphQL server

The user's authentication details in the form of the JWT are now stored in the session storage, and the route to the checkout page is now private. But for the user to check out, this token should also be sent to the GraphQL server, along with every document for the server, to validate whether the user is actually authenticated or whether the token has expired. Therefore, you need to extend the setup of the Apollo Client to also send the token when you make a request to the server and prefix it with Bearer, since this is how a JWT is recognized.

Follow these steps to pass the JWT to the GraphQL server:

  1. You need to install an Apollo package to deal with adding values to the Context since you need the setContext ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

React Projects - Second Edition

React Projects - Second Edition

Roy Derks
Test-Driven React

Test-Driven React

Trevor Burnham

Publisher Resources

ISBN: 9781789954937Supplemental Content