1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

fix: account for invalid token in SWR Provider (#561)

* fix: revalidate user on stale data

* fix: swr provider
This commit is contained in:
Fredrik Strand Oseberg 2021-12-15 11:18:10 +01:00 committed by GitHub
parent fb6c0b3202
commit bd6212a88f
2 changed files with 9 additions and 1 deletions

View File

@ -9,6 +9,8 @@ interface ISWRProviderProps {
isUnauthorized: () => boolean;
}
const INVALID_TOKEN_ERROR = 'InvalidTokenError';
const SWRProvider: React.FC<ISWRProviderProps> = ({
children,
setToastData,
@ -20,10 +22,15 @@ const SWRProvider: React.FC<ISWRProviderProps> = ({
const handleFetchError = error => {
setShowLoader(false);
console.log(error.info.name);
if (error.status === 401) {
cache.clear();
const path = location.pathname;
mutate(USER_CACHE_KEY, { ...error.info }, false);
// Only populate user with authDetails if 401 and
// error is not invalid token
if (error?.info?.name !== INVALID_TOKEN_ERROR) {
mutate(USER_CACHE_KEY, { ...error.info }, false);
}
if (path === '/login') {
return;
}

View File

@ -17,6 +17,7 @@ const handleErrorResponses = (target: string) => async (res: Response) => {
error.statusText = res.statusText;
throw error;
}
return res;
};