File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 810810 });
811811 };
812812
813+ const isAuthFailureResponse = async (response) => {
814+ try {
815+ const data = await response.clone().json();
816+ const detail = data?.detail;
817+ return (
818+ detail === '401 Unauthorized' ||
819+ detail === 'Not authenticated' ||
820+ detail === 'Your session has expired or the token is invalid. Please sign in again.'
821+ );
822+ } catch {
823+ return true;
824+ }
825+ };
826+
813827 const checkTokenExpiry = async () => {
814828 const exp = $user?.expires_at; // token expiry time in unix timestamp
815829 const now = Math.floor(Date.now() / 1000); // current time in unix timestamp
939953 if (
940954 response.status === 401 &&
941955 localStorage.token &&
942- isAuthenticatedBackendFetch(input, init)
956+ isAuthenticatedBackendFetch(input, init) &&
957+ (await isAuthFailureResponse(response))
943958 ) {
944959 redirectToAuthAfterUnauthorized();
945960 }
You can’t perform that action at this time.
0 commit comments