feat: bootstrap taller-turnos project
Estructura inicial con Next.js 14, PostgreSQL/Prisma 7, autenticación por magic link (clientes) y JWT (admins), lógica de scheduling con 4 slots paralelos y API routes completas para cliente y panel admin. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { cookies } from "next/headers";
|
||||
import { SignJWT, jwtVerify } from "jose";
|
||||
|
||||
const SECRET = new TextEncoder().encode(process.env.NEXTAUTH_SECRET || "dev-secret");
|
||||
const COOKIE = "admin_session";
|
||||
|
||||
export async function crearSesionAdmin(adminId: string): Promise<string> {
|
||||
const token = await new SignJWT({ sub: adminId, role: "admin" })
|
||||
.setProtectedHeader({ alg: "HS256" })
|
||||
.setExpirationTime("8h")
|
||||
.sign(SECRET);
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function crearSesionCliente(clienteId: string): Promise<string> {
|
||||
const token = await new SignJWT({ sub: clienteId, role: "cliente" })
|
||||
.setProtectedHeader({ alg: "HS256" })
|
||||
.setExpirationTime("24h")
|
||||
.sign(SECRET);
|
||||
return token;
|
||||
}
|
||||
|
||||
export async function verificarSesion(
|
||||
cookieName: string
|
||||
): Promise<{ sub: string; role: string } | null> {
|
||||
const cookieStore = await cookies();
|
||||
const token = cookieStore.get(cookieName)?.value;
|
||||
if (!token) return null;
|
||||
try {
|
||||
const { payload } = await jwtVerify(token, SECRET);
|
||||
return payload as { sub: string; role: string };
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user