mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-23 19:27:25 +02:00
🐛 Keep redirect in url when switching pages (#1810)
This commit is contained in:
parent
c2701a4d4f
commit
968e513dba
3 changed files with 34 additions and 4 deletions
|
@ -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>
|
||||
);
|
||||
}
|
|
@ -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>
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue