feat: remove avatar on GitHub disconnect

Update GitHub disconnect endpoint to also remove user avatar:
- Clear avatar field in database (set to Prisma.JsonNull)
- Include avatar removal in account update broadcast
- Update logging to reflect avatar removal

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Steve Korshakov 2025-08-26 23:38:09 -07:00
parent 5269de150a
commit 42f2f30b6a

View File

@ -5,7 +5,7 @@ import { Server, Socket } from "socket.io";
import { z } from "zod"; import { z } from "zod";
import * as privacyKit from "privacy-kit"; import * as privacyKit from "privacy-kit";
import { db } from "@/storage/db"; import { db } from "@/storage/db";
import { Account } from "@prisma/client"; import { Account, Prisma } from "@prisma/client";
import { onShutdown } from "@/utils/shutdown"; import { onShutdown } from "@/utils/shutdown";
import { allocateSessionSeq, allocateUserSeq } from "@/services/seq"; import { allocateSessionSeq, allocateUserSeq } from "@/services/seq";
import { randomKeyNaked } from "@/utils/randomKeyNaked"; import { randomKeyNaked } from "@/utils/randomKeyNaked";
@ -633,10 +633,13 @@ export async function startApi(): Promise<{ app: FastifyInstance; io: Server }>
// Remove GitHub connection from account and delete GitHub user record // Remove GitHub connection from account and delete GitHub user record
await db.$transaction(async (tx) => { await db.$transaction(async (tx) => {
// Remove link from account // Remove link from account and clear avatar
await tx.account.update({ await tx.account.update({
where: { id: userId }, where: { id: userId },
data: { githubUserId: null } data: {
githubUserId: null,
avatar: Prisma.JsonNull
}
}); });
// Delete GitHub user record (this also deletes the token) // Delete GitHub user record (this also deletes the token)
@ -648,7 +651,8 @@ export async function startApi(): Promise<{ app: FastifyInstance; io: Server }>
// Send account update to all user connections // Send account update to all user connections
const updSeq = await allocateUserSeq(userId); const updSeq = await allocateUserSeq(userId);
const updatePayload = buildUpdateAccountUpdate(userId, { const updatePayload = buildUpdateAccountUpdate(userId, {
github: null github: null,
avatar: null
}, updSeq, randomKeyNaked(12)); }, updSeq, randomKeyNaked(12));
eventRouter.emitUpdate({ eventRouter.emitUpdate({
userId, userId,
@ -656,7 +660,7 @@ export async function startApi(): Promise<{ app: FastifyInstance; io: Server }>
recipientFilter: { type: 'all-user-authenticated-connections' } recipientFilter: { type: 'all-user-authenticated-connections' }
}); });
log({ module: 'github-disconnect' }, `GitHub account disconnected successfully for user ${userId}`); log({ module: 'github-disconnect' }, `GitHub account and avatar disconnected successfully for user ${userId}`);
return reply.send({ success: true }); return reply.send({ success: true });