Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion apps/web/src/components/form/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,25 @@ export function LoginForm({
const getRedirectUrl = () => {
const url = new URL(window.location.href);
const redirectParam = url.searchParams.get(URL_PARAM.REDIRECT);

// Case 1: Has redirect param (external localhost or internal path)
if (redirectParam && (redirectParam.startsWith("/") || isAllowedExternalRedirect(redirectParam))) {
return redirectParam;
}

// Case 2: On /login route without redirect -> go to homepage
if (url.pathname === "/login") {
return "/";
return undefined; // Let handleCloseModal decide
}

// Case 3: Modal login (/?modal=login) -> return undefined to close modal and stay/go home
if (url.searchParams.get(URL_PARAM.MODAL) === URL_PARAM_VALUE.LOGIN) {
return undefined;
}

// Case 4: Modal opened on another page -> stay on current page (without modal params)
url.searchParams.delete(URL_PARAM.MODAL);
url.searchParams.delete(URL_PARAM.REDIRECT);
return url.pathname + url.search;
};

Expand Down
21 changes: 12 additions & 9 deletions apps/web/src/routes/__root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,30 @@ function RootLayout() {
};

const handleCloseModal = (redirectUrl?: string) => {
// Handle external redirect (e.g., http://localhost:19999)
// Case 1: External redirect (e.g., http://localhost:29999 from install script)
if (redirectUrl && isAllowedExternalRedirect(redirectUrl)) {
const bearerToken = `Bearer ${accessToken}`;
const encodedToken = btoa(bearerToken);
const target = new URL(redirectUrl);
target.searchParams.set("token", `Bearer ${accessToken}`);
target.searchParams.set("token", encodedToken);
window.location.href = target.toString();
return;
}

if (location.pathname === "/login") {
if (redirectUrl && redirectUrl.startsWith("/")) {
router.navigate({ to: redirectUrl });
}
// Case 2: Internal redirect path (e.g., /dashboard)
if (redirectUrl && redirectUrl.startsWith("/")) {
router.navigate({ to: redirectUrl });
return;
}

if (redirectUrl && redirectUrl.startsWith("/")) {
router.navigate({ to: redirectUrl });
// Case 3: Modal login (/?modal=login) - close modal and go to homepage
// Or /login route without redirect - go to homepage
if (location.pathname === "/login") {
router.navigate({ to: "/" });
return;
}

// Remove the modal search param by navigating without it
// Case 4: Modal was opened on another page - just close modal, stay on current page
const url = new URL(window.location.href);
url.searchParams.delete(URL_PARAM.MODAL);
url.searchParams.delete(URL_PARAM.REDIRECT);
Expand Down
Loading