Skip to content

Commit 09a1435

Browse files
fix: resolve [object Object] in redirect URL and prevent query param leakage (#2338)
- Convert location.search object to query string in app route beforeLoad - Use redirect({ href: ... }) instead of redirect({ to: ... }) in callback to prevent callback query params from leaking to destination URL Fixes issue where navigating to checkout without login resulted in URLs like /auth?redirect=/app/checkout[object Object] and after login the callback params (code, scheme, redirect) were preserved in the destination URL. Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: yujonglee <[email protected]>
1 parent 4db150f commit 09a1435

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

apps/web/src/routes/_view/app/route.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ export const Route = createFileRoute("/_view/app")({
66
beforeLoad: async ({ location }) => {
77
const user = await fetchUser();
88
if (!user) {
9+
const searchStr =
10+
Object.keys(location.search).length > 0
11+
? `?${new URLSearchParams(location.search as Record<string, string>).toString()}`
12+
: "";
913
throw redirect({
1014
to: "/auth",
1115
search: {
1216
flow: "web",
13-
redirect: location.pathname + location.search,
17+
redirect: location.pathname + searchStr,
1418
},
1519
});
1620
}

apps/web/src/routes/_view/callback/auth.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export const Route = createFileRoute("/_view/callback/auth")({
2323
const { error } = await supabase.auth.exchangeCodeForSession(search.code);
2424

2525
if (!error) {
26-
throw redirect({ to: search.redirect || "/app/account" });
26+
throw redirect({ href: search.redirect || "/app/account" });
2727
} else {
2828
console.error(error);
2929
}
@@ -86,7 +86,7 @@ function Component() {
8686

8787
useEffect(() => {
8888
if (search.flow === "web") {
89-
throw redirect({ to: search.redirect || "/app/account" });
89+
throw redirect({ href: search.redirect || "/app/account" });
9090
}
9191

9292
if (

0 commit comments

Comments
 (0)