Skip to content

wdi-infinity/lesson-week_11-day_02-react-login

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Authentication with React

gandalf

Clone The repo

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

Run the backend Server

npm install
npm start

React App

Install dependencies

npm install
npm install jwt-decode

Run the app

npm start

add a service

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);
  }
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published