From 2061c07a8f3040aa5fa2a628d71bc870f891fbb1 Mon Sep 17 00:00:00 2001 From: frederikprijck Date: Tue, 6 Jun 2023 10:03:22 +0200 Subject: [PATCH 1/2] Add example for switching organizations --- EXAMPLES.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/EXAMPLES.md b/EXAMPLES.md index 640739445..cb2dd8db3 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -188,6 +188,27 @@ await client.loginWithPopup({ }); ``` +### Switch to a different organizations + +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. + +```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. + ### 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. From e8f977070a3d2cd701897c18ff54eb32f8291a82 Mon Sep 17 00:00:00 2001 From: frederikprijck Date: Tue, 6 Jun 2023 10:53:46 +0200 Subject: [PATCH 2/2] fix review comments --- EXAMPLES.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index cb2dd8db3..e34190c99 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -188,11 +188,11 @@ await client.loginWithPopup({ }); ``` -### Switch to a different organizations +### 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. -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. +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) { @@ -207,8 +207,6 @@ async function switchOrganization(newOrganization: string) { **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. - ### 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.