Files
Fastchat/app/register/actions.ts
T

32 lines
784 B
TypeScript

"use server";
import { signup } from "@/utils/authentication/register";
export type RegisterState = {
error?: string;
} | null;
export async function registerAction(
_prevState: RegisterState,
formData: FormData,
): Promise<RegisterState> {
const email = formData.get("email");
const password = formData.get("password");
if (typeof email !== "string" || typeof password !== "string") {
return { error: "Email and password are required." };
}
try {
const result = await signup(email, password);
if (result?.error) {
return { error: result.error.message ?? "Registration failed." };
}
} catch (error) {
const message = error instanceof Error ? error.message : "Registration failed.";
return { error: message };
}
return null;
}