-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Labels
AuthRelated to Auth components/categoryRelated to Auth components/categoryfeature-requestRequest a new featureRequest a new feature
Description
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 UXRelated Documentation
- https://docs.amplify.aws/gen1/react/tools/libraries/configure-categories/
- https://docs.amplify.aws/gen1/react/build-a-backend/troubleshooting/library-not-configured/
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:
-
URL-based routing with page reloads (current workaround)
- ❌ Poor UX, loses state
- ✅ Works but not ideal
-
Separate subdomains per client
- ❌ Infrastructure overhead
- ❌ Complex deployment
-
Manual session management
- ❌ Error-prone
- ❌ Bypasses Amplify abstractions
-
Multiple app instances
- ❌ Not supported by Amplify
- ✅ Works in Firebase:
firebase.initializeApp(config, 'name')
Additional context
Use Cases
- Multi-tenant SaaS: Users switch between organizations with separate Cognito clients
- Healthcare/Enterprise: Different departments with different auth configs
- White-label apps: Multiple brands sharing codebase
- 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 changeReactions are currently unavailable
Metadata
Metadata
Assignees
Labels
AuthRelated to Auth components/categoryRelated to Auth components/categoryfeature-requestRequest a new featureRequest a new feature