From 968e513dba808e3dfbf8d65846a3e1a79bfb976b Mon Sep 17 00:00:00 2001 From: Luke Vella Date: Fri, 11 Jul 2025 11:42:28 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Keep=20redirect=20in=20url=20whe?= =?UTF-8?q?n=20switching=20pages=20(#1810)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/link-with-redirect-to.tsx | 30 +++++++++++++++++++ .../src/app/[locale]/(auth)/login/page.tsx | 4 +-- .../src/app/[locale]/(auth)/register/page.tsx | 4 +-- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 apps/web/src/app/[locale]/(auth)/components/link-with-redirect-to.tsx diff --git a/apps/web/src/app/[locale]/(auth)/components/link-with-redirect-to.tsx b/apps/web/src/app/[locale]/(auth)/components/link-with-redirect-to.tsx new file mode 100644 index 000000000..d31264423 --- /dev/null +++ b/apps/web/src/app/[locale]/(auth)/components/link-with-redirect-to.tsx @@ -0,0 +1,30 @@ +"use client"; + +import Link from "next/link"; +import { useSearchParams } from "next/navigation"; + +export function LinkWithRedirectTo({ + href, + className, + children, +}: { + href: string; + className?: string; + children?: React.ReactNode; +}) { + const searchParams = useSearchParams(); + const redirectTo = searchParams.get("redirectTo"); + + return ( + + {children} + + ); +} diff --git a/apps/web/src/app/[locale]/(auth)/login/page.tsx b/apps/web/src/app/[locale]/(auth)/login/page.tsx index 3176a58ec..9be81d6a5 100644 --- a/apps/web/src/app/[locale]/(auth)/login/page.tsx +++ b/apps/web/src/app/[locale]/(auth)/login/page.tsx @@ -1,4 +1,3 @@ -import Link from "next/link"; import { Trans } from "react-i18next/TransWithoutContext"; import { GoogleProvider } from "@/auth/providers/google"; @@ -15,6 +14,7 @@ import { AuthPageHeader, AuthPageTitle, } from "../components/auth-page"; +import { LinkWithRedirectTo } from "../components/link-with-redirect-to"; import { AuthErrors } from "./components/auth-errors"; import { LoginWithEmailForm } from "./components/login-email-form"; import { LoginWithOIDC } from "./components/login-with-oidc"; @@ -96,7 +96,7 @@ export default async function LoginPage(props: { i18nKey="loginFooter" defaults="Don't have an account? Sign up" components={{ - a: , + a: , }} /> diff --git a/apps/web/src/app/[locale]/(auth)/register/page.tsx b/apps/web/src/app/[locale]/(auth)/register/page.tsx index 3e16ccd04..3f2621473 100644 --- a/apps/web/src/app/[locale]/(auth)/register/page.tsx +++ b/apps/web/src/app/[locale]/(auth)/register/page.tsx @@ -1,4 +1,3 @@ -import Link from "next/link"; import { Trans } from "react-i18next/TransWithoutContext"; import { getTranslation } from "@/i18n/server"; @@ -13,6 +12,7 @@ import { AuthPageHeader, AuthPageTitle, } from "../components/auth-page"; +import { LinkWithRedirectTo } from "../components/link-with-redirect-to"; import { RegisterNameForm } from "./components/register-name-form"; export default async function Register(props: { @@ -56,7 +56,7 @@ export default async function Register(props: { i18nKey="alreadyHaveAccount" defaults="Already have an account? Log in" components={{ - a: , + a: , }} />