Cache issue on repositories when changing apiKey

Our App uses 2 Amity configs (both in US region, but we have 2 keys), and we have a set of users that will be able to jump between the two of them. They do so by login in and out with different user ids

So, depending on their region we will initialize the AmityCoreClient.setup with the corresponding key. And also, call unregisterDevice when they log out.

We also make use of CommunityRepository. Which is caching the communities between logins, so when a user jumps from one amity config to another, it gets to see the communities from both configurations. Can this be fixed, please?

Hello Franco,

The data supposed to be wiped when you called “unregisterDevice” function. May you please show me the code snippet when you call registerDevice, unregisterDevice, and setup ?

After a user logs in, we know their region, so we use that to initialize Amity:

            AmityCoreClient.setup(
                apiKey = region.getAmityKey(),
                httpEndpoint = AmityRegionalEndpoint.US,
                socketEndpoint = AmityRegionalEndpoint.US
            )

And right after, the user:

AmityCoreClient.registerDevice(user.userId)
                .displayName(displayName = user.username ?: "User")
                .authToken(user.amityToken)
                .build()
                .submit()
            AmityCoreClient.registerDeviceForPushNotification()
                .doOnComplete {
                    Timber.w("Register complete // Amity")
                    sendFirebaseToken()
                }
                .doOnError {
                    Timber.w("Error Register// Amity")
                }
                .subscribe()

We then call these two method on each app launch.

And when the users logs out we call:

            AmityCoreClient.unregisterDevice().subscribe()
            AmityCoreClient.unregisterDeviceForPushNotification().subscribe()

Thank you Franco,
We will investigate the issue further and keep you updated.

Hello Franco,
We have investigated the issue and tried replicating the issue and can’t seem to reproduce. May you help us log if the unregisterDevice method is successfully executed by

AmityCoreClient.unregisterDevice()
               .subscribeOn(Schedulers.io())
               .doOnError { 
                 // log if it's error
                }
               .doOnComplete {
                // log if it's completed
               .subscribe ()