Skip to content

Instantly share code, notes, and snippets.

View smorstabilini's full-sized avatar

Sergio Morstabilini smorstabilini

View GitHub Profile
axiosInstance.interceptors.response.use(
response => response,
error => {
const originalRequest = error.config;
if (error.response.status === 401 && error.response.statusText === "Unauthorized"
&& error.response.data.code === "token_not_valid") {
const refreshToken = localStorage.getItem('refresh_token');
if (refreshToken) {
const tokenParts = JSON.parse(atob(refreshToken.split('.')[1]));
// exp date in token is expressed in seconds, while now() returns milliseconds: