"use server"; import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { createClient } from "@/utils/supabase/server"; export async function signup(email: string, password: string) { const supabase = await createClient(); const { data, error } = await supabase.auth.signUp({ email, password }); if (error) { return { data, error }; } if ( data.user?.identities?.length === undefined || data.user.identities.length < 1 ) { return { data, error: { message: "Email already in use" } }; } // TODO: add username field and insert it const { error: insertError } = await supabase .from("users") .insert({ id: data.user.id, name: "anon", email: data.user.email }); if (insertError) { throw insertError; } revalidatePath("/", "layout"); redirect("/"); }