From ca207d0574af619e5f304a1b6eb6b0dc101d1de7 Mon Sep 17 00:00:00 2001 From: Subhankar Maiti Date: Thu, 11 Jun 2026 11:10:04 +0530 Subject: [PATCH] fix: support runtime tenant/domain switching --- EXAMPLES.md | 60 ++++++++++++++++++- src/hooks/Auth0Provider.tsx | 14 ++++- .../native/adapters/NativeAuth0Client.ts | 26 ++++++++ .../__tests__/NativeAuth0Client.spec.ts | 45 ++++++++++++++ 4 files changed, 142 insertions(+), 3 deletions(-) diff --git a/EXAMPLES.md b/EXAMPLES.md index f55ac098..e05b4a35 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -145,7 +145,9 @@ If you already have credentials (e.g. from `webAuth.authorize()` or `credentials import Auth0, { parseIdToken } from 'react-native-auth0'; const auth0 = new Auth0({ domain, clientId }); -const credentials = await auth0.webAuth.authorize({ scope: 'openid profile email' }); +const credentials = await auth0.webAuth.authorize({ + scope: 'openid profile email', +}); const user = parseIdToken(credentials.idToken); // user.sub, user.name, user.email, etc. ``` @@ -1916,6 +1918,62 @@ If you want to support multiple domains, you would have to pass an array of obje You can skip sending the `customScheme` property if you do not want to customize it. +#### Switching tenants at runtime + +The configuration above is **build-time** setup: it registers the redirect callback for every domain you intend to use. Switching the _active_ tenant while the app is running is done in JavaScript by changing the `domain`/`clientId` you pass to the SDK. + +When you change the `domain` or `clientId` prop on `Auth0Provider`, the provider rebuilds its underlying client so subsequent calls target the newly selected tenant. Keep the props in state and update them to switch: + +```jsx +import React, { useState } from 'react'; +import { Auth0Provider, useAuth0 } from 'react-native-auth0'; + +const TENANTS = [ + { domain: 'tenant-a.us.auth0.com', clientId: 'CLIENT_ID_A' }, + { domain: 'tenant-b.us.auth0.com', clientId: 'CLIENT_ID_B' }, +]; + +const App = () => { + const [index, setIndex] = useState(0); + const tenant = TENANTS[index]; + + return ( + // Changing domain/clientId recreates the client for the new tenant. + +