feat: Add public key to user profiles in API responses and update user caching logic to store and manage it.
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
# Copy this file to .env and fill in your values
|
# Copy this file to .env and fill in your values
|
||||||
|
|
||||||
# Database (Required)
|
# Database (Required)
|
||||||
DATABASE_URL=postgresql://user:password@localhost:5432/synapsis
|
DATABASE_URL=postgresql://user:password@localhost/synapsis
|
||||||
|
|
||||||
# Authentication (Required)
|
# Authentication (Required)
|
||||||
# Generate with: openssl rand -hex 32
|
# Generate with: openssl rand -hex 32
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ export async function GET(request: Request, context: RouteContext) {
|
|||||||
displayName: profile.displayName,
|
displayName: profile.displayName,
|
||||||
avatarUrl: profile.avatarUrl || null,
|
avatarUrl: profile.avatarUrl || null,
|
||||||
did: profile.did || '',
|
did: profile.did || '',
|
||||||
isBot: profile.isBot || false
|
isBot: profile.isBot || false,
|
||||||
|
publicKey: profile.publicKey,
|
||||||
});
|
});
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export interface RemoteProfile {
|
|||||||
avatarUrl?: string | null;
|
avatarUrl?: string | null;
|
||||||
did: string;
|
did: string;
|
||||||
isBot?: boolean;
|
isBot?: boolean;
|
||||||
|
publicKey?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,39 +24,27 @@ export async function upsertRemoteUser(profile: RemoteProfile) {
|
|||||||
|
|
||||||
if (existing) {
|
if (existing) {
|
||||||
// Update metadata if changed
|
// Update metadata if changed
|
||||||
let avatarUrl = profile.avatarUrl || existing.avatarUrl;
|
// Self-healing: Update public key if missing
|
||||||
|
const shouldUpdateKey = profile.publicKey && !existing.publicKey;
|
||||||
// If still no avatar, generate one and save it "permanently"
|
|
||||||
if (!avatarUrl) {
|
|
||||||
const { generateAndUploadAvatar } = await import('@/lib/auth/avatar');
|
|
||||||
avatarUrl = await generateAndUploadAvatar(profile.handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
await db.update(users)
|
await db.update(users)
|
||||||
.set({
|
.set({
|
||||||
displayName: profile.displayName || existing.displayName,
|
displayName: profile.displayName || existing.displayName,
|
||||||
avatarUrl: avatarUrl,
|
avatarUrl: profile.avatarUrl || existing.avatarUrl,
|
||||||
isBot: profile.isBot ?? existing.isBot,
|
isBot: profile.isBot ?? existing.isBot,
|
||||||
|
publicKey: shouldUpdateKey ? profile.publicKey : undefined, // Only update if needed
|
||||||
updatedAt: new Date(),
|
updatedAt: new Date(),
|
||||||
})
|
})
|
||||||
.where(eq(users.id, existing.id));
|
.where(eq(users.id, existing.id));
|
||||||
} else {
|
} 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
|
// Create new placeholder user
|
||||||
await db.insert(users).values({
|
await db.insert(users).values({
|
||||||
did: profile.did,
|
did: profile.did,
|
||||||
handle: profile.handle, // user@domain
|
handle: profile.handle, // user@domain
|
||||||
displayName: profile.displayName || profile.handle,
|
displayName: profile.displayName || profile.handle,
|
||||||
avatarUrl: avatarUrl,
|
avatarUrl: profile.avatarUrl || null,
|
||||||
isBot: profile.isBot || false,
|
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
|
// Note: nodeId is null for remote placeholders unless we specifically link it
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user