Merge pull request #11950 from shirayu/feat_auth_redirect

feat: Adding auth redirect parameter
This commit is contained in:
Timothy Jaeryang Baek 2025-03-23 11:53:45 -07:00 committed by GitHub
commit d81d1333ba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -496,6 +496,9 @@
if ($config) { if ($config) {
await setupSocket($config.features?.enable_websocket ?? true); await setupSocket($config.features?.enable_websocket ?? true);
const currentUrl = `${window.location.pathname}${window.location.search}`;
const encodedUrl = encodeURIComponent(currentUrl);
if (localStorage.token) { if (localStorage.token) {
// Get Session User Info // Get Session User Info
const sessionUser = await getSessionUser(localStorage.token).catch((error) => { const sessionUser = await getSessionUser(localStorage.token).catch((error) => {
@ -512,13 +515,13 @@
} else { } else {
// Redirect Invalid Session User to /auth Page // Redirect Invalid Session User to /auth Page
localStorage.removeItem('token'); localStorage.removeItem('token');
await goto('/auth'); await goto(`/auth?redirect=${encodedUrl}`);
} }
} else { } else {
// Don't redirect if we're already on the auth page // Don't redirect if we're already on the auth page
// Needed because we pass in tokens from OAuth logins via URL fragments // Needed because we pass in tokens from OAuth logins via URL fragments
if ($page.url.pathname !== '/auth') { if ($page.url.pathname !== '/auth') {
await goto('/auth'); await goto(`/auth?redirect=${encodedUrl}`);
} }
} }
} }