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

Reconfigure Amplify at runtime (call Amplify.configure() multiple times) #1902

Open
sagar-sable opened this issue Jul 20, 2022 · 21 comments
Open
Labels
core Issues related to the Amplify Core Plugin feature-request A request for a new feature or an enhancement to an existing API or category.

Comments

@sagar-sable
Copy link

sagar-sable commented Jul 20, 2022

Updated Request

The ability to call Amplify.configure() multiple times with new config values, or to use different config values based on region or other condition.

Original Request

I want to configure amplify once for Online including AmplifyDataStore Plugin and AmplifyAPI Plugin and second once for offline only AmplifyDataStore Plugin.
How to remove configuration of amplify?

@ragingsquirrel3 ragingsquirrel3 added feature-request A request for a new feature or an enhancement to an existing API or category. core Issues related to the Amplify Core Plugin pending-triage This issue is in the backlog of issues to triage and removed pending-triage This issue is in the backlog of issues to triage labels Jul 21, 2022
@ragingsquirrel3
Copy link
Contributor

@sagar14791 this is not currently possible so marked this as a feature request.

@tolik505
Copy link

@ragingsquirrel3 is there any workaround besides app restart?

@ragingsquirrel3 ragingsquirrel3 added question A question about the Amplify Flutter libraries feature-request A request for a new feature or an enhancement to an existing API or category. and removed feature-request A request for a new feature or an enhancement to an existing API or category. question A question about the Amplify Flutter libraries labels Jul 25, 2022
@sagar-sable
Copy link
Author

@ragingsquirrel3 Amplify.reset(); gives error
"The member 'reset' can only be used within 'package:amplify_flutter/src/amplify_impl.dart' or a test."

@dnys1
Copy link
Contributor

dnys1 commented Jul 25, 2022

Sorry for the confusion here. To clarify, runtime re-configuration is not currently supported in the underlying iOS/Android libraries. We are tracking this as a feature request here and will post further updates there.

@dnys1 dnys1 closed this as completed Jul 25, 2022
@sagar-sable
Copy link
Author

@dnys1 is this feature going to get added anytime soon?

@Jordan-Nelson
Copy link
Member

I am going to re-open this issue. This was closed as a duplicate of #1208. While there are similarities between the two requests, they do seem to be distinct.

We will use this issue to track interest in the ability to re-configure Amplify at run time. That is, call Amplify.configure() multiple times.

#1208 will be used to track interest in a new service which allows pulling any configuration data from a remote source. While this configuration data could be an Amplify config, it could also be any other data such as feature flags.

@Jordan-Nelson Jordan-Nelson reopened this Mar 3, 2023
@Jordan-Nelson Jordan-Nelson changed the title Reconfigure Amplify Reconfigure Amplify at runtime (call Amplify.configure() multiple times) Mar 3, 2023
@Jordan-Nelson
Copy link
Member

This feature is not currently on our roadmap. If you would like to see this supported, please comment with details about your use case. Thanks.

@flodaniel
Copy link

I want to describe our use-case:
We are offering our app in the european union and in the US. With the EU having the GDPR (data privacy law), we have duplicated our entire AWS infrastructure and are basically running a mirrored setup in eu-central-1 and us-east-1. In our flutter app the user has the option to switch between the two regions on the very first screen, which is why we would need a reconfigure() call, that allows the user to, for example, swap back from a selected us-east-1 to eu-central-1.

@sagar-sable
Copy link
Author

sagar-sable commented Mar 13, 2023

@Jordan-Nelson Thank you for re-opening this issue
I have One application that I am using for data collection offline and online,
for Online data Collection and sync to amplify I am using the following Configuration.

          Future<void> _configureAmplifyOnline() async {
            await Amplify.addPlugins([ 
              AmplifyDataStore(modelProvider: ModelProvider.instance),
              AmplifyAPI(), // to connect to amplify 
            ]);
            await Amplify.configure(amplifyconfig);
          }

for Offline data Collection and storing data Offline, I am using the following Configuration.

         Future<void> _configureAmplifyOfflnine() async {
            await Amplify.addPlugins([ 
              AmplifyDataStore(modelProvider: ModelProvider.instance), //only to store data in oflline
              ]);
            await Amplify.configure(amplifyconfig);
          }

now when I am online and collecting data all works fine, as soon as I enter data it goes to the datastore and gets synced to amplify,
but if all of a sudden I went offline due to a network issue, My data will get saved in the datastore and won't be synced, later when the network is there data will get synced as in my Online configuration I have AmplifyAPI(); Plugin.
Condition 1:
If I have to send my user to areas where there is no network available, he or she will sync data(Daily Tasks) from Amplify to a Mobile device at Office or where Network is available i.e Delta sync, sync will happen once every day then they may close the application,
after on-field, if they start the application again they will have 2 Options to select Continue in Online ( which will again sync data and it will add AmplifyAPI(); in current configuration) or In Offlince which will not Sync data (but it will not add AmplifyAPI(); in the configuration which will stop data sync from device to server)
then they will start the journey

at the end of the day when they will reach the office or any time of the day they have access to the network, they should be able to Sync data
for that, there is a button in the application for data syncing,
which should be able to change the configuration of Amplify from
Offline

            await Amplify.addPlugins([ 
              AmplifyDataStore(modelProvider: ModelProvider.instance),
            ]);

