diff --git a/apps/frontend/src/pages/hosting/manage/[id].vue b/apps/frontend/src/pages/hosting/manage/[id].vue index 6ea25b17c..6524bfa91 100644 --- a/apps/frontend/src/pages/hosting/manage/[id].vue +++ b/apps/frontend/src/pages/hosting/manage/[id].vue @@ -1335,7 +1335,9 @@ async function initializeIntercom() { if (!auth.value?.user) return try { - const intercomData = await $fetch<{ token: string }>('/api/intercom/messenger-jwt') + const intercomData = await $fetch<{ token: string }>('/api/intercom/messenger-jwt', { + query: { server_id: serverId }, + }) Intercom({ app_id: config.public.intercomAppId, diff --git a/apps/frontend/src/server/routes/api/intercom/messenger-jwt.get.ts b/apps/frontend/src/server/routes/api/intercom/messenger-jwt.get.ts index fd997e414..6992d62a6 100644 --- a/apps/frontend/src/server/routes/api/intercom/messenger-jwt.get.ts +++ b/apps/frontend/src/server/routes/api/intercom/messenger-jwt.get.ts @@ -21,6 +21,7 @@ async function getIntercomKeyFromSecretsStore(): Promise { async function signIntercomUserJwt( user: { id: string; username: string; email?: string; created: string }, secret: string, + serverId?: string, ): Promise { const createdAt = Math.floor(new Date(user.created).getTime() / 1000) @@ -37,6 +38,10 @@ async function signIntercomUserJwt( payload.created_at = createdAt } + if (serverId) { + payload.server_id = serverId + } + return await new SignJWT(payload) .setProtectedHeader({ alg: 'HS256', typ: 'JWT' }) .setIssuedAt() @@ -104,7 +109,10 @@ export default defineEventHandler(async (event): Promise }) } - const token = await signIntercomUserJwt(user, intercomSecret) + const query = getQuery(event) + const serverId = typeof query.server_id === 'string' ? query.server_id : undefined + + const token = await signIntercomUserJwt(user, intercomSecret, serverId) return { token,