Publishing app with two different package name

I would appreciate your opinion on the following issue:

I am using Firebase Firestore and Firebase Auth to manage user login and store basic user information (name and email). Since the app will be published in both the US and EU, I am considering creating separate databases for each region to comply with data residency regulations.

My proposed solution involves using the Flutter Flavors package to build the same app with two different package names, each configured with its own Firebase setup. However, I am unsure if this is the best approach or if there is a better way to address this challenge.

One limitation is that I currently don’t have any information to determine whether a user is using the app in the US or the EU.

I would greatly appreciate your insights or recommendations.

Thank you in advance!

1 Like

I’m also quite interested in this topic.

I can say with some certainty that creating two separate apps is probably not the way to go as the stores don’t like having duplicate apps.

You could use the device’s locale as a proxy for location? Or ask the user? Then initialise the Firebase Client with the location property depending on the result.

Your approach using Flutter Flavors sounds solid for managing separate Firebase setups. It’s a good way to comply with data residency regulations.

You can ping v1 Cloud Function and read the header to get Google-detected country code. Return it to the app to know if user is in EU :slight_smile:

export const appLaunch = functions
    .region("europe-west1")
    .runWith({ timeoutSeconds: 60, minInstances: 1 })
    .https
    .onCall(async (data, context) => {
        try {
            const country = context.rawRequest.headers["x-appengine-country"] as string | null;
...

You can set whatever package name you want per flavor. Just make sure to provide correct Google-Services configuration. I wrote about flavors in 2019 and I think it’s still valid today. There’s also nice official guide on it.

However, realistically you shouldn’t be publishing 2 apps for separate regions. Google Play and AppStore won’t let you have 2 identical apps just available in different countries.

You should do the check on the app launch, perhaps cache this information (e.g. in shared prefs) so that it works even when the user doesn’t have internet connection.

Once the user signed up to your desired endpoint, and they try to sign in or come back to the app, you can do a backend cloud function check to just return you a project id to use (if you cache it, then it will not have impact on launch time). You can provide Firebase configuration dynamically to the app by providing it to

await Firebase.initializeApp(
  options: // here your custom config
);

Also I want to add, the location is not enough. EU privacy regulations apply for any EU citizen independent where they are living. So if you want to sell your app to EU users you better make sure you comply to GDPR