feat(users): Add remote placeholder refresh logic to user profile endpoint
- Add detection for remote placeholder users (handles containing @) - Implement fresh data fetching from remote when placeholder is detected - Refactor conditional logic to treat stale placeholders as missing users - Only return 404 error if user is genuinely not found, not for refresh attempts - Improves data freshness for federated user profiles by re-fetching from source
This commit is contained in:
@@ -88,7 +88,10 @@ export async function GET(request: Request, context: RouteContext) {
|
|||||||
where: eq(users.handle, cleanHandle),
|
where: eq(users.handle, cleanHandle),
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!user) {
|
// If user exists but is a remote placeholder (handle contains @), fetch fresh data from remote
|
||||||
|
const isRemotePlaceholder = user && cleanHandle.includes('@');
|
||||||
|
|
||||||
|
if (!user || isRemotePlaceholder) {
|
||||||
if (remoteHandle && remoteDomain) {
|
if (remoteHandle && remoteDomain) {
|
||||||
// Try Swarm API first (for Synapsis nodes)
|
// Try Swarm API first (for Synapsis nodes)
|
||||||
const swarmData = await fetchSwarmProfile(remoteHandle, remoteDomain);
|
const swarmData = await fetchSwarmProfile(remoteHandle, remoteDomain);
|
||||||
@@ -157,7 +160,10 @@ export async function GET(request: Request, context: RouteContext) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NextResponse.json({ error: 'User not found' }, { status: 404 });
|
// Only return 404 if this wasn't a remote placeholder we were trying to refresh
|
||||||
|
if (!isRemotePlaceholder) {
|
||||||
|
return NextResponse.json({ error: 'User not found' }, { status: 404 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (user.isSuspended) {
|
if (user.isSuspended) {
|
||||||
return NextResponse.json({ error: 'User not found' }, { status: 404 });
|
return NextResponse.json({ error: 'User not found' }, { status: 404 });
|
||||||
|
|||||||
Reference in New Issue
Block a user