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"; const identifier = String(formData.get("identifier") ?? "").trim(); console.log("[login-page] Submit login ricevuto", { hasIdentifier: Boolean(identifier), hasPassword: Boolean(formData.get("password")), }); try { await signIn("credentials", { identifier, password: formData.get("password"), redirectTo: "/", }); } catch (error) { if (error instanceof AuthError) { console.log("[login-page] AuthError durante login", { type: error.type, cause: error.cause, }); redirect("/login?error=CredentialsSignin"); } console.error("[login-page] Errore inatteso durante login", { error: error instanceof Error ? error.message : String(error), }); 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}
); }