User switch between Organization

Auth0 Organization fits perfect for my use case. However, after going through the docs on Organization, and looked at the implementation here [Authentication services for SaaS companies] . I have a couple questions.

  1. The claims (i.e. role and permission) are specific to the organization that the user auth against, so does that mean when a user switches between organizations, that user needs to sign out and sign back in or auth0 does some silent auth in the background to re-generate the access_token? What’s the recommended way to accomplish a seamless switch between organizations?

  2. In the article, the author uses localStorage to persist the org_id that the user is auth against… without that refresh would kick the user off. Is this a temporary fix or intended to be the implementation (i.e. this functionality will be taken care of by the react-sdk)?

  3. Is there a limit to number of organizations?

Answering some questions that I posed after some digging around for an implentation.

Using the React-sdk, we can use the getAccessTokenSilently from the auth0 hook and pass in organization (similar to the same prop on the Auth0Provider) with the new org_id when a user wants to switch organization.

To do this, we have to pass in the ignoreCache flag when we get the access token (otherwise you’d get the same access token for the same organization.

Drawback is obvious, if a user switches back and forth between organizations, without some caching locally, we are making multiple calls to the API.

1 Like

Another issue came up is idToken… even we can use the getAccessTokenSilently, we are not re-fetching the idToken… that means when we injected the role to the idToken, when a user switch between organization, they are not getting the new idToken that has the new role.

Work Around aka Hack
use jwt-decode on the front end to decode the token → no need to verify, and just get whatever you need from the access token

1 Like

Talked to a solutions engineer from Auth0, if you’re not on the enterprise plan, the cap of number of organization is 100

1 Like

Thanks for sharing that with the rest of community!