import { AuthError } from "next-auth"; import { redirect } from "next/navigation"; import { auth, signIn } from "@/src/auth"; type LoginPageProps = { searchParams?: Promise<{ error?: string; }>; }; async function login(formData: FormData) { "use server"; try { await signIn("credentials", { identifier: formData.get("identifier"), password: formData.get("password"), redirectTo: "/", }); } catch (error) { if (error instanceof AuthError) { redirect("/login?error=CredentialsSignin"); } throw error; } } export default async function LoginPage({ searchParams }: LoginPageProps) { const session = await auth(); if (session?.user) { redirect("/"); } const params = await searchParams; const hasError = params?.error === "CredentialsSignin"; return (

Accesso

Entra in MagRicambi con utente o email.

{hasError ? (

Credenziali non valide oppure utente non attivo.

) : null}
); }