Skip to content

fix(expo): re-register push token on in-place user switch#1039

Merged
kylemcd merged 1 commit into
rcfrom
kyle-kno-14229-expo-push-user-switch
Jul 14, 2026
Merged

fix(expo): re-register push token on in-place user switch#1039
kylemcd merged 1 commit into
rcfrom
kyle-kno-14229-expo-push-user-switch

Conversation

@kylemcd

@kylemcd kylemcd commented Jul 14, 2026

Copy link
Copy Markdown
Member

What

Fixes the Cursor BugBot finding on #1038: the Expo push auto-register effect does not re-run when the signed-in user changes in place.

useAuthenticatedKnockClient re-authenticates the same Knock instance when only the userId changes (it returns currentKnock), so on a user A -> user B switch the knockClient identity is stable and isAuthenticated stays true. The auto-register effect depended on isAuthenticated but not userId, so it never re-ran, leaving the device token bound to user A's channel data.

This is the same class as the Slack/Teams "authCheck race on user switch" fix already in this release, applied to the one integration that was missed.

Change

  • KnockExpoPushNotificationProvider: destructure userId from useKnockAuthState and add it to the auto-register effect's dependency array (2 source lines).
  • Test: make the mocked userId controllable and add a case asserting the token re-registers on an in-place user switch. Verified it fails without the dep and passes with it.
  • Changeset: @knocklabs/expo patch.

Release path

Base is rc so this rides the same release as #1038: merge here, then merge rc -> main (#1038) to publish stable with the fix (@knocklabs/expo@0.7.0).

Tracks KNO-14229. The secondary point from the finding (no unregisterPushTokenFromChannel on auth loss) is intentionally out of scope and captured in the ticket as a separate decision.

The auto-register effect gated on isAuthenticated but not the signed-in
userId. Switching users on the same KnockProvider re-auths the same Knock
instance (isAuthenticated never flips), so the effect never re-ran and the
device token stayed bound to the previous user's channel data. Add userId
to the effect deps so a switch re-registers for the new user. Mirrors the
Slack/Teams authCheck-on-user-switch fix already in this release.

Addresses the Cursor BugBot finding on #1038 (KNO-14229).
@linear-code

linear-code Bot commented Jul 14, 2026

Copy link
Copy Markdown

KNO-14229

@changeset-bot

changeset-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 6414414

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@knocklabs/expo Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Jul 14, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
javascript-ms-teams-connect-example Ready Ready Preview, Comment Jul 14, 2026 4:35pm
javascript-nextjs-example Ready Ready Preview, Comment Jul 14, 2026 4:35pm
javascript-slack-connect-example Ready Ready Preview, Comment Jul 14, 2026 4:35pm
javascript-slack-kit-example Ready Ready Preview, Comment Jul 14, 2026 4:35pm

