Skip to content

Commit abac967

Browse files
authored
fix: prevent auth button cross-contamination when SlackKit and TeamsKit are co-rendered (#987)
1 parent 8851bd7 commit abac967

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@knocklabs/react-core": patch
3+
---
4+
5+
Fix auth button cross-contamination when SlackKit and TeamsKit are rendered simultaneously. The shared `useAuthPostMessageListener` hook now checks whether its own popup is open before processing `authComplete` messages, preventing one integration's OAuth completion from incorrectly updating the other's connection state.

packages/react-core/src/modules/core/hooks/useAuthPostMessageListener.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ export function useAuthPostMessageListener(
8484
return;
8585
}
8686

87+
// Ignore messages when this integration hasn't opened a popup
88+
if (!popupWindowRef.current) {
89+
return;
90+
}
91+
8792
const messageType = getMessageType(event.data);
8893

8994
if (messageType === "authComplete") {

packages/react-core/test/core/hooks/useAuthPostMessageListener.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,28 @@ describe("useAuthPostMessageListener", () => {
132132
expect(popupWindowRef.current).toBeNull();
133133
});
134134

135+
it("should ignore messages when popupWindowRef is null", () => {
136+
popupWindowRef.current = null;
137+
138+
renderHook(() =>
139+
useAuthPostMessageListener({
140+
knockHost,
141+
popupWindowRef,
142+
setConnectionStatus,
143+
onAuthenticationComplete,
144+
}),
145+
);
146+
147+
const event = new MessageEvent("message", {
148+
data: "authComplete",
149+
origin: knockHost,
150+
});
151+
window.dispatchEvent(event);
152+
153+
expect(setConnectionStatus).not.toHaveBeenCalled();
154+
expect(onAuthenticationComplete).not.toHaveBeenCalled();
155+
});
156+
135157
it("should ignore messages from different origins", () => {
136158
renderHook(() =>
137159
useAuthPostMessageListener({

0 commit comments

Comments
 (0)