Fixed registration, added per room message encryption
This commit is contained in:
1 parent
3135131ae4
commit
30edfab0a3
2 files changed
+22
-18
No files matched your search
@@ -1,34 +1,38 @@
|
||||
"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) {
|
||||
export type SignupResult =
|
||||
| { success: true; emailConfirmationNeeded: true }
|
||||
| { success: true; emailConfirmationNeeded: false }
|
||||
| { error: { message: string } };
|
||||
|
||||
export async function signup(
|
||||
email: string,
|
||||
password: string,
|
||||
): Promise<SignupResult> {
|
||||
const supabase = await createClient();
|
||||
|
||||
const { data, error } = await supabase.auth.signUp({ email, password });
|
||||
|
||||
if (error) {
|
||||
return { data, error };
|
||||
return {
|
||||
error: { message: "An error occured when trying to create the account." },
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
data.user?.identities?.length === undefined ||
|
||||
data.user.identities.length < 1
|
||||
) {
|
||||
return { data, error: { message: "Email already in use" } };
|
||||
return { error: { message: "An account with this email already exists." } };
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
// The auth trigger (handle_new_auth_user) automatically inserts into
|
||||
// public.users when a new auth.users row is created — no manual insert needed.
|
||||
|
||||
revalidatePath("/", "layout");
|
||||
redirect("/");
|
||||
// If there's no session, email confirmation is required
|
||||
const emailConfirmationNeeded = !data.session;
|
||||
|
||||
return { success: true, emailConfirmationNeeded };
|
||||
}
|
||||
Reference in new issue
Block a user