inserimento accesso come ospite
Some checks failed
Deploy to VPS / build (push) Failing after 50m44s
Deploy to VPS / deploy (push) Has been cancelled

This commit is contained in:
Andre Villari 2026-10-07 15:39:50 +02:00
parent 751b7f24d7
commit e6559dd95a
7 changed files with 554 additions and 442 deletions

View file

@ -1,5 +1,9 @@
<!-- BEGIN:nextjs-agent-rules -->
# This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` before writing any code. Heed deprecation notices.
## This is NOT the Next.js you know
This version has breaking changes — APIs, conventions, and file structure may all differ from your training data. Read the relevant guide in `node_modules/next/dist/docs/` (resolved from this file's directory; in monorepos the `next` package may not be visible from the repo root) before writing any code. Heed deprecation notices.
This block is written and re-added by `next dev` — verify at `node_modules/next/dist/server/lib/generate-agent-files.js`. Removing it from a diff only re-creates the uncommitted change; committing it with your work keeps the tree clean.
<!-- END:nextjs-agent-rules -->

1
next-env.d.ts vendored
View file

@ -1,6 +1,7 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
import "./.next/dev/types/routes.d.ts";
import "./.next/dev/types/root-params.d.ts";
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.

View file

@ -1,5 +1,11 @@
import path from "node:path";
import { fileURLToPath } from "node:url";
/** @type {import('next').NextConfig} */
const nextConfig = {
output: "standalone",
output: "standalone",
turbopack: {
root: path.dirname(fileURLToPath(import.meta.url)),
},
};
export default nextConfig;

915
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,7 @@
"dependencies": {
"bcrypt": "^6.0.0",
"mysql2": "^3.22.3",
"next": "16.2.6",
"next": "^16.4.0",
"next-auth": "^5.0.0-beta.31",
"react": "19.2.6",
"react-dom": "19.2.6"
@ -23,7 +23,7 @@
"@types/react": "19.2.15",
"@types/react-dom": "19.2.3",
"eslint": "^9.0.0",
"eslint-config-next": "16.2.6",
"eslint-config-next": "^16.4.0",
"tailwindcss": "^4",
"typescript": "^5"
},

View file

@ -59,6 +59,31 @@ async function login(formData: FormData) {
}
}
async function loginAsGuest(formData: FormData) {
"use server";
console.log("[login-page] Submit accesso ospite ricevuto");
try {
await signIn("credentials", {
guest: "1",
redirect: false,
});
} catch (error) {
if (error instanceof AuthError) {
console.log("[login-page] AuthError durante accesso ospite", {
type: error.type,
cause: error.cause,
});
redirect("/login?error=CredentialsSignin");
}
throw error;
}
redirect(getSafeRedirectTo(formData.get("callbackUrl")));
}
export default async function LoginPage({ searchParams }: LoginPageProps) {
const session = await auth();
@ -98,6 +123,7 @@ export default async function LoginPage({ searchParams }: LoginPageProps) {
) : null}
<form action={login} className="space-y-4">
<input type="hidden" name="callbackUrl" value={params?.callbackUrl ?? "/"} />
<label className="block">
<span className="text-sm font-medium text-zinc-700">Utente o email</span>
<input
@ -127,6 +153,22 @@ export default async function LoginPage({ searchParams }: LoginPageProps) {
Accedi
</button>
</form>
<div className="my-4 flex items-center gap-3 text-xs text-zinc-400">
<span className="h-px flex-1 bg-zinc-200" />
oppure
<span className="h-px flex-1 bg-zinc-200" />
</div>
<form action={loginAsGuest}>
<input type="hidden" name="callbackUrl" value={params?.callbackUrl ?? "/"} />
<button
type="submit"
className="w-full rounded-md border border-zinc-300 bg-white px-4 py-2 font-medium text-zinc-800 transition-colors hover:bg-zinc-100"
>
Entra come ospite
</button>
</form>
</div>
</section>
</main>

View file

@ -9,6 +9,14 @@ import type { DbUser } from "@/src/types/user";
type DbUserRow = DbUser & RowDataPacket;
const GUEST_USER = {
id: "guest",
name: "Ospite",
email: null as string | null,
ruolo: "operatore" as const,
utente: "Ospite",
};
function maskIdentifier(identifier: string): string {
if (identifier.includes("@")) {
const [name = "", domain = ""] = identifier.split("@");
@ -107,9 +115,19 @@ export const { handlers, auth, signIn, signOut } = NextAuth({
credentials: {
identifier: { label: "Utente o email", type: "text" },
password: { label: "Password", type: "password" },
guest: { label: "Ospite", type: "text" },
},
async authorize(credentials) {
const startedAt = Date.now();
const isGuest = String(credentials?.guest ?? "") === "1";
if (isGuest) {
authLog("Login ospite riuscito", {
durationMs: Date.now() - startedAt,
});
return GUEST_USER;
}
const identifier = String(credentials?.identifier ?? "").trim();
const password = String(credentials?.password ?? "");
const maskedIdentifier = maskIdentifier(identifier);