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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ The following claims may be populated if the user is part of an organization:
- `organizationId`: The currently-selected organization.
- `role`: The `role` of the user for the current organization.
- `permissions`: Permissions corresponding to this role.
- `featureFlags`: Enabled feature flags for the current organization.

## Passing Data Through Authentication Flows

Expand Down
9 changes: 4 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
"react": ">=17"
},
"dependencies": {
"@workos-inc/authkit-js": "0.11.0"
"@workos-inc/authkit-js": "0.13.0"
}
}
12 changes: 10 additions & 2 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,19 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
const handleRefresh = React.useCallback(
(response: OnRefreshResponse) => {
const { user, accessToken, organizationId } = response;
const { role = null, permissions = [] } = getClaims(accessToken);
const {
role = null,
permissions = [],
feature_flags = [],
} = getClaims(accessToken);
setState((prev) => {
const next = {
...prev,
user,
organizationId: organizationId ?? null,
role,
permissions,
featureFlags: feature_flags,
};
return isEquivalentWorkOSSession(prev, next) ? prev : next;
});
Expand Down Expand Up @@ -106,7 +111,10 @@ function isEquivalentWorkOSSession(
a.user?.updatedAt === b.user?.updatedAt &&
a.organizationId === b.organizationId &&
a.role === b.role &&
a.permissions.every((perm, i) => perm === b.permissions[i])
a.permissions.length === b.permissions.length &&
a.permissions.every((perm, i) => perm === b.permissions[i]) &&
a.featureFlags.length === b.featureFlags.length &&
a.featureFlags.every((flag, i) => flag === b.featureFlags[i])
);
}

Expand Down
2 changes: 2 additions & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export interface State {
role: string | null;
organizationId: string | null;
permissions: string[];
featureFlags: string[];
}

export const initialState: State = {
Expand All @@ -14,4 +15,5 @@ export const initialState: State = {
role: null,
organizationId: null,
permissions: [],
featureFlags: [],
};