Skip to content

Commit 96433b6

Browse files
Ensure organization cookie is set when no organization was set (#1123)
1 parent c2b72d8 commit 96433b6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

__tests__/Auth0Client/loginWithRedirect.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,28 @@ describe('Auth0Client', () => {
491491
);
492492
});
493493

494+
it('stores the organization in a hint cookie when no organization was set but a claim was found', async () => {
495+
const auth0 = setup({}, { org_id: TEST_ORG_ID });
496+
497+
await loginWithRedirect(auth0);
498+
499+
expect(<jest.Mock>esCookie.set).toHaveBeenCalledWith(
500+
`auth0.${TEST_CLIENT_ID}.organization_hint`,
501+
JSON.stringify(TEST_ORG_ID),
502+
{
503+
expires: 1
504+
}
505+
);
506+
507+
expect(<jest.Mock>esCookie.set).toHaveBeenCalledWith(
508+
`_legacy_auth0.${TEST_CLIENT_ID}.organization_hint`,
509+
JSON.stringify(TEST_ORG_ID),
510+
{
511+
expires: 1
512+
}
513+
);
514+
});
515+
494516
it('removes the organization hint cookie if no organization specified', async () => {
495517
// TODO: WHAT IS ORG_NAME ?
496518
const auth0 = setup({});

src/Auth0Client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ export class Auth0Client {
11291129
cookieDomain: this.options.cookieDomain
11301130
});
11311131

1132-
this._processOrgHint(organization);
1132+
this._processOrgHint(organization || decodedToken.claims.org_id);
11331133

11341134
return { ...authResult, decodedToken };
11351135
}

0 commit comments

Comments
 (0)