refac
This commit is contained in:
1 parent
1f0dc90abe
commit
0e0d08382a
3 files changed
+19
-23
No files matched your search
@@ -837,8 +837,8 @@
|
||||
}
|
||||
};
|
||||
|
||||
const redirectToAuthAfterUnauthorized = () => {
|
||||
if (isAuthRedirectInProgress || window.location.pathname === '/auth') {
|
||||
const clearExpiredSession = () => {
|
||||
if (isAuthRedirectInProgress) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -855,11 +855,7 @@
|
||||
console.error('Error signing out expired session:', error);
|
||||
});
|
||||
toast.error($i18n.t('Session expired. Please sign in again.'));
|
||||
|
||||
const currentPath = `${window.location.pathname}${window.location.search}`;
|
||||
goto(`/auth?redirect=${encodeURIComponent(currentPath)}`).finally(() => {
|
||||
isAuthRedirectInProgress = false;
|
||||
});
|
||||
isAuthRedirectInProgress = false;
|
||||
};
|
||||
|
||||
const isCurrentSessionUnauthorized = async (originalFetch) => {
|
||||
@@ -885,7 +881,7 @@
|
||||
}
|
||||
|
||||
if (now >= exp - TOKEN_EXPIRY_BUFFER) {
|
||||
redirectToAuthAfterUnauthorized();
|
||||
clearExpiredSession();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1003,7 +999,7 @@
|
||||
isAuthenticatedBackendFetch(input, init) &&
|
||||
(await isCurrentSessionUnauthorized(originalFetch))
|
||||
) {
|
||||
redirectToAuthAfterUnauthorized();
|
||||
clearExpiredSession();
|
||||
}
|
||||
|
||||
return response;
|
||||
@@ -1189,9 +1185,6 @@
|
||||
if ($config) {
|
||||
await setupSocket($config.features?.enable_websocket ?? true);
|
||||
|
||||
const currentUrl = `${window.location.pathname}${window.location.search}`;
|
||||
const encodedUrl = encodeURIComponent(currentUrl);
|
||||
|
||||
if (localStorage.token) {
|
||||
// Get Session User Info
|
||||
const sessionUser = await getSessionUser(localStorage.token).catch((error) => {
|
||||
@@ -1223,15 +1216,8 @@
|
||||
.catch(() => {});
|
||||
}
|
||||
} else {
|
||||
// Redirect Invalid Session User to /auth Page
|
||||
localStorage.removeItem('token');
|
||||
await goto(`/auth?redirect=${encodedUrl}`);
|
||||
}
|
||||
} else {
|
||||
// Don't redirect if we're already on the auth page
|
||||
// Needed because we pass in tokens from OAuth logins via URL fragments
|
||||
if ($page.url.pathname !== '/auth') {
|
||||
await goto(`/auth?redirect=${encodedUrl}`);
|
||||
await user.set(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user