Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/expo-push-reregister-on-user-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@knocklabs/expo": patch
---

Fix Expo push auto-registration not re-running when the signed-in user changes in place. The auto-register effect now depends on the authenticated `userId`, so switching users on the same `KnockProvider` (where `isAuthenticated` never flips) re-registers the device token against the new user's channel data.
13 changes: 13 additions & 0 deletions .changeset/knockprovider-enabled-client.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"@knocklabs/client": minor
---

Make the client do nothing (instead of throwing or making requests) when there's no signed-in user, and add tools to manage sign-in state.

- New `Knock.logout()` clears the user and disconnects everything: the websocket, the token-refresh timer, and the page-visibility listener.
- New `knock.authStatus` (`"authenticated"` or `"unauthenticated"`) and a subscribable `knock.authStore` to check or react to whether a user is signed in.
- With no signed-in user, these now do nothing instead of throwing or calling the API:
- Feed `markAs*` / `markAll*` / `fetchNextPage` (they also skip the optimistic UI update).
- Guides `fetch` / `subscribe` and the step actions. These previously threw, which could crash the app when Guides rendered before a user was set.
- Slack/MS Teams `authCheck` (returns "not connected"), `getChannels` / `getTeams` (return empty), and `messages.batchUpdateStatuses` (returns `[]`).
- Fixes two Guide bugs: real-time updates broke after a re-login (a stale socket reference), and the `history` patch used for location tracking broke when a Guide provider remounted.
21 changes: 21 additions & 0 deletions .changeset/knockprovider-enabled-prop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
"@knocklabs/react-core": minor
"@knocklabs/react": minor
"@knocklabs/react-native": minor
"@knocklabs/expo": minor
---

Add an `enabled` prop to `KnockProvider` (and an `enabled` option to `useAuthenticatedKnockClient`).

When `enabled` is `false`, the provider still renders its children but the Knock client sits idle: no identify call, no API requests, no websocket. Set it to `true` and it connects like a login; set it back to `false` and it disconnects and clears its data like a logout. It defaults to `true`, so existing code is unaffected.

Use this instead of conditionally mounting `KnockProvider`, for example to wait for a user token that loads asynchronously:

```tsx
<KnockProvider apiKey={apiKey} user={{ id: userId }} userToken={userToken} enabled={Boolean(userId && userToken)} />
```

Also fixed:

- `useFeedSettings` no longer calls `GET /v1/users/undefined/feeds/.../settings` when there's no user.
- `KnockProvider` now disconnects its client (websocket, token-refresh timer, listener) when it unmounts, instead of leaving them running.
29 changes: 29 additions & 0 deletions .changeset/pre.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"mode": "pre",
"tag": "rc",
"initialVersions": {
"client-example": "0.3.59",
"@knocklabs/expo-example": "1.1.9",
"guide-example": "0.0.84",
"ms-teams-connect-example": "0.0.71",
"nextjs-app-dir-example": "0.0.70",
"nextjs-example": "1.2.36",
"slack-connect-example": "0.3.70",
"slack-kit-example": "0.4.68",
"@knocklabs/client": "0.21.15",
"@knocklabs/eslint-config": "0.0.6",
"@knocklabs/expo": "0.6.9",
"@knocklabs/prettier-config": "0.0.1",
"@knocklabs/react": "0.11.24",
"@knocklabs/react-core": "0.13.16",
"@knocklabs/react-native": "0.9.9",
"@knocklabs/types": "0.1.5",
"@knocklabs/typescript-config": "0.0.2"
},
"changesets": [
"expo-push-reregister-on-user-switch",
"knockprovider-enabled-client",
"knockprovider-enabled-prop",
"use-knock-auth-state-reactive-integrations"
]
}
12 changes: 12 additions & 0 deletions .changeset/use-knock-auth-state-reactive-integrations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@knocklabs/react-core": minor
"@knocklabs/react": minor
"@knocklabs/react-native": minor
"@knocklabs/expo": minor
---

