Fixed registration, added per room message encryption

This commit is contained in:
pascalyazid committed 2026-05-15 18:39:21 +02:00
1 parent 3135131ae4
commit 30edfab0a3
2 files changed
+22 -18

No files matched your search

+19 -15
View File
@@ -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 };
}
+3 -3
View File
@@ -4,7 +4,7 @@ import {
privateDecrypt,
constants,
subtle,
} from "crypto";
} from "node:crypto";
import { decryptPrivateKey } from "./decrypt_private_key";
import { createClient } from "@/utils/supabase/server";
@@ -88,8 +88,8 @@ export async function encryptMessageValue(
// Web Crypto AES-GCM output = ciphertext || authTag (last 16 bytes)
const buf = Buffer.from(encrypted);
const ciphertext = buf.slice(0, buf.length - 16).toString("base64");
const authTag = buf.slice(buf.length - 16).toString("base64");
const ciphertext = buf.slice(0, - 16).toString("base64");
const authTag = buf.slice(- 16).toString("base64");
return {
ciphertext,