From ff1343b422d348a36685a79b5ea0ff4e0202c550 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Fri, 11 Jul 2025 13:01:07 +0000 Subject: [PATCH] fix: preserve params when you are not signed in --- apps/remix/app/routes/_unauthenticated+/signin.tsx | 9 ++++++++- apps/remix/app/routes/billing-redirect.tsx | 4 +++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/apps/remix/app/routes/_unauthenticated+/signin.tsx b/apps/remix/app/routes/_unauthenticated+/signin.tsx index 99bad06e6..157643f65 100644 --- a/apps/remix/app/routes/_unauthenticated+/signin.tsx +++ b/apps/remix/app/routes/_unauthenticated+/signin.tsx @@ -20,6 +20,8 @@ export function meta() { export async function loader({ request }: Route.LoaderArgs) { const { isAuthenticated } = await getOptionalSession(request); + const url = new URL(request.url); + const redirectParam = url.searchParams.get('redirect'); // SSR env variables. const isGoogleSSOEnabled = IS_GOOGLE_SSO_ENABLED; @@ -27,6 +29,9 @@ export async function loader({ request }: Route.LoaderArgs) { const oidcProviderLabel = OIDC_PROVIDER_LABEL; if (isAuthenticated) { + if (redirectParam) { + throw redirect(redirectParam); + } throw redirect('/'); } @@ -34,11 +39,12 @@ export async function loader({ request }: Route.LoaderArgs) { isGoogleSSOEnabled, isOIDCSSOEnabled, oidcProviderLabel, + redirectTo: redirectParam, }; } export default function SignIn({ loaderData }: Route.ComponentProps) { - const { isGoogleSSOEnabled, isOIDCSSOEnabled, oidcProviderLabel } = loaderData; + const { isGoogleSSOEnabled, isOIDCSSOEnabled, oidcProviderLabel, redirectTo } = loaderData; return (
@@ -56,6 +62,7 @@ export default function SignIn({ loaderData }: Route.ComponentProps) { isGoogleSSOEnabled={isGoogleSSOEnabled} isOIDCSSOEnabled={isOIDCSSOEnabled} oidcProviderLabel={oidcProviderLabel} + returnTo={redirectTo || undefined} /> {env('NEXT_PUBLIC_DISABLE_SIGNUP') !== 'true' && ( diff --git a/apps/remix/app/routes/billing-redirect.tsx b/apps/remix/app/routes/billing-redirect.tsx index 2a4b6d31c..3b9577b11 100644 --- a/apps/remix/app/routes/billing-redirect.tsx +++ b/apps/remix/app/routes/billing-redirect.tsx @@ -9,7 +9,9 @@ import type { Route } from './+types/billing-redirect'; export async function loader({ request }: Route.LoaderArgs) { const session = await getOptionalSession(request); if (!session.isAuthenticated) { - throw redirect('/signin'); + const currentUrl = new URL(request.url); + const redirectParam = encodeURIComponent(currentUrl.pathname + currentUrl.search); + throw redirect(`/signin?redirect=${redirectParam}`); } const url = new URL(request.url);