Skip to content

Support for Runtime Multi-Client/Multi-Tenant Configuration Switching #14742

@shivennn

Description

@shivennn

Is this related to a new or existing framework?

React

Is this related to a new or existing API?

Authentication

Is this related to another service?

Amazon Cognito

Describe the feature you'd like to request

Problem

Amplify.configure() can only be called once at application startup. Multi-tenant applications that need to switch between different Cognito User Pool Clients at runtime have no supported way to reconfigure without forcing a full page reload, which breaks UX and loses application state.

Current Limitation

// index.js - Only works at initial load
const params = new URLSearchParams(window.location.search);
const config = params.get('source') === 'epic' ? clientBConfig : clientAConfig;
Amplify.configure(config);

Runtime switching currently requires:

await signOut()

Amplify.configure(newConfig)

window.location.reload()  Breaks UX

Related Documentation

Describe the solution you'd like


Describe the solution you'd like:

Option 1: Reconfigure API

await Amplify.reconfigure(newConfig, { clearSession: true });

Option 2: Multi-Client Context (Preferred)

const clientA = Amplify.createClient('clientA', clientAConfig);
const clientB = Amplify.createClient('clientB', clientBConfig);
await Amplify.switchClient('clientB'); // No reload needed

Option 3: Dynamic Authenticator

<Authenticator config={activeConfig} onConfigChange={handleSessionClear}>
  {({ signOut, user }) => <App />}
</Authenticator>

Describe alternatives you've considered


Describe alternatives you've considered:

  1. URL-based routing with page reloads (current workaround)

    • ❌ Poor UX, loses state
    • ✅ Works but not ideal
  2. Separate subdomains per client

    • ❌ Infrastructure overhead
    • ❌ Complex deployment
  3. Manual session management

    • ❌ Error-prone
    • ❌ Bypasses Amplify abstractions
  4. Multiple app instances

    • ❌ Not supported by Amplify
    • ✅ Works in Firebase: firebase.initializeApp(config, 'name')

Additional context

Use Cases

  1. Multi-tenant SaaS: Users switch between organizations with separate Cognito clients
  2. Healthcare/Enterprise: Different departments with different auth configs
  3. White-label apps: Multiple brands sharing codebase
  4. Dev/Test environments: Switch configs without restart

Example Implementation

// Current workaround in production
const switchClient = async (targetClient) => {
  await signOut({ global: true });
  Amplify.configure(targetClient === 'B' ? clientBConfig : clientAConfig);
  window.location.href = targetClient === 'B' ? '?source=epic' : '/';
};


### Is this something that you'd be interested in working on?

- [ ] 👋 I may be able to implement this feature request
- [ ] ⚠️ This feature might incur a breaking change

Metadata

Metadata

Assignees

No one assigned

    Labels

    AuthRelated to Auth components/categoryfeature-requestRequest a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions