From 8c9ddfe5470e84bccee4888ff219d24fd98d1660 Mon Sep 17 00:00:00 2001 From: Matthew Mikolay Date: Mon, 11 Aug 2025 13:56:18 -0400 Subject: [PATCH 01/10] Include branch in useSlackAuth state param --- packages/react-core/src/modules/slack/hooks/useSlackAuth.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts index ac1e6d2f8..4f938d59c 100644 --- a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts +++ b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts @@ -93,6 +93,7 @@ function useSlackAuth( channel_id: knockSlackChannelId, public_key: knock.apiKey, user_token: knock.userToken, + branch: knock.branch, }), client_id: slackClientId, scope: combinedScopes.join(","), @@ -104,6 +105,7 @@ function useSlackAuth( knockSlackChannelId, knock.apiKey, knock.userToken, + knock.branch, slackClientId, combinedScopes, ]); From b5414b6097617a23c107925503c139efb0530f02 Mon Sep 17 00:00:00 2001 From: Matthew Mikolay Date: Mon, 11 Aug 2025 16:45:07 -0400 Subject: [PATCH 02/10] Update slack-connect-example app --- .changeset/every-geese-fix.md | 5 +++++ examples/slack-connect-example/.env.sample | 2 ++ examples/slack-connect-example/pages/index.tsx | 1 + 3 files changed, 8 insertions(+) create mode 100644 .changeset/every-geese-fix.md diff --git a/.changeset/every-geese-fix.md b/.changeset/every-geese-fix.md new file mode 100644 index 000000000..5c4a48e06 --- /dev/null +++ b/.changeset/every-geese-fix.md @@ -0,0 +1,5 @@ +--- +"slack-connect-example": patch +--- + +Add `NEXT_PUBLIC_KNOCK_BRANCH` env var for specifying branch diff --git a/examples/slack-connect-example/.env.sample b/examples/slack-connect-example/.env.sample index 1cf88e37a..d2bac8053 100644 --- a/examples/slack-connect-example/.env.sample +++ b/examples/slack-connect-example/.env.sample @@ -20,3 +20,5 @@ NEXT_PUBLIC_SLACK_CLIENT_ID= # the slack channel you want to use and you'll find its ID on the page NEXT_PUBLIC_KNOCK_SLACK_CHANNEL_ID= NEXT_PUBLIC_REDIRECT_URL=http://localhost:3000/ + +NEXT_PUBLIC_KNOCK_BRANCH= diff --git a/examples/slack-connect-example/pages/index.tsx b/examples/slack-connect-example/pages/index.tsx index bcf8aadd6..29e99172c 100644 --- a/examples/slack-connect-example/pages/index.tsx +++ b/examples/slack-connect-example/pages/index.tsx @@ -50,6 +50,7 @@ export default function Home() { user={{ id: user.id }} host={process.env.NEXT_PUBLIC_KNOCK_API_URL} userToken={localStorage.getItem("knock-user-token")!} + branch={process.env.NEXT_PUBLIC_KNOCK_BRANCH} > Date: Mon, 11 Aug 2025 16:45:33 -0400 Subject: [PATCH 03/10] Rename branch to branch_slug in state --- packages/react-core/src/modules/slack/hooks/useSlackAuth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts index 4f938d59c..91f5c9eb1 100644 --- a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts +++ b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts @@ -93,7 +93,7 @@ function useSlackAuth( channel_id: knockSlackChannelId, public_key: knock.apiKey, user_token: knock.userToken, - branch: knock.branch, + branch_slug: knock.branch, }), client_id: slackClientId, scope: combinedScopes.join(","), From 615c1ff9f51c3bf6204e71f3d0e7ffa4726961c8 Mon Sep 17 00:00:00 2001 From: Matthew Mikolay Date: Mon, 11 Aug 2025 17:18:16 -0400 Subject: [PATCH 04/10] Assign branch_slug inside an if statement --- .../src/modules/slack/hooks/useSlackAuth.ts | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts index 91f5c9eb1..477da86a9 100644 --- a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts +++ b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts @@ -83,21 +83,27 @@ function useSlackAuth( ]); const buildSlackAuthUrl = useCallback(() => { + const state: Record = { + redirect_url: redirectUrl, + access_token_object: { + object_id: tenantId, + collection: TENANT_OBJECT_COLLECTION, + }, + channel_id: knockSlackChannelId, + public_key: knock.apiKey, + user_token: knock.userToken, + }; + + if (knock.branch) { + state.branch_slug = knock.branch; + } + const rawParams = { - state: JSON.stringify({ - redirect_url: redirectUrl, - access_token_object: { - object_id: tenantId, - collection: TENANT_OBJECT_COLLECTION, - }, - channel_id: knockSlackChannelId, - public_key: knock.apiKey, - user_token: knock.userToken, - branch_slug: knock.branch, - }), + state: JSON.stringify(state), client_id: slackClientId, scope: combinedScopes.join(","), }; + return `${SLACK_AUTHORIZE_URL}?${new URLSearchParams(rawParams)}`; }, [ redirectUrl, From b524688fd55305fea456b6a130a84a1d27b3d606 Mon Sep 17 00:00:00 2001 From: Matthew Mikolay Date: Mon, 11 Aug 2025 17:21:16 -0400 Subject: [PATCH 05/10] Revert "Assign branch_slug inside an if statement" This reverts commit d6d83ca8f24030702c27962496ac826e6044c320. --- .../src/modules/slack/hooks/useSlackAuth.ts | 28 ++++++++----------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts index 477da86a9..91f5c9eb1 100644 --- a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts +++ b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts @@ -83,27 +83,21 @@ function useSlackAuth( ]); const buildSlackAuthUrl = useCallback(() => { - const state: Record = { - redirect_url: redirectUrl, - access_token_object: { - object_id: tenantId, - collection: TENANT_OBJECT_COLLECTION, - }, - channel_id: knockSlackChannelId, - public_key: knock.apiKey, - user_token: knock.userToken, - }; - - if (knock.branch) { - state.branch_slug = knock.branch; - } - const rawParams = { - state: JSON.stringify(state), + state: JSON.stringify({ + redirect_url: redirectUrl, + access_token_object: { + object_id: tenantId, + collection: TENANT_OBJECT_COLLECTION, + }, + channel_id: knockSlackChannelId, + public_key: knock.apiKey, + user_token: knock.userToken, + branch_slug: knock.branch, + }), client_id: slackClientId, scope: combinedScopes.join(","), }; - return `${SLACK_AUTHORIZE_URL}?${new URLSearchParams(rawParams)}`; }, [ redirectUrl, From f845991c43b45690de93e2b4b15af9213544d71e Mon Sep 17 00:00:00 2001 From: Matthew Mikolay Date: Mon, 11 Aug 2025 17:21:35 -0400 Subject: [PATCH 06/10] Fall back to undefined --- packages/react-core/src/modules/slack/hooks/useSlackAuth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts index 91f5c9eb1..9c23e4d63 100644 --- a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts +++ b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts @@ -93,7 +93,7 @@ function useSlackAuth( channel_id: knockSlackChannelId, public_key: knock.apiKey, user_token: knock.userToken, - branch_slug: knock.branch, + branch_slug: knock.branch ?? undefined, }), client_id: slackClientId, scope: combinedScopes.join(","), From ed903bf8d08385fbddd99391b078b32226b54fab Mon Sep 17 00:00:00 2001 From: Matthew Mikolay Date: Mon, 11 Aug 2025 17:24:44 -0400 Subject: [PATCH 07/10] Update test --- packages/react-core/test/slack/useSlackAuth.test.tsx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/react-core/test/slack/useSlackAuth.test.tsx b/packages/react-core/test/slack/useSlackAuth.test.tsx index 8e19023c8..2b608ff4c 100644 --- a/packages/react-core/test/slack/useSlackAuth.test.tsx +++ b/packages/react-core/test/slack/useSlackAuth.test.tsx @@ -3,6 +3,8 @@ import { beforeEach, describe, expect, test, vi } from "vitest"; import useSlackAuth from "../../src/modules/slack/hooks/useSlackAuth"; +const TEST_BRANCH_SLUG = "lorem-ipsum-branch"; + const mockSetConnectionStatus = vi.fn(); const mockSetActionLabel = vi.fn(); @@ -24,6 +26,7 @@ vi.mock("../../src/modules/core", () => ({ slack: mockSlackClient, apiKey: "test_api_key", userToken: "test_user_token", + branch: TEST_BRANCH_SLUG, }), })); @@ -53,6 +56,7 @@ describe("useSlackAuth", () => { channel_id: "test_channel_id", public_key: "test_api_key", user_token: "test_user_token", + branch_slug: TEST_BRANCH_SLUG, }); }); From d3d6cf866f06f9f55bc41e348c71683ac35593e2 Mon Sep 17 00:00:00 2001 From: Matthew Mikolay Date: Mon, 11 Aug 2025 17:26:12 -0400 Subject: [PATCH 08/10] Remove fall back to undefined --- packages/react-core/src/modules/slack/hooks/useSlackAuth.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts index 9c23e4d63..91f5c9eb1 100644 --- a/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts +++ b/packages/react-core/src/modules/slack/hooks/useSlackAuth.ts @@ -93,7 +93,7 @@ function useSlackAuth( channel_id: knockSlackChannelId, public_key: knock.apiKey, user_token: knock.userToken, - branch_slug: knock.branch ?? undefined, + branch_slug: knock.branch, }), client_id: slackClientId, scope: combinedScopes.join(","), From 46d6d7c9d35cac49ae39d805de3c8e3310fc8928 Mon Sep 17 00:00:00 2001 From: Matthew Mikolay Date: Mon, 11 Aug 2025 17:32:06 -0400 Subject: [PATCH 09/10] Add changeset --- .changeset/seven-badgers-learn.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .changeset/seven-badgers-learn.md diff --git a/.changeset/seven-badgers-learn.md b/.changeset/seven-badgers-learn.md new file mode 100644 index 000000000..eaca13212 --- /dev/null +++ b/.changeset/seven-badgers-learn.md @@ -0,0 +1,11 @@ +--- +"@knocklabs/react-core": patch +"@knocklabs/react": patch +--- + +Enable use of SlackKit with branches + +The `useSlackAuth` hook exported by `@knocklabs/react-core` has been updated so +that it works with branches. You can now use either this hook or the +`` component exported by `@knocklabs/react` to test connecting +Slack workspaces to Knock tenants. From b044d8c0f49f2984222409568d6b3f04b408872c Mon Sep 17 00:00:00 2001 From: Matthew Mikolay Date: Mon, 11 Aug 2025 17:33:05 -0400 Subject: [PATCH 10/10] Update changeset --- .changeset/seven-badgers-learn.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/seven-badgers-learn.md b/.changeset/seven-badgers-learn.md index eaca13212..bc94eb2a9 100644 --- a/.changeset/seven-badgers-learn.md +++ b/.changeset/seven-badgers-learn.md @@ -8,4 +8,4 @@ Enable use of SlackKit with branches The `useSlackAuth` hook exported by `@knocklabs/react-core` has been updated so that it works with branches. You can now use either this hook or the `` component exported by `@knocklabs/react` to test connecting -Slack workspaces to Knock tenants. +Slack workspaces to Knock tenants while working on a branch.