https://github.com/bezkoder/react-jwt-refresh-token
Buid React JWT Refresh Token example with Axios Interceptors - Refresh Token in React.js, Axios silent refresh JWT token example
https://github.com/bezkoder/react-jwt-refresh-token
authentication authorization jwt jwt-auth jwt-authentication jwt-token react react-authentication reactjs refresh-token token-based-authentication
Last synced: 4 months ago
JSON representation
Buid React JWT Refresh Token example with Axios Interceptors - Refresh Token in React.js, Axios silent refresh JWT token example
- Host: GitHub
- URL: https://github.com/bezkoder/react-jwt-refresh-token
- Owner: bezkoder
- Created: 2021-07-26T03:39:34.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-07-28T05:10:05.000Z (over 4 years ago)
- Last Synced: 2025-04-14T22:37:44.894Z (10 months ago)
- Topics: authentication, authorization, jwt, jwt-auth, jwt-authentication, jwt-token, react, react-authentication, reactjs, refresh-token, token-based-authentication
- Language: JavaScript
- Homepage:
- Size: 415 KB
- Stars: 62
- Watchers: 2
- Forks: 26
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## React Refresh Token with JWT and Axios Interceptors example

For more detail, please visit:
> [React Refresh Token with JWT and Axios Interceptors](https://www.bezkoder.com/react-refresh-token/)
> [React JWT Authentication & Authorization example](https://bezkoder.com/react-jwt-auth/)
Fullstack (JWT Authentication & Authorization example):
> [React + Spring Boot](https://bezkoder.com/spring-boot-react-jwt-auth/)
> [React + Node.js Express](https://bezkoder.com/react-express-authentication-jwt/)
This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
### Set port
.env
```
PORT=8081
```
## Note:
Open `src/services/api.js` and modify `config.headers` for appropriate back-end (found in the tutorial).
```js
instance.interceptors.request.use(
(config) => {
const token = TokenService.getLocalAccessToken();
if (token) {
// config.headers["Authorization"] = 'Bearer ' + token; // for Spring Boot back-end
config.headers["x-access-token"] = token; // for Node.js Express back-end
}
return config;
},
(error) => {
return Promise.reject(error);
}
);
```
## 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](http://localhost:8081) to view it in the browser.
The page will reload if you make edits.
## Related Posts
> [In-depth Introduction to JWT-JSON Web Token](https://bezkoder.com/jwt-json-web-token/)
> [React.js CRUD example to consume Web API](https://bezkoder.com/react-crud-web-api/)
> [React Pagination example](https://bezkoder.com/react-pagination-material-ui/)
> [React File Upload with Axios and Progress Bar to Rest API](https://bezkoder.com/react-file-upload-axios/)
Fullstack (JWT Authentication & Authorization example):
> [React + Spring Boot](https://bezkoder.com/spring-boot-react-jwt-auth/)
> [React + Node.js Express](https://bezkoder.com/react-express-authentication-jwt/)
CRUD with Node.js Express:
> [React.js + Node.js Express + MySQL](https://bezkoder.com/react-node-express-mysql/)
> [React.js + Node.js Express + PostgreSQL](https://bezkoder.com/react-node-express-postgresql/)
> [React.js + Node.js Express + MongoDB](https://bezkoder.com/react-node-express-mongodb-mern-stack/)
CRUD with Spring Boot:
> [React.js + Spring Boot + MySQL](https://bezkoder.com/react-spring-boot-crud/)
> [React.js + Spring Boot + PostgreSQL](https://bezkoder.com/spring-boot-react-postgresql/)
> [React.js + Spring Boot + MongoDB](https://bezkoder.com/react-spring-boot-mongodb/)
CRUD with Django:
> [React.js + Django Rest Framework](https://bezkoder.com/django-react-axios-rest-framework/)
Serverless:
> [React Firebase CRUD App with Realtime Database](https://bezkoder.com/react-firebase-crud/)
> [React Firestore CRUD App example | Firebase Cloud Firestore](https://bezkoder.com/react-firestore-crud/)
Integration (run back-end & front-end on same server/port)
> [Integrate React with Spring Boot](https://bezkoder.com/integrate-reactjs-spring-boot/)
> [Integrate React with Node.js Express](https://bezkoder.com/integrate-react-express-same-server-port/)