feat: Use X-Swarm-Source-Domain header to identify the sender's node domain in chat messages.
This commit is contained in:
@@ -39,11 +39,17 @@ export async function POST(request: NextRequest) {
|
||||
const parts = handle.split('@');
|
||||
senderNodeDomain = parts[parts.length - 1];
|
||||
} else {
|
||||
// Try handle registry (though we likely don't have it if we don't have the user)
|
||||
const registryEntry = await db.query.handleRegistry.findFirst({
|
||||
where: eq(handleRegistry.did, did)
|
||||
});
|
||||
if (registryEntry) senderNodeDomain = registryEntry.nodeDomain;
|
||||
// Try to get from header first
|
||||
const sourceDomainHeader = request.headers.get('X-Swarm-Source-Domain');
|
||||
if (sourceDomainHeader) {
|
||||
senderNodeDomain = sourceDomainHeader;
|
||||
} else {
|
||||
// Try handle registry (though we likely don't have it if we don't have the user)
|
||||
const registryEntry = await db.query.handleRegistry.findFirst({
|
||||
where: eq(handleRegistry.did, did)
|
||||
});
|
||||
if (registryEntry) senderNodeDomain = registryEntry.nodeDomain;
|
||||
}
|
||||
}
|
||||
|
||||
if (senderNodeDomain) {
|
||||
|
||||
@@ -165,7 +165,10 @@ export async function POST(request: NextRequest) {
|
||||
const protocol = targetDomain.includes('localhost') ? 'http' : 'https';
|
||||
const res = await fetch(`${protocol}://${targetDomain}/api/chat/receive`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Swarm-Source-Domain': process.env.NEXT_PUBLIC_NODE_DOMAIN || ''
|
||||
},
|
||||
body: JSON.stringify(signedAction) // Forward the user's signed intent
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user