feat: implement user authentication and authorization with NextAuth, including user schema, password hashing, and role-based access control.

This commit is contained in:
Michael committed 2026-02-22 14:11:36 +01:00
1 parent c842c2447a
commit 359d196c4d
18 files changed
+652 -32

No files matched your search

+28
View File
@@ -0,0 +1,28 @@
"use server";
import { signIn } from "@/lib/auth";
import { AuthError } from "next-auth";
/**
* Server action to handle user login.
*/
export async function loginAction(prevState: string | undefined, formData: FormData) {
try {
await signIn("credentials", {
username: formData.get("username"),
password: formData.get("password"),
redirectTo: "/dashboard"
});
} catch (error) {
if (error instanceof AuthError) {
switch (error.type) {
case "CredentialsSignin":
return "Utilisateur ou mot de passe incorrect.";
default:
return "Une erreur technique est survenue.";
}
}
// Next.js redirect throws a special error that must be rethrown
throw error;
}
}