initial commit with imported utils from old github project
This commit is contained in:
commit
66bb463e23
39 files changed
+1944
No files matched your search
@@ -0,0 +1,42 @@
|
||||
"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();
|
||||
|
||||
// type-casting here for convenience
|
||||
// in practice, you should validate your inputs
|
||||
const login_data = {
|
||||
email: email,
|
||||
password: password,
|
||||
};
|
||||
const { data, error } = await supabase.auth.signUp(login_data);
|
||||
|
||||
if (error) {
|
||||
return { data, error };
|
||||
} else {
|
||||
if (
|
||||
data.user?.identities?.length == undefined ||
|
||||
data.user.identities.length < 1
|
||||
) {
|
||||
const error = { message: "Email already in use" };
|
||||
return { data, error };
|
||||
} else {
|
||||
//TODO add username field and insert it
|
||||
const name = "anon";
|
||||
//TODO add avatar url field and insert it
|
||||
const { error } = await supabase
|
||||
.from("users")
|
||||
.insert({ id: data.user.id, name: name, email: data.user.email });
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
revalidatePath("/", "layout");
|
||||
redirect("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user