feat(01-02): configure NextAuth.js v4 with credentials provider and JWT

- Install next-auth@4, bcryptjs, @types/bcryptjs, @types/jest
- src/types/next-auth.d.ts: extend Session/JWT with tenantId, roles, isSuperAdmin
- src/lib/auth-options.ts: CredentialsProvider + JWT/session callbacks, 24h maxAge
- src/lib/auth.ts: getServerSession() and getCurrentUser() server helpers
- src/app/api/auth/[...nextauth]/route.ts: NextAuth GET/POST handler
- src/middleware.ts: withAuth middleware protecting all routes except /login /signup /api/auth/*
This commit is contained in:
kevin-asprec
2026-03-04 18:37:29 +08:00
parent 19a5520dd5
commit 71a9277913
7 changed files with 857 additions and 0 deletions

39
src/types/next-auth.d.ts vendored Normal file
View File

@@ -0,0 +1,39 @@
import { Role } from "@prisma/client";
import "next-auth";
import "next-auth/jwt";
declare module "next-auth" {
interface Session {
user: {
id: string;
email: string;
tenantId: string | null;
roles: Role[];
isSuperAdmin: boolean;
firstName: string;
lastName: string;
};
}
interface User {
id: string;
email: string;
tenantId: string | null;
roles: Role[];
isSuperAdmin: boolean;
firstName: string;
lastName: string;
}
}
declare module "next-auth/jwt" {
interface JWT {
id: string;
email: string;
tenantId: string | null;
roles: Role[];
isSuperAdmin: boolean;
firstName: string;
lastName: string;
}
}