mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-09 00:18:00 +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:
parent
fb6c0b3202
commit
bd6212a88f
@ -9,6 +9,8 @@ interface ISWRProviderProps {
|
|||||||
isUnauthorized: () => boolean;
|
isUnauthorized: () => boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const INVALID_TOKEN_ERROR = 'InvalidTokenError';
|
||||||
|
|
||||||
const SWRProvider: React.FC<ISWRProviderProps> = ({
|
const SWRProvider: React.FC<ISWRProviderProps> = ({
|
||||||
children,
|
children,
|
||||||
setToastData,
|
setToastData,
|
||||||
@ -20,10 +22,15 @@ const SWRProvider: React.FC<ISWRProviderProps> = ({
|
|||||||
|
|
||||||
const handleFetchError = error => {
|
const handleFetchError = error => {
|
||||||
setShowLoader(false);
|
setShowLoader(false);
|
||||||
|
console.log(error.info.name);
|
||||||
if (error.status === 401) {
|
if (error.status === 401) {
|
||||||
cache.clear();
|
cache.clear();
|
||||||
const path = location.pathname;
|
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') {
|
if (path === '/login') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ const handleErrorResponses = (target: string) => async (res: Response) => {
|
|||||||
error.statusText = res.statusText;
|
error.statusText = res.statusText;
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user