diff --git a/.env.example b/.env.example index 3c10070..52c5f51 100644 --- a/.env.example +++ b/.env.example @@ -4,7 +4,7 @@ # Copy this file to .env and fill in your values # Database (Required) -DATABASE_URL=postgresql://user:password@localhost:5432/synapsis +DATABASE_URL=postgresql://user:password@localhost/synapsis # Authentication (Required) # Generate with: openssl rand -hex 32 diff --git a/src/app/api/users/[handle]/route.ts b/src/app/api/users/[handle]/route.ts index 65ffba8..4ec5ef8 100644 --- a/src/app/api/users/[handle]/route.ts +++ b/src/app/api/users/[handle]/route.ts @@ -53,7 +53,8 @@ export async function GET(request: Request, context: RouteContext) { displayName: profile.displayName, avatarUrl: profile.avatarUrl || null, did: profile.did || '', - isBot: profile.isBot || false + isBot: profile.isBot || false, + publicKey: profile.publicKey, }); return NextResponse.json({ diff --git a/src/lib/swarm/user-cache.ts b/src/lib/swarm/user-cache.ts index 9277967..010a119 100644 --- a/src/lib/swarm/user-cache.ts +++ b/src/lib/swarm/user-cache.ts @@ -7,6 +7,7 @@ export interface RemoteProfile { avatarUrl?: string | null; did: string; isBot?: boolean; + publicKey?: string; } /** @@ -23,39 +24,27 @@ export async function upsertRemoteUser(profile: RemoteProfile) { if (existing) { // Update metadata if changed - let avatarUrl = profile.avatarUrl || existing.avatarUrl; - - // If still no avatar, generate one and save it "permanently" - if (!avatarUrl) { - const { generateAndUploadAvatar } = await import('@/lib/auth/avatar'); - avatarUrl = await generateAndUploadAvatar(profile.handle); - } + // Self-healing: Update public key if missing + const shouldUpdateKey = profile.publicKey && !existing.publicKey; await db.update(users) .set({ displayName: profile.displayName || existing.displayName, - avatarUrl: avatarUrl, + avatarUrl: profile.avatarUrl || existing.avatarUrl, isBot: profile.isBot ?? existing.isBot, + publicKey: shouldUpdateKey ? profile.publicKey : undefined, // Only update if needed updatedAt: new Date(), }) .where(eq(users.id, existing.id)); } else { - let avatarUrl = profile.avatarUrl; - - // If no avatar provided, generate one - if (!avatarUrl) { - const { generateAndUploadAvatar } = await import('@/lib/auth/avatar'); - avatarUrl = await generateAndUploadAvatar(profile.handle); - } - // Create new placeholder user await db.insert(users).values({ did: profile.did, handle: profile.handle, // user@domain displayName: profile.displayName || profile.handle, - avatarUrl: avatarUrl, + avatarUrl: profile.avatarUrl || null, isBot: profile.isBot || false, - publicKey: '', // We don't necessarily have their public key yet, but DMs often do + publicKey: profile.publicKey || '', // Cache provided key or default to empty // Note: nodeId is null for remote placeholders unless we specifically link it }); }