Vercel's serverless functions only allow writes to /tmp, and it starts empty on every cold start. Point the database there in production and create the User table on first request if it doesn't exist yet, so the app can be deployed for a live preview without manual database setup. Note: this is a demo-friendly stand-in — data does not persist across cold starts on Vercel. A real persistent database is a later phase. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VL5YUEf2B9LG4xdVUQwcSg
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
import { getServerSession } from "next-auth";
|
|
import { redirect } from "next/navigation";
|
|
import { authOptions } from "@/lib/auth";
|
|
import { prisma, ensureDb } from "@/lib/prisma";
|
|
import ProfileEditor from "./profile-editor";
|
|
import SignOutButton from "./sign-out-button";
|
|
|
|
export default async function ProfilePage() {
|
|
const session = await getServerSession(authOptions);
|
|
if (!session?.user?.id) {
|
|
redirect("/login");
|
|
}
|
|
|
|
await ensureDb();
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: { id: session.user.id },
|
|
select: { id: true, name: true, email: true, age: true, bio: true },
|
|
});
|
|
|
|
if (!user) {
|
|
redirect("/login");
|
|
}
|
|
|
|
return (
|
|
<main className="mx-auto flex min-h-screen max-w-sm flex-col justify-center gap-6 px-6 py-12">
|
|
<div className="flex items-center justify-between">
|
|
<h1 className="text-2xl font-bold text-brand">Your profile</h1>
|
|
<SignOutButton />
|
|
</div>
|
|
<p className="text-sm text-gray-500">
|
|
{user.email} · Age {user.age}
|
|
</p>
|
|
<ProfileEditor initialName={user.name} initialBio={user.bio} />
|
|
</main>
|
|
);
|
|
}
|