Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration switching #1584

Open
brennanMKE opened this issue Jan 4, 2022 · 14 comments
Open

Configuration switching #1584

brennanMKE opened this issue Jan 4, 2022 · 14 comments
Assignees
Labels
core Amplify Core components feature-request Request a new feature pending-maintainer-response Issue is pending response from an Amplify team member

Comments

@brennanMKE
Copy link
Contributor

Is your feature request related to a problem? Please describe.

An app which is used in multiple regions will need to switch configurations to use a different configuration. When a user logs out and then logs into a different region it is necessary to change the configuration. There is no support currently do this without restarting the app.

Describe the solution you'd like

Support an API to define multiple configurations and switch between regions.

Describe alternatives you've considered

None

Is the feature request related to any of the existing Amplify categories?

Auth

Additional context

No response

@brennanMKE
Copy link
Contributor Author

#527 Related issue

@brennanMKE
Copy link
Contributor Author

@brennanMKE
Copy link
Contributor Author

brennanMKE commented May 27, 2022

There are multiple scenarios to cover. These are listed below.

  1. Loading a Amplify configuration so it is specific to a region
  2. Changing the configuration at build time
  3. Changing the configuration after the app has been launched and configured

Scenario 1

By default when Amplify is configured it will load amplifyconfiguration.json from the main bundle of the app. It is possible to use an alternative .json file by loading it and creating an instance of AmplifyConfiguration with the URL for that file. The selection can be based on whatever logic is appropriate. One use case is to use a specific configuration for a region. Below is some sample code which could be used to configure Amplify by region. It requires placing each .json file into the app bundle.

enum Failure: Error {
    case configurationFileNotFound
}

init() {
    do {
        try configureAmplify(region: "EU")
    } catch {
        fatalError("Failed to configure Amplify: \(error)")
    }
}

func configureAmplify(region: String) throws {
    guard let configPath = Bundle.main.path(forResource: "amplifyconfiguration-\(region)",
                                            ofType: "json") else {
        throw Failure.configurationFileNotFound
    }
    let configURL = URL(fileURLWithPath: configPath)
    let configuration = try AmplifyConfiguration(configurationFile: configURL)
    // TODO: add plugins
    try Amplify.configure(configuration)
}

Scenario 2

The Amplify CLI supports multiple environments such has dev, qa and prod. You can switch between these environments which will change the contents of amplifyconfiguration.json which is a resource file included in the app bundle when it is built. When the environment is changed it is best to also update the App ID which will install the app as a separate app from another App ID since it will create keychain items and other resources specific to that Amplify environment. Using the CLI to change the environment and set the App ID will support scenario 2 above.

Scenario 3

Dynamically changing the configuration after the app has already been configured is not supported. This is due to operations which are still in process. There is no support tracking all operations which could cancel each of them and wait until they are completed before switching over to the other configuration. This issue covers this scenario as a feature request.

@sonic555gr
Copy link

Anyone has any updates, please?

@harsh62
Copy link
Member

harsh62 commented Nov 20, 2023

@sonic555gr The team is still trying to prioritize the feature internally. We will post an update on the issue as soon as we have more information.

@sonic555gr
Copy link

Thank you. This feature is needed for our business model. As we have 1 app with multiple potential pools with different accounts for every physical user. At the moment, after the user logs out from one pool and tries to login into a different pool, we force shut the app and ask them to relaunch which feels wrong as UX goes. This feature will go a long way to improve our app.

@harsh62
Copy link
Member

harsh62 commented Nov 21, 2023

At this moment, Amplify does not offer any features/workarounds that can support this use case. Please keep watching this issue for updates.

@gaffarmalik
Copy link

gaffarmalik commented Sep 16, 2024

Hello, please has there been any update regarding this feature?
It's would also be helpful for nextjs (react) apps that need to support cognito multi tenant user-pools. Dynamically updating the config input through redux or Context API would be super helpful.

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 16, 2024
@DrBeak1
Copy link

