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:
parent
fb6c0b3202
commit
bd6212a88f
@ -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;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ const handleErrorResponses = (target: string) => async (res: Response) => {
|
||||
error.statusText = res.statusText;
|
||||
throw error;
|
||||
}
|
||||
|
||||
return res;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user