modifica a login

This commit is contained in:
AV77web 2026-05-27 16:46:16 +02:00
parent 487983bf3e
commit 1a81ef0865
7 changed files with 72 additions and 48 deletions

BIN
immagini/Home.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

BIN
public/Home.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

BIN
public/images/Home.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

View file

@ -1,15 +1,28 @@
export default function MainLayout({ import { redirect } from "next/navigation";
import { auth } from "@/src/auth";
import SignOutButton from "@/src/components/auth/SignOutButton";
import Navbar from "@/src/components/Navbar";
export default async function MainLayout({
children, children,
}: { }: {
children: React.ReactNode; children: React.ReactNode;
}) { }) {
const session = await auth();
if (!session?.user) {
redirect("/login");
}
return ( return (
<div> <div>
<Navbar actions={<SignOutButton />} />
<p className="bg-violet-700 text-white w-full text-center py-2"> <p className="bg-violet-700 text-white w-full text-center py-2">
Sono del layout (main) Sono del layout (main)
</p> </p>
<main>{children}</main> <main>{children}</main>
</div> </div>
); );
} }

View file

@ -1,6 +1,8 @@
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
import { auth } from "@/src/auth"; import { auth } from "@/src/auth";
import SignOutButton from "@/src/components/auth/SignOutButton";
import Navbar from "@/src/components/Navbar";
export default async function ManagementLayout({ export default async function ManagementLayout({
children, children,
@ -15,6 +17,7 @@ export default async function ManagementLayout({
return ( return (
<div> <div>
<Navbar actions={<SignOutButton />} />
<header className="border-b border-zinc-200 bg-white"> <header className="border-b border-zinc-200 bg-white">
<div className="mx-auto flex max-w-6xl items-center justify-between px-4 py-3"> <div className="mx-auto flex max-w-6xl items-center justify-between px-4 py-3">
<div> <div>

View file

@ -1,8 +1,5 @@
import type { Metadata } from "next"; import type { Metadata } from "next";
import { Inter, JetBrains_Mono } from "next/font/google"; import { Inter, JetBrains_Mono } from "next/font/google";
import { auth } from "@/src/auth";
import SignOutButton from "@/src/components/auth/SignOutButton";
import Navbar from "../components/Navbar";
import "./globals.css"; import "./globals.css";
/** Stesse variabili CSS di globals.css; Geist non è disponibile in next/font su Next 14. */ /** Stesse variabili CSS di globals.css; Geist non è disponibile in next/font su Next 14. */
@ -26,15 +23,12 @@ export default async function RootLayout({
}: Readonly<{ }: Readonly<{
children: React.ReactNode; children: React.ReactNode;
}>) { }>) {
const session = await auth();
return ( return (
<html lang="en"> <html lang="en">
<body className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}> <body className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}>
<p className="bg-purple-700 text-white w-full text-center py-2"> <p className="bg-purple-700 text-white w-full text-center py-2">
Sono del layout root Sono del layout root
</p> </p>
{session?.user ? <Navbar actions={<SignOutButton />} /> : null}
{children} {children}
</body> </body>
</html> </html>

View file

@ -1,3 +1,4 @@
import Image from "next/image";
import { AuthError } from "next-auth"; import { AuthError } from "next-auth";
import { redirect } from "next/navigation"; import { redirect } from "next/navigation";
@ -52,51 +53,64 @@ export default async function LoginPage({ searchParams }: LoginPageProps) {
const hasError = params?.error === "CredentialsSignin"; const hasError = params?.error === "CredentialsSignin";
return ( return (
<main className="flex min-h-[calc(100vh-4rem)] items-center justify-center bg-zinc-50 px-4 py-12"> <main className="flex min-h-screen items-center justify-center bg-zinc-50 px-4 py-12">
<section className="w-full max-w-sm rounded-lg border border-zinc-200 bg-white p-6 shadow-sm"> <section className="w-full max-w-sm overflow-hidden rounded-lg border border-zinc-200 bg-white shadow-sm">
<div className="mb-6"> <div className="relative h-48 w-full bg-zinc-100">
<Image
src="/images/Home.jpg"
alt="MagRicambi"
fill
priority
className="object-contain"
sizes="(max-width: 640px) 100vw, 384px"
/>
</div>
<div className="p-6">
<div className="mb-6">
<h1 className="text-2xl font-semibold text-zinc-950">Accesso</h1> <h1 className="text-2xl font-semibold text-zinc-950">Accesso</h1>
<p className="mt-2 text-sm text-zinc-600"> <p className="mt-2 text-sm text-zinc-600">
Entra in MagRicambi con utente o email. Entra in MagRicambi con utente o email.
</p> </p>
</div>
{hasError ? (
<p className="mb-4 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700">
Credenziali non valide oppure utente non attivo.
</p>
) : null}
<form action={login} className="space-y-4">
<label className="block">
<span className="text-sm font-medium text-zinc-700">Utente o email</span>
<input
required
autoComplete="username"
name="identifier"
type="text"
className="mt-1 w-full rounded-md border border-zinc-300 px-3 py-2 text-zinc-950 outline-none transition-colors focus:border-zinc-900"
/>
</label>
<label className="block">
<span className="text-sm font-medium text-zinc-700">Password</span>
<input
required
autoComplete="current-password"
name="password"
type="password"
className="mt-1 w-full rounded-md border border-zinc-300 px-3 py-2 text-zinc-950 outline-none transition-colors focus:border-zinc-900"
/>
</label>
<button
type="submit"
className="w-full rounded-md bg-zinc-950 px-4 py-2 font-medium text-white transition-colors hover:bg-zinc-800"
>
Accedi
</button>
</form>
</div> </div>
{hasError ? (
<p className="mb-4 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700">
Credenziali non valide oppure utente non attivo.
</p>
) : null}
<form action={login} className="space-y-4">
<label className="block">
<span className="text-sm font-medium text-zinc-700">Utente o email</span>
<input
required
autoComplete="username"
name="identifier"
type="text"
className="mt-1 w-full rounded-md border border-zinc-300 px-3 py-2 text-zinc-950 outline-none transition-colors focus:border-zinc-900"
/>
</label>
<label className="block">
<span className="text-sm font-medium text-zinc-700">Password</span>
<input
required
autoComplete="current-password"
name="password"
type="password"
className="mt-1 w-full rounded-md border border-zinc-300 px-3 py-2 text-zinc-950 outline-none transition-colors focus:border-zinc-900"
/>
</label>
<button
type="submit"
className="w-full rounded-md bg-zinc-950 px-4 py-2 font-medium text-white transition-colors hover:bg-zinc-800"
>
Accedi
</button>
</form>
</section> </section>
</main> </main>
); );