Initial SeConectai briefing system
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
"use server";
|
||||
|
||||
import { AuthError } from "next-auth";
|
||||
import { redirect } from "next/navigation";
|
||||
import { signIn } from "@/auth";
|
||||
|
||||
export type LoginState = {
|
||||
ok: boolean;
|
||||
message?: string;
|
||||
};
|
||||
|
||||
export async function login(_state: LoginState, formData: FormData): Promise<LoginState> {
|
||||
const callbackUrl = formData.get("callbackUrl")?.toString();
|
||||
|
||||
try {
|
||||
await signIn("credentials", {
|
||||
email: formData.get("email"),
|
||||
senha: formData.get("senha"),
|
||||
redirectTo: callbackUrl || undefined
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof AuthError) {
|
||||
return {
|
||||
ok: false,
|
||||
message: "E-mail ou senha invalidos."
|
||||
};
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
redirect(callbackUrl || "/briefings");
|
||||
}
|
||||
Reference in New Issue
Block a user