April 2020
Intermediate to advanced
716 pages
18h 55m
English
In our frontend components, we will need to retrieve the stored credentials to check if the current user is signed in. In the isAuthenticated() method, we can retrieve these credentials from sessionStorage.
mern-skeleton/client/auth/auth-helper.js:
isAuthenticated() { if (typeof window == "undefined") return false if (sessionStorage.getItem('jwt')) return JSON.parse(sessionStorage.getItem('jwt')) else return false}
A call to isAuthenticated() will return either the stored credentials or false, depending on whether credentials were found in sessionStorage. Finding credentials in storage will mean a user is signed in, whereas not finding credentials will mean the user is not signed in. We will also add a method that allows ...
Read now
Unlock full access