This commit is contained in:
Timothy Jaeryang Baek
2026-07-26 18:11:12 -04:00
parent 1f0dc90abe
commit 0e0d08382a
3 changed files with 19 additions and 23 deletions
+10 -1
View File
@@ -227,9 +227,14 @@
});
};
const gotoAuth = async () => {
const currentUrl = `${$page.url.pathname}${$page.url.search}`;
await goto(`/auth?redirect=${encodeURIComponent(currentUrl)}`);
};
onMount(async () => {
if ($user === undefined || $user === null) {
await goto('/auth');
await gotoAuth();
return;
}
if (!['user', 'admin'].includes($user?.role)) {
@@ -392,6 +397,10 @@
void openSettingsFromUrl();
}
$: if (loaded && ($user === undefined || $user === null)) {
void gotoAuth();
}
const checkForVersionUpdates = async () => {
version = await getVersionUpdates(localStorage.token).catch((error) => {
return {
+6 -20
View File
@@ -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);
}
}
}
+3 -2
View File
@@ -44,7 +44,8 @@
$: messages = createMessagesList(history, history.currentId);
$: canClone =
$sessionUser && ($sessionUser.role === 'admin' || ($sessionUser.permissions?.chat?.import ?? true));
$sessionUser &&
($sessionUser.role === 'admin' || ($sessionUser.permissions?.chat?.import ?? true));
$: if ($page.params.id) {
(async () => {
@@ -181,7 +182,7 @@
<div
class="pt-5 px-2 w-full {($settings?.widescreenMode ?? null)
? 'max-w-full'
: 'max-w-[52rem]'} mx-auto"
: 'max-w-[58rem]'} mx-auto"
>
<div class="px-3">
<h1 class=" text-2xl font-normal line-clamp-1 m-0">