fix(profile): use correct image column on users table (not avatar_url)
users.avatar_url doesn't exist — the column is `image`. Querying/updating a non-existent column caused a SQL error on every profile load (blank name & email) and on every avatar save/delete. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7816247073
commit
cff17a079d
2 changed files with 8 additions and 8 deletions
|
|
@ -87,10 +87,10 @@ export async function PATCH(req: NextRequest) {
|
|||
if (!avatarUrl) return NextResponse.json({ error: "avatarUrl required" }, { status: 400 });
|
||||
|
||||
// Fetch old URL before overwriting
|
||||
const existing = await sql`SELECT avatar_url FROM users WHERE id = ${userId} LIMIT 1`;
|
||||
const oldUrl: string | null = existing[0]?.avatar_url ?? null;
|
||||
const existing = await sql`SELECT image FROM users WHERE id = ${userId} LIMIT 1`;
|
||||
const oldUrl: string | null = existing[0]?.image ?? null;
|
||||
|
||||
await sql`UPDATE users SET avatar_url = ${avatarUrl}, updated_at = NOW() WHERE id = ${userId}`;
|
||||
await sql`UPDATE users SET image = ${avatarUrl}, updated_at = NOW() WHERE id = ${userId}`;
|
||||
|
||||
// Clean up old R2 object
|
||||
if (oldUrl && oldUrl !== avatarUrl) await deleteOldAvatar(oldUrl);
|
||||
|
|
@ -103,10 +103,10 @@ export async function DELETE(_req: NextRequest) {
|
|||
const userId = await getAuthedUserId();
|
||||
if (!userId) return NextResponse.json({ error: "Not authenticated" }, { status: 401 });
|
||||
|
||||
const existing = await sql`SELECT avatar_url FROM users WHERE id = ${userId} LIMIT 1`;
|
||||
const oldUrl: string | null = existing[0]?.avatar_url ?? null;
|
||||
const existing = await sql`SELECT image FROM users WHERE id = ${userId} LIMIT 1`;
|
||||
const oldUrl: string | null = existing[0]?.image ?? null;
|
||||
|
||||
await sql`UPDATE users SET avatar_url = NULL, updated_at = NOW() WHERE id = ${userId}`;
|
||||
await sql`UPDATE users SET image = NULL, updated_at = NOW() WHERE id = ${userId}`;
|
||||
|
||||
await deleteOldAvatar(oldUrl);
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export async function GET() {
|
|||
|
||||
// Get session and user
|
||||
const sessions = await sql`
|
||||
SELECT s.user_id, s.expires, u.id, u.email, u.name, u.avatar_url, u.created_at
|
||||
SELECT s.user_id, s.expires, u.id, u.email, u.name, u.image, u.created_at
|
||||
FROM sessions s
|
||||
JOIN users u ON u.id = s.user_id
|
||||
WHERE s.session_token = ${sessionToken}
|
||||
|
|
@ -40,7 +40,7 @@ export async function GET() {
|
|||
id: session.id,
|
||||
email: session.email,
|
||||
name: session.name || "Parent",
|
||||
avatarUrl: session.avatar_url || null,
|
||||
avatarUrl: session.image || null,
|
||||
familyId: members?.[0]?.family_id,
|
||||
familyName: members?.[0]?.family_name,
|
||||
memberSince: session.created_at,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue