Skip to content

Commit

Permalink
Ensure organization cookie is set when no organization was set (#1123)
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikprijck committed Aug 18, 2023
1 parent c2b72d8 commit 96433b6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
22 changes: 22 additions & 0 deletions __tests__/Auth0Client/loginWithRedirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,28 @@ describe('Auth0Client', () => {
);
});

it('stores the organization in a hint cookie when no organization was set but a claim was found', async () => {
const auth0 = setup({}, { org_id: TEST_ORG_ID });

await loginWithRedirect(auth0);

expect(<jest.Mock>esCookie.set).toHaveBeenCalledWith(
`auth0.${TEST_CLIENT_ID}.organization_hint`,
JSON.stringify(TEST_ORG_ID),
{
expires: 1
}
);

expect(<jest.Mock>esCookie.set).toHaveBeenCalledWith(
`_legacy_auth0.${TEST_CLIENT_ID}.organization_hint`,
JSON.stringify(TEST_ORG_ID),
{
expires: 1
}
);
});

it('removes the organization hint cookie if no organization specified', async () => {
// TODO: WHAT IS ORG_NAME ?
const auth0 = setup({});
Expand Down
2 changes: 1 addition & 1 deletion src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,7 @@ export class Auth0Client {
cookieDomain: this.options.cookieDomain
});

this._processOrgHint(organization);
this._processOrgHint(organization || decodedToken.claims.org_id);

return { ...authResult, decodedToken };
}
Expand Down

0 comments on commit 96433b6

Please sign in to comment.