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:
pascalyazid committed 2026-05-11 21:35:28 +02:00
1 parent 508f17315e
commit 32e4bf8b32
58 files changed
+3270 -362

No files matched your search

+148
View File
@@ -0,0 +1,148 @@
import { createClient } from "@/utils/supabase/server";
import { redirect } from "next/navigation";
import { headers } from "next/headers";
import type { Profile } from "@/types/profile";
import { getSignedAvatarUrl } from "@/utils/assets/avatars";
import { EditableName } from "./editable-name";
import { ShareProfileButton } from "./share-profile";
import { AvatarUpload } from "./avatar-upload";
export default async function ProfilePage() {
const supabase = await createClient();
const {
data: { user },
} = await supabase.auth.getUser();
if (!user) return redirect("/login");
const { data: profile } = await supabase
.from("users")
.select("*")
.eq("id", user.id)
.single<Profile>();
if (!profile) {
return (
<div className="flex h-full items-center justify-center">
<p className="text-neutral-500">Profile not found.</p>
</div>
);
}
// Generate a signed URL for the user's own avatar
const avatarUrl = profile.avatar_url
? await getSignedAvatarUrl(profile.id)
: null;
const memberSince = new Date(profile.created_at).toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
});
// Build the full share URL for the QR code
const requestHeaders = await headers();
const host = requestHeaders.get("host") ?? "localhost:3000";
const protocol = requestHeaders.get("x-forwarded-proto") ?? "https";
const basePath = process.env.BASE_PATH ?? "";
const shareUrl = `${protocol}://${host}${basePath}/friends/add?id=${profile.id}`;
return (
<div className="mx-auto max-w-3xl px-6 py-10">
{/* Header */}
<h1 className="text-2xl font-semibold text-neutral-900">Profile</h1>
<p className="mt-1 text-sm text-neutral-500">
Manage your account information.
</p>
{/* Profile Card */}
<div className="mt-8 rounded-xl border border-neutral-200 bg-white shadow-sm">
{/* Banner area */}
<div className="h-28 rounded-t-xl bg-linear-to-br from-neutral-800 to-neutral-600" />
{/* Avatar + name */}
<div className="relative px-6 pb-6">
<AvatarUpload avatarUrl={avatarUrl} />
<EditableName key={profile.name} currentName={profile.name} />
<div className="mt-3 flex items-center gap-3">
<p className="text-sm text-neutral-500">{profile.email}</p>
<ShareProfileButton userId={profile.id} shareUrl={shareUrl} />
</div>
</div>
</div>
{/* Details */}
<div className="mt-6 space-y-4">
<div className="rounded-xl border border-neutral-200 bg-white shadow-sm">
<div className="border-b border-neutral-100 px-6 py-4">
<h3 className="text-sm font-semibold text-neutral-900">
Account Details
</h3>
</div>
<dl className="divide-y divide-neutral-100">
<DetailRow label="User ID" value={profile.id} mono />
<DetailRow label="Display Name" value={profile.name} />
<DetailRow label="Email" value={profile.email} />
<DetailRow label="Member Since" value={memberSince} />
<DetailRow
label="Identity Verified"
value={profile.has_identity ? "Yes" : "No"}
badge={profile.has_identity ? "green" : "yellow"}
/>
<DetailRow
label="Encryption Keys"
value={
profile.private_key_enc && profile.public_key_dec
? "Set up"
: "Not configured"
}
badge={
profile.private_key_enc && profile.public_key_dec
? "green"
: "yellow"
}
/>
</dl>
</div>
</div>
</div>
);
}
function DetailRow({
label,
value,
mono,
badge,
}: {
label: string;
value: string;
mono?: boolean;
badge?: "green" | "yellow";
}) {
return (
<div className="flex items-center justify-between px-6 py-3.5">
<dt className="text-sm text-neutral-500">{label}</dt>
<dd>
{badge ? (
<span
className={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${
badge === "green"
? "bg-emerald-50 text-emerald-700"
: "bg-amber-50 text-amber-700"
}`}
>
{value}
</span>
) : (
<span
className={`text-sm text-neutral-900 ${mono ? "font-mono text-xs" : ""}`}
>
{value}
</span>
)}
</dd>
</div>
);
}