Request Review

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 11.97kB (2.13%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@knocklabs/react-core-react-core-cjs 38.05kB 1.6kB (4.4%) ⬆️
@knocklabs/react-react-esm 117.11kB 52 bytes (0.04%) ⬆️
@knocklabs/expo-expo-cjs 7.58kB 172 bytes (2.32%) ⬆️
@knocklabs/expo-expo-esm 8.18kB 258 bytes (3.26%) ⬆️
@knocklabs/react-react-cjs 107.02kB 95 bytes (0.09%) ⬆️
@knocklabs/client-client-esm 87.0kB 5.02kB (6.12%) ⬆️
@knocklabs/react-core-react-core-esm 43.38kB 1.82kB (4.39%) ⬆️
@knocklabs/client-client-cjs 63.38kB 2.95kB (4.89%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: @knocklabs/react-core-react-core-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js 101 bytes 3.82kB 2.72%
modules/slack/hooks/useSlackAuth.js 33 bytes 1.71kB 1.97%
modules/slack/hooks/useSlackChannels.js 33 bytes 1.69kB 1.99%
modules/ms-*.js 33 bytes 1.15kB 2.96%
modules/ms-*.js 49 bytes 1.52kB 3.34%
modules/ms-*.js 33 bytes 1.25kB 2.7%
modules/ms-*.js 33 bytes 1.41kB 2.4%
modules/ms-*.js 235 bytes 1.21kB 24.1% ⚠️
modules/ms-*.js 33 bytes 1.63kB 2.07%
modules/slack/context/KnockSlackProvider.js 49 bytes 1.55kB 3.27%
modules/guide/context/KnockGuideProvider.js 33 bytes 1.42kB 2.38%
modules/slack/hooks/useConnectedSlackChannels.js 33 bytes 1.4kB 2.42%
modules/slack/hooks/useSlackConnectionStatus.js 235 bytes 1.36kB 20.8% ⚠️
modules/core/context/KnockProvider.js 55 bytes 1.3kB 4.41%
modules/feed/context/KnockFeedProvider.js 33 bytes 1.29kB 2.62%
modules/core/hooks/useAuthenticatedKnockClient.js 164 bytes 1.09kB 17.71% ⚠️
modules/core/utils.js 22 bytes 1.09kB 2.07%
modules/preferences/hooks/usePreferences.js 33 bytes 884 bytes 3.88%
modules/feed/hooks/useNotifications.js 33 bytes 695 bytes 4.98%
modules/feed/hooks/useFeedSettings.js 37 bytes 548 bytes 7.24% ⚠️
modules/core/hooks/useKnockAuthState.js (New) 292 bytes 292 bytes 100.0% 🚀
view changes for bundle: @knocklabs/react-react-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.js 95 bytes 7.68kB 1.25%
view changes for bundle: @knocklabs/react-core-react-core-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.mjs 113 bytes 4.2kB 2.76%
modules/slack/hooks/useSlackAuth.mjs 32 bytes 2.11kB 1.54%
modules/slack/hooks/useSlackChannels.mjs 32 bytes 2.06kB 1.58%
modules/ms-*.mjs 54 bytes 1.39kB 4.05%
modules/ms-*.mjs 32 bytes 1.93kB 1.69%
modules/ms-*.mjs 32 bytes 1.6kB 2.04%
modules/ms-*.mjs 333 bytes 1.68kB 24.78% ⚠️
modules/ms-*.mjs 32 bytes 1.38kB 2.37%
modules/ms-*.mjs 32 bytes 2.01kB 1.62%
modules/slack/hooks/useSlackConnectionStatus.mjs 333 bytes 1.92kB 20.98% ⚠️
modules/slack/hooks/useConnectedSlackChannels.mjs 32 bytes 1.9kB 1.71%
modules/slack/context/KnockSlackProvider.mjs 54 bytes 1.52kB 3.68%
modules/guide/context/KnockGuideProvider.mjs 32 bytes 1.37kB 2.4%
modules/core/utils.mjs 32 bytes 1.25kB 2.64%
modules/core/hooks/useAuthenticatedKnockClient.mjs 220 bytes 1.23kB 21.7% ⚠️
modules/core/context/KnockProvider.mjs 65 bytes 1.14kB 6.02% ⚠️
modules/feed/hooks/useNotifications.mjs 32 bytes 1.1kB 3.0%
modules/feed/context/KnockFeedProvider.mjs 32 bytes 1.08kB 3.05%
modules/preferences/hooks/usePreferences.mjs 32 bytes 926 bytes 3.58%
modules/feed/hooks/useFeedSettings.mjs 60 bytes 751 bytes 8.68% ⚠️
modules/core/hooks/useKnockAuthState.mjs (New) 208 bytes 208 bytes 100.0% 🚀
view changes for bundle: @knocklabs/expo-expo-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
modules/push/KnockExpoPushNotificationProvider.mjs 258 bytes 3.62kB 7.67% ⚠️

Files in modules/push/KnockExpoPushNotificationProvider.mjs:

  • ./src/modules/push/KnockExpoPushNotificationProvider.tsx → Total Size: 5.0kB
view changes for bundle: @knocklabs/client-client-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
clients/guide/client.js 687 bytes 18.35kB 3.89%
clients/feed/feed.js 634 bytes 10.74kB 6.27% ⚠️
api.js 4 bytes 5.35kB 0.07%
knock.js 714 bytes 4.27kB 20.07% ⚠️
clients/ms-*.js 441 bytes 2.38kB 22.79% ⚠️
clients/slack/index.js 296 bytes 1.89kB 18.55% ⚠️
clients/messages/index.js 128 bytes 1.62kB 8.55% ⚠️
clients/feed/index.js 50 bytes 1.21kB 4.33%
view changes for bundle: @knocklabs/expo-expo-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
modules/push/KnockExpoPushNotificationProvider.js 172 bytes 2.79kB 6.56% ⚠️

Files in modules/push/KnockExpoPushNotificationProvider.js:

  • ./src/modules/push/KnockExpoPushNotificationProvider.tsx → Total Size: 5.17kB
view changes for bundle: @knocklabs/client-client-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
clients/guide/client.mjs 825 bytes 25.35kB 3.36%
clients/feed/feed.mjs 1.11kB 15.65kB 7.61% ⚠️
api.mjs 4 bytes 8.07kB 0.05%
knock.mjs 1.88kB 6.6kB 39.77% ⚠️
clients/ms-*.mjs 545 bytes 3.05kB 21.79% ⚠️
clients/slack/index.mjs 367 bytes 2.4kB 18.07% ⚠️
clients/messages/index.mjs 158 bytes 1.99kB 8.62% ⚠️
clients/feed/index.mjs 132 bytes 1.45kB 10.05% ⚠️
view changes for bundle: @knocklabs/react-react-esm

Assets Changed:

Asset Name Size Change Total Size Change (%)
index.mjs 52 bytes 6.12kB 0.86%

@kylemcd
kylemcd merged commit 6414414 into rc Jul 14, 2026
14 checks passed
@kylemcd
kylemcd deleted the kyle-kno-14229-expo-push-user-switch branch July 14, 2026 16:40
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.02%. Comparing base (4d300f3) to head (6414414).
⚠️ Report is 1 commits behind head on rc.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@           Coverage Diff           @@
##               rc    #1039   +/-   ##
=======================================
  Coverage   66.02%   66.02%           
=======================================
  Files         213      213           
  Lines       10499    10500    +1     
  Branches     1509     1509           
=======================================
+ Hits         6932     6933    +1     
  Misses       3542     3542           
  Partials       25       25           
Files with missing lines Coverage Δ
...modules/push/KnockExpoPushNotificationProvider.tsx 96.40% <100.00%> (+0.02%) ⬆️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant