Integrating Backend API - Summary Slide
Integrating Backend API - Summary Slide
mern-skeleton/client/lib/api-auth.js:
export { signin, signout }
const auth = {
isAuthenticated() {
if (typeof window == "undefined")
return false
if (sessionStorage.getItem('jwt'))
return JSON.parse(sessionStorage.getItem('jwt'))
else
return false
},
authenticate(jwt, cb) {
if (typeof window !== "undefined")
sessionStorage.setItem('jwt', JSON.stringify(jwt))
cb()
},
clearJWT(cb) {
if (typeof window !== "undefined")
sessionStorage.removeItem('jwt')
cb()
//optional
signout().then((data) => {
document.cookie = "t=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"
})
}
}
export default auth
mern-skeleton/client/MainRouter.jsx:
<Route path="/users" element={Users}/>
mern-skeleton/client/MainRouter.jsx:
<Route path="/signin" element={Signin}/>