April 2020
Intermediate to advanced
716 pages
18h 55m
English
In order to save the JWT credentials that are received from the server on successful sign-in, we use the authenticate method, which is defined as follows.
mern-skeleton/client/auth/auth-helper.js:
authenticate(jwt, cb) { if(typeof window !== "undefined") sessionStorage.setItem('jwt', JSON.stringify(jwt)) cb()}
The authenticate method takes the JWT credentials, jwt, and a callback function, cb, as arguments. It stores the credentials in sessionStorage after ensuring window is defined, in other words ensuring this code is running in a browser and hence has access to sessionStorage. Then, it executes the callback function that is passed in. This callback will allow the component – in our case, the component where sign-in is ...
Read now
Unlock full access