mirror of
https://github.com/R0m1k3/CollectFlow.git
synced 2026-10-15 11:18:42 +02:00
feat: implement user authentication and authorization with NextAuth, including user schema, password hashing, and role-based access control.
This commit is contained in:
1 parent
c842c2447a
commit
359d196c4d
18 files changed
+652
-32
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user