From 7ca5d97cb56ad23e1fcf5b6e7a896d27a3dac331 Mon Sep 17 00:00:00 2001 From: Frederik Prijck Date: Tue, 6 Jun 2023 12:00:03 +0200 Subject: [PATCH] Add example for switching organizations (#1107) --- EXAMPLES.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/EXAMPLES.md b/EXAMPLES.md index 640739445..e34190c99 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -188,6 +188,25 @@ await client.loginWithPopup({ }); ``` +### Switch to a different organization + +When working with multiple organizations, there might be a situation where you want your users to be able to switch between different organizations. + +To do this, clear the local logged in state from your application and login to Auth0 again, leveraging any existing Auth0 session to prevent the user from being prompted for their credentials. + +```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. + ### 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.