Skip to content

Commit

Permalink
fix(app-security): handle cases when identity is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed Nov 3, 2021
1 parent f87635e commit d6578fe
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions packages/app-security/src/contexts/Security.tsx
Expand Up @@ -15,6 +15,10 @@ export const SecurityProvider = props => {

const getPermission = useCallback(
<T extends SecurityPermission = SecurityPermission>(name: string): T => {
if (!identity) {
return null;
}

const perms = identity.permissions || [];
const exactMatch = perms.find(p => p.name === name);
if (exactMatch) {
Expand All @@ -29,11 +33,13 @@ export const SecurityProvider = props => {

const value = useMemo(
() => ({
identity: {
...identity,
// For backwards compatibility, expose the `getPermission` method on the `identity` object.
getPermission: getPermission as any
},
identity: identity
? {
...identity,
// For backwards compatibility, expose the `getPermission` method on the `identity` object.
getPermission: getPermission as any
}
: null,
setIdentity,
getPermission
}),
Expand Down

0 comments on commit d6578fe

Please sign in to comment.