Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.
TypeScript i18nextnext-authnextjspostgresqlprismareact-emailt3-stacktailwindcsstrpcturborepotypescriptzod
🐛 Keep redirect in url when switching pages (#1810)
Luke Vella968e513dba80
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.tsxnew file mode 100644index 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 (+ <Link+ className={className}+ href={+ redirectTo+ ? `${href}?redirectTo=${encodeURIComponent(redirectTo)}`+ : href+ }+ >+ {children}+ </Link>+ );+}diff --git a/apps/web/src/app/[locale]/(auth)/login/page.tsx b/apps/web/src/app/[locale]/(auth)/login/page.tsxindex 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? <a>Sign up</a>"components={{- a: <Link className="text-link" href="/register" />,+ a: <LinkWithRedirectTo className="text-link" href="/register" />,}}/></AuthPageExternal>diff --git a/apps/web/src/app/[locale]/(auth)/register/page.tsx b/apps/web/src/app/[locale]/(auth)/register/page.tsxindex 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? <a>Log in</a>"components={{- a: <Link className="text-link" href="/login" />,+ a: <LinkWithRedirectTo className="text-link" href="/login" />,}}/></AuthPageExternal>