redoc123 / react-redux-jwt-auth

React Redux: Token Authentication example with JWT, React Router, Axios, Thunk Middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React Redux JWT Authentication & Authorization example

For more detail, please visit:

React Redux JWT Authentication & Authorization example

React Hooks + Redux: JWT Authentication & Authorization example

React JWT Authentication & Authorization (without Redux) example

Related Posts:

In-depth Introduction to JWT-JSON Web Token

React.js CRUD example to consume Web API

React File Upload with Axios and Progress Bar to Rest API

Fullstack (JWT Authentication & Authorization example):

React + Spring Boot

React + Node.js Express

This project was bootstrapped with Create React App.

Set port

.env

PORT=8081

Note:

Open src/services/auth-header.js and modify return statement for appropriate back-end (found in the tutorial).

export default function authHeader() {
  const user = JSON.parse(localStorage.getItem('user'));

  if (user && user.accessToken) {
    // return { Authorization: 'Bearer ' + user.accessToken }; // for Spring Boot back-end
    return { 'x-access-token': user.accessToken };             // for Node.js Express back-end
  } else {
    return {};
  }
}

Project setup

In the project directory, you can run:

npm install
# or
yarn install

or

Compiles and hot-reloads for development

npm start
# or
yarn start

Open http://localhost:8081 to view it in the browser.

The page will reload if you make edits.

About

React Redux: Token Authentication example with JWT, React Router, Axios, Thunk Middleware


Languages

Language:JavaScript 91.5%Language:HTML 5.4%Language:CSS 3.1%