Reimplemented outdated code, added encryption keys for each room, added support for profile images, added friend requests via url/qr-code
This commit is contained in:
1 parent
508f17315e
commit
32e4bf8b32
58 files changed
+3270
-362
No files matched your search
@@ -8,35 +8,27 @@ 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);
|
||||
const { data, error } = await supabase.auth.signUp({ email, password });
|
||||
|
||||
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("/");
|
||||
}
|
||||
}
|
||||
|
||||
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("/");
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
"use server";
|
||||
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
import { createClient } from "@/utils/supabase/server";
|
||||
import { validateIdentity } from "@/utils/security/validate_identity";
|
||||
import { storeAccessKey_Cookie } from "@/utils/security/access_storage";
|
||||
@@ -10,30 +9,29 @@ import { deriveKey } from "@/utils/security/encryption";
|
||||
export async function login(email: string, password: string) {
|
||||
const supabase = await createClient();
|
||||
|
||||
const login_data = {
|
||||
email: email,
|
||||
password: password,
|
||||
};
|
||||
const { data, error } = await supabase.auth.signInWithPassword(login_data);
|
||||
const { data, error } = await supabase.auth.signInWithPassword({
|
||||
email,
|
||||
password,
|
||||
});
|
||||
|
||||
if (error) {
|
||||
return { data, error };
|
||||
} else {
|
||||
await validateIdentity(password);
|
||||
const { data, error } = await supabase
|
||||
.from("users")
|
||||
.select("salt")
|
||||
.eq("id", (await supabase.auth.getUser()).data.user?.id)
|
||||
.single();
|
||||
|
||||
if (error) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const salt = Uint8Array.from(atob(data.salt), (c) => c.charCodeAt(0));
|
||||
const key = await deriveKey(password, salt);
|
||||
storeAccessKey_Cookie(key);
|
||||
revalidatePath("/profile", "layout");
|
||||
redirect("/profile");
|
||||
}
|
||||
|
||||
await validateIdentity(password);
|
||||
const { data: saltData, error: saltError } = await supabase
|
||||
.from("users")
|
||||
.select("salt")
|
||||
.eq("id", (await supabase.auth.getUser()).data.user?.id)
|
||||
.single();
|
||||
|
||||
if (saltError) {
|
||||
throw saltError;
|
||||
}
|
||||
|
||||
const salt = Uint8Array.from(atob(saltData.salt), (c) => c.charCodeAt(0));
|
||||
const key = await deriveKey(password, salt);
|
||||
await storeAccessKey_Cookie(key);
|
||||
revalidatePath("/profile", "layout");
|
||||
return { success: true };
|
||||
}
|
||||
Reference in new issue
Block a user