bezkoder/react-jwt-auth
关于
React JWT 身份验证与授权示例——React.js 登录和注册示例
安全与隐私实测星标增长
- 24小时
- 0
- 7天
- 0
- 15天
- +1
- 1个月
- 正在收集历史
各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。
README.md
原文React JWT Authentication (without Redux) example
In this tutorial, we’re gonna build a React JWT Authentication example with LocalStorage, React Router, Axios and Bootstrap (without Redux). I will show you:
- JWT Authentication Flow for User Signup & User Login
- Project Structure for React JWT Authentication (without Redux) with LocalStorage, React Router & Axios
- Creating React Components with Form Validation
- React Components for accessing protected Resources (Authorization)
- Dynamic Navigation Bar in React App
User Registration and User Login Flow
For JWT Authentication, we’re gonna call 2 endpoints:
- POST
api/auth/signupfor User Registration - POST
api/auth/signinfor User Login
The following flow shows you an overview of Requests and Responses that React Client will make or receive. This React Client must add a JWT to HTTP Header before sending request to protected resources.

Demo Video
This is full React + Node.js Express JWT Authentication & Authorization demo (with form validation, check signup username/email duplicates, test authorization with 3 roles: Admin, Moderator, User):
Or React with Spring Boot Server:
React Component Diagram with Router, Axios & LocalStorage

For more detail, please visit:
React (without Redux) JWT Authentication & Authorization example
React JWT Authentication & Authorization example with HttpOnly Cookie
React + Redux + Hooks: JWT Authentication & Authorization example
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.
Related Posts
Fullstack (JWT Authentication & Authorization example):
CRUD with Node.js Express:
CRUD with Spring Boot:
CRUD with Django:
Serverless:
Integration (run back-end & front-end on same server/port)
探索相关项目
加载中…