to Online

            await Amplify.addPlugins([ 
              AmplifyDataStore(modelProvider: ModelProvider.instance),
              AmplifyAPI(), // to connect to amplify 
            ]);

So basically, I should be able to change the configuration of Amplify on demand. it can be region based or just basic Configuration.

@sagar-sable
Copy link
Author

@ragingsquirrel3 @dnys1 @Jordan-Nelson
My company is developing an application for a very big client using Amplify and we are stuck since last year on this Amplify Reconfiguration thing only.
Can anyone update me on this? Otherwise, we have to remove all AWS services and develop the application using other available services.

@mugbug
Copy link

mugbug commented May 31, 2023

I'd like to describe our use case as well:

Our app currently supports two countries. For each country, we have a different Amplify project with a different list of users. So one user can have two different accounts, one for each country. And we allow the user to dynamically change its current country through a feature inside the app. When that happens, we log the user out so they can log in again on the selected country context. But to allow the user to log in on the selected country, we'd need to re-configure the amplify sdk with the configurations for the selected country amplify project, which is currently not possible.

(I'm also on version v0.6 because of some dependency conflicts, but we will probably migrate to v1 soon)

@richwcahill
Copy link

Please consider adding a runtime amplify reconfiguration. My customers have different API endpoints, and in React + Apollo I can dynamically set those urls
Thanks!

@abdallahshaban557
Copy link
Contributor

Hello everyone, thank you for all the feedback on needing this feature. We have it on our radar, and we will investigate how to enable this moving forward. We will provide an update when we have a path forward.

@krrskl
Copy link

krrskl commented Jul 1, 2023

Hello everyone, I have been interested in this function, especially my use case is to update the amplify configurations when any aws region presents a problem.

Right now the solution I see is to force the app to close and have the user start it again.

@jfacoustic
Copy link

@abdallahshaban557 Any updates on this feature?

@richwcahill
Copy link

To clarify my request....I need to modify the GQL/Appsync Endpoints based on claims made in Cognito user attributes. Otherwise a Flutter/Amplify app can only connect with an initial configuration. My clients who use my app have unique APIs, hence the problem with a static amplifyconfiguration.dart file.

In an my React/Amplify app, I implement Apollo HttpLink within the client, which allows me to change the GQL URL at any time after the user has authenticated with Cognito. Thus, allowing me to modify user access based on their attributes post authentication.

https://www.apollographql.com/docs/react/api/link/apollo-link-http/

However, React does not provide an easy, maintainable development path for mobile/tablet (and even desktop) like flutter does.

Is there a roadmap to implement such a feature?

@abdallahshaban557
Copy link
Contributor

Hello @richwcahill - thank you for sharing that use case. We understand this request, and have plans to enable the re-configuration of Amplify Flutter to accomplish this. We do not have an exact timeline right now - but we will share it on this issue when we do!

@Vumcam
Copy link

Vumcam commented Jan 16, 2024

My use case for the runtime configuration is to enable creating a silo multi-tenant app with one frontend.
Which means that the app has a shared login page, then by using a prefix in the username I would be able to tell which backend environment the user belongs to and reconfigure the environment accordingly and grant the user access to his specific environment only.

@dJani97
Copy link

dJani97 commented Aug 23, 2024

My use-case is a multi-tenant application as well. As a workaround, I'm experimenting with restarting the Flutter engine using the restart plugin.

The plugin works by creating a new instance of the Flutter Engine. The entry point of the Dart VM is executed again, while the underlying platform specific application keeps running.

This allows me to reconfigure amplify without triggering an AmplifyAlreadyConfiguredException, but I'm yet to test if it causes any runtime issues after the engine is restarted and configured for a different tenant. If Amplify.configure() relies only on Dart code, this may work, since the Dart VM is restarted. If it calls and configures platform implementations, it will cause unexpected issues, because platform code is not restarted.

@Jordan-Nelson do you think this could work?

@anankul
Copy link

anankul commented Feb 4, 2025

This is blocking us, in our mobile app, user can switch different countries and based on country they will go to different aws region...we can't use same aws region across countries for privacy and compliance reasons. 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?

@github-actions github-actions bot added the pending-maintainer-response Pending response from a maintainer of this repository label Feb 4, 2025
@tyllark
Copy link
Member

tyllark commented Feb 6, 2025

Hello @anankul, Amplify.reset() it is only supported for internal use within unit tests currently, but you can call it within your code by calling:

// ignore: invalid_use_of_visible_for_testing_member
Amplify.reset();

However some of our packages depend on Amplify iOS/Android SDKs which do not support multiple configurations, so I would not recommend using this in production code. If you can give the iOS/Android issues a thumbs up it will help us gauge interest in them. Unfortunately we are blocked on the Flutter side without a work around until these are implemented.

Edit: I just noticed you have already replied to the iOS issue.

@github-actions github-actions bot removed the pending-maintainer-response Pending response from a maintainer of this repository label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Issues related to the Amplify Core Plugin feature-request A request for a new feature or an enhancement to an existing API or category.
Projects
None yet
Development

No branches or pull requests