Skip to content

Instantly share code, notes, and snippets.

View fredsced's full-sized avatar
🏠
Working from home

fredsced

🏠
Working from home
View GitHub Profile
@fredsced
fredsced / api.js
Created April 26, 2019 20:14
JWT authentication handler using Axios interceptors. It refreshes access token on the fly when backend API throws out a 401 error. Multiple requests at the same time supported.
import axios from 'axios';
import JWTDecode from 'jwt-decode';
import { AuthApi } from './auth.api';
import { config } from '../config';
const { API_ENDPOINT } = config[process.env.NODE_ENV];
axios.defaults.baseURL = API_ENDPOINT;
axios.defaults.timeout = 7000;