From 63a3e774205bd67f6f08dd33bcbedaf0aecb32c2 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 5 Jul 2020 13:36:22 +0300 Subject: fix: logout user if token expires --- src/requests.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/requests.ts b/src/requests.ts index b02329d..e1f82b4 100644 --- a/src/requests.ts +++ b/src/requests.ts @@ -12,6 +12,14 @@ requests.interceptors.request.use(config => { return _.set(config, 'headers.Authorization', token); }); +requests.interceptors.response.use(response => response, error => { + if (error.message === 'Request failed with status code 401' && localStorage.getItem('token')) { + localStorage.setItem('shouldClear', 'true'); + window.location.reload(); + } + return Promise.reject(error); +}); + export const { get, post, put, patch } = requests; -- cgit v1.2.3