f0397740d7
Usernames are auto-assigned at signup (shipped earlier this session) but there was still no way to change one. Adds a Username field to Settings, validated client- and server-side against the same 3-20-char lowercase/digits/underscore pattern used for generation, with a 409 on collision (excluding the user's own current username). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import type { Metadata } from "next";
|
|
import { headers } from "next/headers";
|
|
import { auth } from "@/lib/auth/server";
|
|
import { db, users, eq } from "@epicure/db";
|
|
import { SettingsForm } from "@/components/settings/settings-form";
|
|
|
|
export const metadata: Metadata = {};
|
|
|
|
export default async function SettingsPage() {
|
|
const session = await auth.api.getSession({ headers: await headers() });
|
|
if (!session) return null;
|
|
|
|
const dbUser = await db.query.users.findFirst({
|
|
where: eq(users.id, session.user.id),
|
|
columns: { bio: true, privateBio: true, isPrivate: true, hasCustomAvatar: true, avatarUrl: true, username: true },
|
|
});
|
|
|
|
return (
|
|
<SettingsForm
|
|
user={{
|
|
name: session.user.name,
|
|
email: session.user.email,
|
|
image: dbUser?.avatarUrl ?? null,
|
|
locale: (session.user as { locale?: string }).locale ?? "en",
|
|
bio: dbUser?.bio ?? null,
|
|
privateBio: dbUser?.privateBio ?? null,
|
|
isPrivate: dbUser?.isPrivate ?? false,
|
|
hasCustomAvatar: dbUser?.hasCustomAvatar ?? false,
|
|
username: dbUser?.username ?? null,
|
|
}}
|
|
/>
|
|
);
|
|
}
|