Skip to content

Commit

Permalink
fix(tokens): fix trying to get tokens.accessToken when tokens is null
Browse files Browse the repository at this point in the history
  • Loading branch information
devcauldron committed Apr 4, 2021
1 parent 5b14f05 commit 4684284
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kettlespace-eng/expo-keycloak",
"version": "1.0.29",
"version": "1.0.30",
"description": "Keycloak authentication for react-native apps using Expo.",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down Expand Up @@ -45,4 +45,4 @@
"expo-random": "^9.0.0",
"react": "^16.13.1"
}
}
}
8 changes: 4 additions & 4 deletions src/useKeycloak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ export const useKeycloak = () => {

const hasRealmRole = useCallback(
(role: string) => {
if (tokens.accessToken) {
if (tokens && tokens.accessToken) {
const { realm_access: { roles = [] } = {} } = jwt_decode(
tokens.accessToken,
);
return roles.includes(role);
}
return false;
},
[tokens.accessToken],
[tokens],
);

const accessTokenParsed = useMemo(
() => (tokens.accessToken ? jwt_decode(tokens.accessToken) : {}),
[tokens.accessToken],
() => (tokens && tokens.accessToken ? jwt_decode(tokens.accessToken) : {}),
[tokens],
);

return {
Expand Down

0 comments on commit 4684284

Please sign in to comment.