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"; "use server";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { createClient } from "@/utils/supabase/server"; 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 supabase = await createClient();
const { data, error } = await supabase.auth.signUp({ email, password }); const { data, error } = await supabase.auth.signUp({ email, password });
if (error) { if (error) {
return { data, error }; return {
error: { message: "An error occured when trying to create the account." },
};
} }
if ( if (
data.user?.identities?.length === undefined || data.user?.identities?.length === undefined ||
data.user.identities.length < 1 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 // The auth trigger (handle_new_auth_user) automatically inserts into
const { error: insertError } = await supabase // public.users when a new auth.users row is created — no manual insert needed.
.from("users")
.insert({ id: data.user.id, name: "anon", email: data.user.email });
if (insertError) {
throw insertError;
}
revalidatePath("/", "layout"); // If there's no session, email confirmation is required
redirect("/"); const emailConfirmationNeeded = !data.session;
return { success: true, emailConfirmationNeeded };
} }
+3 -3
View File
@@ -4,7 +4,7 @@ import {
privateDecrypt, privateDecrypt,
constants, constants,
subtle, subtle,
} from "crypto"; } from "node:crypto";
import { decryptPrivateKey } from "./decrypt_private_key"; import { decryptPrivateKey } from "./decrypt_private_key";
import { createClient } from "@/utils/supabase/server"; import { createClient } from "@/utils/supabase/server";
@@ -88,8 +88,8 @@ export async function encryptMessageValue(
// Web Crypto AES-GCM output = ciphertext || authTag (last 16 bytes) // Web Crypto AES-GCM output = ciphertext || authTag (last 16 bytes)
const buf = Buffer.from(encrypted); const buf = Buffer.from(encrypted);
const ciphertext = buf.slice(0, buf.length - 16).toString("base64"); const ciphertext = buf.slice(0, - 16).toString("base64");
const authTag = buf.slice(buf.length - 16).toString("base64"); const authTag = buf.slice(- 16).toString("base64");
return { return {
ciphertext, ciphertext,