DrBeak1 commented Sep 23, 2024

Running into the issue of not being able to re-configure during runtime.
Our auth flow supports several regions, we have a different config file per region / user-pool.
When a user tries to log in we first fetch what region (if any) they have an account in and then configure Amplify with the correct config file based on that information.
Things get weird if they sign-out of that account and then try to sign into an account in a different region because we're now not able to sign into any other region unless we kill the app and allow the user to select a different one and we reconfigure Amplify.
At this point, I'm tempted to fork the repo and build some sort of reconfigure option.

@harsh62
Copy link
Member

harsh62 commented Sep 23, 2024

re-configure during runtime

This is not a supported use case. It would need to be implemented as part this feature request. The weird behaviour you see is because of Amplify maintaining configuration states at several places in the code.

We are definitely open to seeing a community PR and will prioritize reviewing any PR's opened by our community members.

@github-actions github-actions bot removed the pending-maintainer-response Issue is pending response from an Amplify team member label Sep 23, 2024
@yanz-safe
Copy link

Hi @DrBeak1 did you had any progress with fork? My company needs the same functionality, as we support multi-tenant approach with different regions. While on the web, it is natively switched, but we have only one mobile app that should support all the regions. The weird thing, we have Demo environment we separate aws stack from production and need to switch between them smoothly.

I am also thinking about the forking the lib with the goal to achieve this

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Nov 20, 2024
@harsh62 harsh62 removed the pending-maintainer-response Issue is pending response from an Amplify team member label Nov 21, 2024
@DrBeak1
Copy link

DrBeak1 commented Nov 21, 2024

@yanz-safe My team decided it was less risky to just handle the lock state gracefully. In our case, if a user tries to log in with one region the app is essentially locked to that region until they kill the app. The edge case is only an issue if a user tries to (a) sign in and fails because they tried to log in with the wrong region selected, or (b) if the user logs out of one user/region and then needs to login with a user that has a different region.
All of that said, I did fork the amplify-swift repo, removed some of the guard statements preventing reconfiguration (specifically in AuthCategory.swift and AmplifyConfiguration.swift and everything seemed to work just fine upon reconfiguration. But I didn't test this extensively due to the teams decision to go the other route.
Frankly, I don't understand how this isn't considered a "supported use case". Placing users in a lock state is just such a bad UX.
Perhaps we're doing something wrong with our amplify config files? Is there a way to have a single config file support multiple regions / user pools, etc? Again, just doesn't make sense to me.
Another solution I've been toying with is just using AWSCore and AWSCognitoIdentityProvider. Using these two SDKs you can successfully sign-in/out, setting clientId, clientSecret, poolId, and region on the fly. No restrictions on configuration. So the issue seems to be with Amplify. The only problem with going this route would be, I think you'll need to do your own caching in Keychain and token renewal (which are both handled for you by Amplify).

@github-actions github-actions bot added the pending-maintainer-response Issue is pending response from an Amplify team member label Nov 21, 2024
@yanz-safe
Copy link

@DrBeak1 thanks for answer.
We have already implemented such "lock" state with app restart. But we want to improve that.
I have seen that there are reset method already exist in SDK for testing. Would happy to know why it cannot be used in production. Maybe someone from Amplify team can provide clarifications and details. Is there any big issues with it like some deep-nested used Singletons that should be reseted on multiple places, etc.

@harsh62 harsh62 self-assigned this Jan 30, 2025
@anankul
Copy link

anankul commented Feb 4, 2025

@harsh62 - any update on this? This is blocking us, in our mobile app, user can switch different countries and based on country they will go to different aws region... Outside this, we also have a test app that connects to different environments that target different aws account and regions. At minimum, can Amplify.reset() method which currently is internal be made public so caller can reset and reconfigure?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Amplify Core components feature-request Request a new feature pending-maintainer-response Issue is pending response from an Amplify team member
Projects
None yet
Development

No branches or pull requests

9 participants