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

Add example for switching organizations #1107

Merged
merged 2 commits into from
Jun 6, 2023
Merged
Changes from 1 commit
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
21 changes: 21 additions & 0 deletions EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,27 @@ await client.loginWithPopup({
});
```

### Switch to a different organizations
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved

When working with multiple organizations, there might be a situation where you want your users to be able to switch between different organizations.

Important to realize is that the authentication state in the SDK is build around the organization, so in order to switch organizations, you need to logout and login again. However, it's enough to log out from the SDK and not from Auth0. Doing that ensures that, when calling login again, the user might not be prompted for their credentials depending on whether or not they have an active session with Auth0.
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved

```ts
async function switchOrganization(newOrganization: string) {
await client.logout({ openUrl: false });
await client.loginWithRedirect({
authorizationParams: {
organization: newOrganization
}
});
}
```

**Note:** Ensure to pass any additional parameters to `loginWithRedirect` (or `loginWithPopup`) just as you might have passed on other occurences of calling login.

Doing the above will ensure the SDK removes any token that is linked to the current organization, and logs in again to retrieve tokens for the new organization.
frederikprijck marked this conversation as resolved.
Show resolved Hide resolved

### Accept user invitations

Accept a user invitation through the SDK by creating a route within your application that can handle the user invitation URL, and log the user in by passing the `organization` and `invitation` parameters from this URL. You can either use `loginWithRedirect` or `loginWithPopup` as needed.
Expand Down