Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure organization cookie is set when no organization was set #1123

Merged
merged 1 commit into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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