feat: integrate NextAuth for authentication, refactor login and registration processes, and enhance middleware for session management

This commit is contained in:
Julien Froidefond
2025-10-16 15:50:37 +02:00
parent 9ecdd72804
commit 7426bfb33c
33 changed files with 417 additions and 729 deletions

View File

@@ -0,0 +1,26 @@
import { NextRequest } from "next/server";
import { getToken } from "next-auth/jwt";
export async function getAuthSession(request: NextRequest) {
try {
const token = await getToken({
req: request,
secret: process.env.NEXTAUTH_SECRET
});
if (!token) {
return null;
}
return {
user: {
id: token.sub!,
email: token.email!,
roles: JSON.parse(token.roles as string),
}
};
} catch (error) {
console.error("Auth error in middleware:", error);
return null;
}
}