feat: implement user authentication and route protection using NextAuth middleware and server actions.

This commit is contained in:
Michael committed 2026-02-22 14:23:11 +01:00
1 parent a03fd64b5d
commit 44d7f95d4c
2 files changed
+3 -3

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ export async function loginAction(prevState: string | undefined, formData: FormD
await signIn("credentials", {
username: formData.get("username"),
password: formData.get("password"),
redirectTo: "/dashboard"
redirectTo: "/grid"
});
} catch (error) {
if (error instanceof AuthError) {
+2 -2
View File
@@ -21,7 +21,7 @@ export default auth((req) => {
// 3. Rediriger vers le dashboard si déjà connecté et sur /login
if (isLoggedIn && isPublicRoute) {
return NextResponse.redirect(new URL("/dashboard", nextUrl));
return NextResponse.redirect(new URL("/grid", nextUrl));
}
// 4. Protection par rôle (Admin seulement pour les paramètres)
@@ -29,7 +29,7 @@ export default auth((req) => {
const userRole = (req.auth?.user as any)?.role;
if (isAdminRoute && userRole !== "admin") {
return NextResponse.redirect(new URL("/dashboard", nextUrl));
return NextResponse.redirect(new URL("/grid", nextUrl));
}
return NextResponse.next();