diff --git a/__tests__/Auth0Client/loginWithRedirect.test.ts b/__tests__/Auth0Client/loginWithRedirect.test.ts index f399b1736..08462259e 100644 --- a/__tests__/Auth0Client/loginWithRedirect.test.ts +++ b/__tests__/Auth0Client/loginWithRedirect.test.ts @@ -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(esCookie.set).toHaveBeenCalledWith( + `auth0.${TEST_CLIENT_ID}.organization_hint`, + JSON.stringify(TEST_ORG_ID), + { + expires: 1 + } + ); + + expect(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({}); diff --git a/src/Auth0Client.ts b/src/Auth0Client.ts index 5fd0085ae..3d1dccc70 100644 --- a/src/Auth0Client.ts +++ b/src/Auth0Client.ts @@ -1129,7 +1129,7 @@ export class Auth0Client { cookieDomain: this.options.cookieDomain }); - this._processOrgHint(organization); + this._processOrgHint(organization || decodedToken.claims.org_id); return { ...authResult, decodedToken }; }