Skip to content

Commit

Permalink
Merge pull request #29 from Orfium/fix/diff-organization-refetch
Browse files Browse the repository at this point in the history
  • Loading branch information
panvourtsis committed Oct 10, 2022
2 parents 4f5196a + 8306d1b commit ac59a91
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/authentication/context.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,21 @@ describe('Context', () => {
test('with cached results', async () => {
const NEW_FAKE_EXPIRED_TOKEN = getNewFakeToken();
const setToken = useRequestToken.getState().setToken;
const setSelectedOrganization = useOrganization.getState().setSelectedOrganization;
setToken(NEW_FAKE_EXPIRED_TOKEN);
setSelectedOrganization({
org_id: 'org_WYZLEMyTm2xEbnbn',
display_name: 'test',
name: 'test',
can_administrate: true,
metadata: {
type: 'test',
product_codes: 'test',
},
branding: {
logo_url: 'test',
},
});

const { token, decodedToken } = await getTokenSilently();

Expand Down
2 changes: 1 addition & 1 deletion src/authentication/context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const getTokenSilently = async (
? new Date(decodedToken?.exp * 1000).getTime() < new Date().getTime()
: true; // has expired

if (!isExpired && decodedToken.org_id) {
if (!isExpired && decodedToken.org_id && decodedToken.org_id === selectedOrganization?.org_id) {
return { token: stateToken, decodedToken };
}

Expand Down

0 comments on commit ac59a91

Please sign in to comment.