wulf-pulse/app/api/settings/profile/route.ts
lorentz 3dd379de36 fix: "user" table writes use "updatedAt" not updated_at
Two more sites with the same bug as the theme route — Better Auth's "user"
table column is quoted camelCase. Caught via UAT after the theme PUT fix.

- app/api/settings/profile/route.ts:26 (PATCH admin profile name)
- lib/bootstrap.ts:97 (clearSetupFlag — first-login setup wizard)
2026-05-10 23:03:36 -04:00

39 lines
1 KiB
TypeScript

import { NextRequest, NextResponse } from "next/server";
import { Pool } from "pg";
import { requireAuth, getSession } from "@/lib/auth-utils";
const pool = new Pool({
connectionString: process.env.DATABASE_URL,
});
// PATCH /api/settings/profile - Update current user's profile
export async function PATCH(request: NextRequest) {
const { session, error } = await requireAuth();
if (error) return error;
try {
const body = await request.json();
const { name } = body;
if (!name) {
return NextResponse.json(
{ error: "Name is required" },
{ status: 400 }
);
}
const result = await pool.query(
`UPDATE "user" SET name = $1, "updatedAt" = NOW() WHERE id = $2
RETURNING id, name, email`,
[name, session!.user.id]
);
return NextResponse.json({ user: result.rows[0] });
} catch (error) {
console.error("Error updating profile:", error);
return NextResponse.json(
{ error: "Failed to update profile" },
{ status: 500 }
);
}
}