From 12ccb1a1f56d9a31d1e6f6f7c90edb17c18bcf9b Mon Sep 17 00:00:00 2001 From: Thibault Le Ouay Ducasse Date: Mon, 6 Jul 2026 19:36:23 +0200 Subject: [PATCH] slack app: fix --- apps/server/src/routes/slack/workspace-resolver.ts | 6 +++++- packages/subscriptions/src/channels/slack.ts | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/server/src/routes/slack/workspace-resolver.ts b/apps/server/src/routes/slack/workspace-resolver.ts index 750110ca..ec01c8b9 100644 --- a/apps/server/src/routes/slack/workspace-resolver.ts +++ b/apps/server/src/routes/slack/workspace-resolver.ts @@ -1,4 +1,4 @@ -import { and, db, eq } from "@openstatus/db"; +import { and, db, desc, eq } from "@openstatus/db"; import { integration, selectWorkspaceSchema, @@ -32,6 +32,10 @@ export async function resolveWorkspace( eq(integration.externalId, teamId), ), ) + // Slack keeps one live token per (app, team); a reinstall invalidates all + // earlier ones. If the team is linked to several workspaces, the newest row + // is the only one holding a valid token. + .orderBy(desc(integration.updatedAt)) .get(); if (!row?.workspaceId) return null; diff --git a/packages/subscriptions/src/channels/slack.ts b/packages/subscriptions/src/channels/slack.ts index 6759e688..f70589e1 100644 --- a/packages/subscriptions/src/channels/slack.ts +++ b/packages/subscriptions/src/channels/slack.ts @@ -1,4 +1,4 @@ -import { and, db, eq } from "@openstatus/db"; +import { and, db, desc, eq } from "@openstatus/db"; import { integration, pageSubscriber } from "@openstatus/db/src/schema"; import type { ChatPostMessageArguments, @@ -77,6 +77,10 @@ async function getBotTokenFromDb(teamId: string): Promise { eq(integration.externalId, teamId), ), ) + // Slack keeps one live token per (app, team); a reinstall invalidates all + // earlier ones. If the team is linked to several workspaces, the newest row + // is the only one holding a valid token. + .orderBy(desc(integration.updatedAt)) .get(); const credential = row?.credential as { botToken?: string } | null; return credential?.botToken ?? null; -- 2.51.2