Files
prowler/actions/auth.ts
T
2024-08-22 18:04:30 +02:00

31 lines
656 B
TypeScript

"use server";
import { AuthError } from "next-auth";
import { signIn, signOut } from "@/auth.config";
export async function authenticate(
prevState: string | undefined,
formData: FormData,
) {
try {
// await new Promise((resolve) => setTimeout(resolve, 2000));
console.log(formData);
await signIn("credentials", formData);
} catch (error) {
if (error instanceof AuthError) {
switch (error.type) {
case "CredentialsSignin":
return "Invalid credentials.";
default:
return "Something went wrong.";
}
}
throw error;
}
}
export async function logOut() {
await signOut();
}