In this repo you have an express app that have a login route it was what we did in lesson-week_11-day_01-expres-auth-with-passport but with a little bit of refactoring
npm install
npm start
npm install
npm install jwt-decode
npm start
import jwtDecode from "jwt-decode";
const tokenKey = "authToken";
function setJwt(token) {
localStorage.setItem(tokenKey, token);
}
function getJwt() {
return localStorage.getItem(tokenKey);
}
function logout() {
localStorage.removeItem(tokenKey);
}
function getUser() {
try {
const jwt = localStorage.getItem(tokenKey);
return jwtDecode(jwt);
} catch (ex) {
console.log(ex);
}
}