mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-11 17:26:32 +02:00
feat: implement user authentication and route protection using NextAuth middleware and server actions.
This commit is contained in:
1 parent
a03fd64b5d
commit
44d7f95d4c
2 files changed
+3
-3
No files matched your search
@@ -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
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user