feat(federation): resolveOrCreateReplicatedUser uses findFederatedUser + normalizes homeInstance

This commit is contained in:
Jannis Braun
2026-03-31 04:42:12 +02:00
parent 8167540afc
commit f8e41e3cc5
+6 -5
View File
@@ -1008,11 +1008,12 @@ export function resolveOrCreateReplicatedUser(
homeUserId: string, homeUserId: string,
homeInstance: string, homeInstance: string,
db: ReturnType<typeof getDb>, db: ReturnType<typeof getDb>,
hints?: { username?: string | null },
): typeof schema.users.$inferSelect { ): typeof schema.users.$inferSelect {
const existing = resolveLocalUser(homeUserId, db); const existing = findFederatedUser(homeUserId, homeInstance, db, hints);
if (existing) return existing; if (existing) return backfillHomeUserId(existing, homeUserId, db);
// Extract bare domain from homeInstance for username construction // Normalize homeInstance to bare domain for consistent storage
const domain = extractDomain(homeInstance); const domain = extractDomain(homeInstance);
// Use the snowflake-style homeUserId as the local part; append the // Use the snowflake-style homeUserId as the local part; append the
@@ -1045,7 +1046,7 @@ export function resolveOrCreateReplicatedUser(
passwordHash: '!federation-replicated', // Cannot be used to log in (bcrypt never produces this) passwordHash: '!federation-replicated', // Cannot be used to log in (bcrypt never produces this)
status: 'offline', status: 'offline',
isAdmin: 0, isAdmin: 0,
homeInstance, homeInstance: domain, // Normalized to bare domain
homeUserId, homeUserId,
createdAt: now, createdAt: now,
}).run(); }).run();
@@ -1055,7 +1056,7 @@ export function resolveOrCreateReplicatedUser(
throw new Error(`Failed to create replicated user for homeUserId=${homeUserId}`); throw new Error(`Failed to create replicated user for homeUserId=${homeUserId}`);
} }
console.log(`[federation] Auto-created replicated user ${userId} (${username}) for homeUserId=${homeUserId} from ${homeInstance}`); console.log(`[federation] Auto-created replicated user ${userId} (${username}) for homeUserId=${homeUserId} from ${domain}`);
return created; return created;
} }