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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/node_modules
/dist
.idea
8 changes: 4 additions & 4 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.13.0"
"@workos-inc/authkit-js": "0.14.0"
}
}
3 changes: 3 additions & 0 deletions src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
} = response;
const {
role = null,
roles = null,
permissions = [],
feature_flags: featureFlags = [],
} = getClaims(accessToken);
Expand All @@ -52,6 +53,7 @@ export function AuthKitProvider(props: AuthKitProviderProps) {
user,
organizationId,
role,
roles,
permissions,
featureFlags,
impersonator,
Expand Down Expand Up @@ -117,6 +119,7 @@ function isEquivalentWorkOSSession(
a.user?.updatedAt === b.user?.updatedAt &&
a.organizationId === b.organizationId &&
a.role === b.role &&
a.roles === b.roles &&
a.permissions.length === b.permissions.length &&
a.permissions.every((perm, i) => perm === b.permissions[i]) &&
a.featureFlags.length === b.featureFlags.length &&
Expand Down
2 changes: 2 additions & 0 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface State {
isLoading: boolean;
user: User | null;
role: string | null;
roles: string[] | null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, why not string[] and default to an empty array like permissions and featureFlags?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's an optional field in the JWT payload, so I didn't want to default to empty. If users use this to authorize anything, an empty roles array might be different than expected and change the authorization decision. Also felt weird that roles could be null, but roles couldn't

organizationId: string | null;
permissions: string[];
featureFlags: string[];
Expand All @@ -19,6 +20,7 @@ export const initialState: State = {
isLoading: true,
user: null,
role: null,
roles: null,
organizationId: null,
permissions: [],
featureFlags: [],
Expand Down