diff --git a/app/signin/page.tsx b/app/signin/page.tsx index 7fb44745..3a3a687b 100644 --- a/app/signin/page.tsx +++ b/app/signin/page.tsx @@ -8,10 +8,16 @@ export const metadata: Metadata = { title: "Enkun - Connexion", }; -export default async function SignIn() { +export default async function SignIn({ + searchParams, +}: { + searchParams: { callbackUrl?: string }; +}) { const session = await getServerSession(authOptions); - if (session) { + // If user is already authenticated and there's no specific callback URL, + // redirect to the home page + if (session && !searchParams.callbackUrl) { redirect("/"); } @@ -25,7 +31,7 @@ export default async function SignIn() { backgroundRepeat: 'no-repeat' }} > - + ); } diff --git a/components/auth/signin-form.tsx b/components/auth/signin-form.tsx index 0d7bc89f..a577b35f 100644 --- a/components/auth/signin-form.tsx +++ b/components/auth/signin-form.tsx @@ -1,18 +1,18 @@ "use client"; import { signIn } from "next-auth/react"; -import { useSearchParams } from "next/navigation"; -export function SignInForm() { - const searchParams = useSearchParams(); - const callbackUrl = searchParams.get("callbackUrl") || "/"; +interface SignInFormProps { + callbackUrl?: string; +} +export function SignInForm({ callbackUrl }: SignInFormProps) { return (

Bienvenue sur Enkun

Connectez-vous pour accéder à votre espace