diff options
author | eug-vs <eug-vs@keemail.me> | 2020-07-05 13:36:22 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-07-05 13:36:22 +0300 |
commit | 63a3e774205bd67f6f08dd33bcbedaf0aecb32c2 (patch) | |
tree | 3605892c05b6a7b72ac3004ce5eeb33e31db70fc | |
parent | e08140bf69c10b0bd313da4bce0abdabf29ef709 (diff) | |
download | which-ui-63a3e774205bd67f6f08dd33bcbedaf0aecb32c2.tar.gz |
fix: logout user if token expires
-rw-r--r-- | src/requests.ts | 8 |
1 files changed, 8 insertions, 0 deletions
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; |