Add `useKnockAuthState()` and make Slack, MS Teams, and Expo respond to sign-in changes.

- New `useKnockAuthState(knock)` hook re-renders when the user signs in, signs out, or switches.
- Slack and MS Teams connection status now re-checks when the user changes, instead of checking once and sticking with that result.
- Expo waits for a signed-in user before registering for push notifications, so logged-out users don't see the OS permission prompt. A notification tapped while logged out no longer tries to update its status.
7 changes: 7 additions & 0 deletions examples/client-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# client-example

## 0.3.60-rc.0

### Patch Changes

- Updated dependencies [d2f7948]
- @knocklabs/client@0.22.0-rc.0

## 0.3.59

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/client-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "client-example",
"version": "0.3.59",
"version": "0.3.60-rc.0",
"private": true,
"type": "module",
"dependencies": {
Expand Down
15 changes: 15 additions & 0 deletions examples/expo-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# @knocklabs/expo-example

## 1.1.10-rc.1

### Patch Changes

- Updated dependencies [6414414]
- @knocklabs/expo@0.7.0-rc.1

## 1.1.10-rc.0

### Patch Changes

- Updated dependencies [d2f7948]
- Updated dependencies [d2f7948]
- @knocklabs/expo@0.7.0-rc.0

## 1.1.9

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/expo-example/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@knocklabs/expo-example",
"main": "expo-router/entry",
"version": "1.1.9",
"version": "1.1.10-rc.1",
"scripts": {
"start": "expo start",
"android": "expo start --android",
Expand Down
10 changes: 10 additions & 0 deletions examples/guide-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# guide-example

## 0.0.85-rc.0

### Patch Changes

- Updated dependencies [d2f7948]
- Updated dependencies [d2f7948]
- Updated dependencies [d2f7948]
- @knocklabs/client@0.22.0-rc.0
- @knocklabs/react@0.12.0-rc.0

## 0.0.84

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/guide-example/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "guide-example",
"private": true,
"version": "0.0.84",
"version": "0.0.85-rc.0",
"type": "module",
"scripts": {
"dev": "vite",
Expand Down
8 changes: 8 additions & 0 deletions examples/ms-teams-connect-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# ms-teams-connect-example

## 0.0.72-rc.0

### Patch Changes

- Updated dependencies [d2f7948]
- Updated dependencies [d2f7948]
- @knocklabs/react@0.12.0-rc.0

## 0.0.71

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions examples/ms-teams-connect-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ms-teams-connect-example",
"version": "0.0.71",
"version": "0.0.72-rc.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -11,7 +11,7 @@
"format:check": "prettier \"**/*.{js,ts,tsx}\" --check"
},
"dependencies": {
"@knocklabs/react": "0.11.24",
"@knocklabs/react": "0.12.0-rc.0",
"jsonwebtoken": "^9.0.3",
"next": "15.3.6",
"react": "^19.2.7",
Expand Down
8 changes: 8 additions & 0 deletions examples/nextjs-app-dir-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# nextjs-app-dir-example

## 0.0.71-rc.0

### Patch Changes

- Updated dependencies [d2f7948]
- Updated dependencies [d2f7948]
- @knocklabs/react@0.12.0-rc.0

## 0.0.70

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-app-dir-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextjs-app-dir-example",
"version": "0.0.70",
"version": "0.0.71-rc.0",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
Expand Down
8 changes: 8 additions & 0 deletions examples/nextjs-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# nextjs-example

## 1.2.37-rc.0

### Patch Changes

- Updated dependencies [d2f7948]
- Updated dependencies [d2f7948]
- @knocklabs/react@0.12.0-rc.0

## 1.2.36

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nextjs-example",
"version": "1.2.36",
"version": "1.2.37-rc.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand Down
8 changes: 8 additions & 0 deletions examples/slack-connect-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# slack-connect-example

## 0.3.71-rc.0

### Patch Changes

- Updated dependencies [d2f7948]
- Updated dependencies [d2f7948]
- @knocklabs/react@0.12.0-rc.0

## 0.3.70

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions examples/slack-connect-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slack-connect-example",
"version": "0.3.70",
"version": "0.3.71-rc.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -11,7 +11,7 @@
"format:check": "prettier \"**/*.{js,ts,tsx}\" --check"
},
"dependencies": {
"@knocklabs/react": "0.11.24",
"@knocklabs/react": "0.12.0-rc.0",
"jsonwebtoken": "^9.0.3",
"next": "15.3.6",
"react": "^19.2.7",
Expand Down
8 changes: 8 additions & 0 deletions examples/slack-kit-example/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# slack-kit-example

## 0.4.69-rc.0

### Patch Changes

- Updated dependencies [d2f7948]
- Updated dependencies [d2f7948]
- @knocklabs/react@0.12.0-rc.0

## 0.4.68

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions examples/slack-kit-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "slack-kit-example",
"version": "0.4.68",
"version": "0.4.69-rc.0",
"private": true,
"scripts": {
"dev": "next dev",
Expand All @@ -12,7 +12,7 @@
},
"dependencies": {
"@knocklabs/node": "^1.30.0",
"@knocklabs/react": "0.11.24",
"@knocklabs/react": "0.12.0-rc.0",
"jsonwebtoken": "^9.0.3",
"next": "15.3.6",
"react": "^19.2.7",
Expand Down
14 changes: 14 additions & 0 deletions packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 0.22.0-rc.0

### Minor Changes

- d2f7948: Make the client do nothing (instead of throwing or making requests) when there's no signed-in user, and add tools to manage sign-in state.

- New `Knock.logout()` clears the user and disconnects everything: the websocket, the token-refresh timer, and the page-visibility listener.
- New `knock.authStatus` (`"authenticated"` or `"unauthenticated"`) and a subscribable `knock.authStore` to check or react to whether a user is signed in.
- With no signed-in user, these now do nothing instead of throwing or calling the API:
- Feed `markAs*` / `markAll*` / `fetchNextPage` (they also skip the optimistic UI update).
- Guides `fetch` / `subscribe` and the step actions. These previously threw, which could crash the app when Guides rendered before a user was set.
- Slack/MS Teams `authCheck` (returns "not connected"), `getChannels` / `getTeams` (return empty), and `messages.batchUpdateStatuses` (returns `[]`).
- Fixes two Guide bugs: real-time updates broke after a re-login (a stale socket reference), and the `history` patch used for location tracking broke when a Guide provider remounted.

## 0.21.15

### Patch Changes
Expand Down
20 changes: 20 additions & 0 deletions packages/client/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,26 @@ knockClient.authenticate(
);
```

### Logging out and authentication state

While no user is signed in, the client stays idle: user-scoped calls (feed
fetches, mark-as-read, Guides, Slack/Teams checks, and so on) do nothing instead
of throwing or making requests, and no websocket is opened. This makes it safe
to construct a client before you have a user.

Call `logout()` to clear the current user and tear down all stateful
connections (the socket, the token-expiration timer, and the page-visibility
listener):

```typescript
knockClient.logout();
```

You can observe authentication state via `knockClient.authStatus`
(`"authenticated" | "unauthenticated"`) or subscribe to the `knockClient.authStore`
for changes. In React, prefer the `enabled` prop on `KnockProvider` (see
`@knocklabs/react`), which manages this lifecycle for you.

### Retrieving new items from the feed

```typescript
Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@knocklabs/client",
"version": "0.21.15",
"version": "0.22.0-rc.0",
"description": "The clientside library for interacting with Knock",
"homepage": "https://github.com/knocklabs/javascript/tree/main/packages/client",
"author": "@knocklabs",
Expand Down
Loading
Loading