Server Action Error
Answered
Havana posted this in #help-forum
HavanaOP
Uncaught Error: Only plain objects, and a few built-ins, can be passed to Server Actions. Classes or null prototypes are not supported.
This happens when I used the server action.
note that this is my first time using server actions
here's a signup function that is located here
src/actions/auth.ts
with "use server;"
at the top of that fileexport async function signUp(values: z.infer<typeof signUpSchema>) {
const origin = headers().get("origin");
const email = values.email;
const password = values.password;
const cookieStore = cookies();
const supabase = createClient(cookieStore);
const { error } = await supabase.auth.signUp({
email,
password,
options: {
emailRedirectTo: `${origin}/api/auth/callback`,
},
});
if (error) {
return console.error("Could not authenticate user");
}
return console.log("✅ Signup successfully.");
}
Answered by Ray
try this
export default function Signup() {
const form = useForm<z.infer<typeof signUpSchema>>({
resolver: zodResolver(signUpSchema),
defaultValues: {
email: "",
password: "",
confirmPassword: "",
},
});
const onSubmit = async (values: z.infer<typeof signUpSchema>) => {
await signUp(values)
}
return (
<Card>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<CardHeader>
<CardTitle className="mt-0">Signu
10 Replies
HavanaOP
##
src/components/auth/Signup.tsx
@Havana ## `src/components/auth/Signup.tsx`
don't see issue here
@Havana ## `src/components/auth/Signup.tsx`
try this
export default function Signup() {
const form = useForm<z.infer<typeof signUpSchema>>({
resolver: zodResolver(signUpSchema),
defaultValues: {
email: "",
password: "",
confirmPassword: "",
},
});
const onSubmit = async (values: z.infer<typeof signUpSchema>) => {
await signUp(values)
}
return (
<Card>
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<CardHeader>
<CardTitle className="mt-0">Signu
Answer
HavanaOP
it works!
but how?
can you please explain?
@Havana can you please explain?
because
form.handleSubmit(data, event)
passing a event class to the actionand class is not serializable by react
HavanaOP
Thanks man, Appreciate your help.