Skip to content

Commit

Permalink
Ensure organization hint cookie is removed in loginWithPopup
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Hobbs committed Sep 6, 2021
1 parent 714e80f commit 98dda60
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions __tests__/Auth0Client/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export const loginWithRedirectFn = (mockWindow, mockFetch) => {
customCallbackUrl
} = processDefaultLoginWithRedirectOptions(testConfig);
await auth0.loginWithRedirect(options);

const redirectMethod = options?.redirectMethod || 'assign';

expect(mockWindow.location[redirectMethod]).toHaveBeenCalled();

if (error && errorDescription) {
Expand Down
14 changes: 14 additions & 0 deletions __tests__/Auth0Client/loginWithPopup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,20 @@ describe('Auth0Client', () => {
);
});

it('removes the organization hint cookie if no org_id claim was returned in the ID token', async () => {
const auth0 = setup();

await loginWithPopup(auth0);

expect(<jest.Mock>esCookie.remove).toHaveBeenCalledWith(
`_legacy_auth0.${TEST_CLIENT_ID}.organization_hint`
);

expect(<jest.Mock>esCookie.remove).toHaveBeenCalledWith(
`auth0.${TEST_CLIENT_ID}.organization_hint`
);
});

it('saves `auth0.is.authenticated` key in storage for an extended period', async () => {
const auth0 = setup({
sessionCheckExpiryDays: 2
Expand Down
2 changes: 2 additions & 0 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ export default class Auth0Client {
this.orgHintCookieName,
decodedToken.claims.org_id
);
} else {
this.cookieStorage.remove(this.orgHintCookieName);
}
}

Expand Down

0 comments on commit 98dda60

Please sign in to comment.