refac
This commit is contained in:
1 parent
5134e5ecfc
commit
f6baa1bb77
1 file changed
+16
-1
@@ -810,6 +810,20 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const isAuthFailureResponse = async (response) => {
|
||||||
|
try {
|
||||||
|
const data = await response.clone().json();
|
||||||
|
const detail = data?.detail;
|
||||||
|
return (
|
||||||
|
detail === '401 Unauthorized' ||
|
||||||
|
detail === 'Not authenticated' ||
|
||||||
|
detail === 'Your session has expired or the token is invalid. Please sign in again.'
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const checkTokenExpiry = async () => {
|
const checkTokenExpiry = async () => {
|
||||||
const exp = $user?.expires_at; // token expiry time in unix timestamp
|
const exp = $user?.expires_at; // token expiry time in unix timestamp
|
||||||
const now = Math.floor(Date.now() / 1000); // current time in unix timestamp
|
const now = Math.floor(Date.now() / 1000); // current time in unix timestamp
|
||||||
@@ -939,7 +953,8 @@
|
|||||||
if (
|
if (
|
||||||
response.status === 401 &&
|
response.status === 401 &&
|
||||||
localStorage.token &&
|
localStorage.token &&
|
||||||
isAuthenticatedBackendFetch(input, init)
|
isAuthenticatedBackendFetch(input, init) &&
|
||||||
|
(await isAuthFailureResponse(response))
|
||||||
) {
|
) {
|
||||||
redirectToAuthAfterUnauthorized();
|
redirectToAuthAfterUnauthorized();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user