Question

Only using custom App User ID

  • 28 October 2023
  • 5 replies
  • 83 views

Badge +5

The documentation clearly states that to use only custom App User ID, we just need to configure the SDK with a custom app user id. Never calling logout. But my question is tied to multiple users using the same application on same device: do we need to call login() to be safe or anything special when the app authenticates a different user in? This seems to talk about this but not sure when it says login just means actually login()?

Also is it ok to configure the SDK much further down in a user flow where only purchases are needed? Say when they navigate to settings->purchases. This way when starting the app (even if user is logged in) we will not configure. This way it will ensure that anonymous IDs will never be created. I am just not sure if this is ok to call configure each time a screen open and if there is any performance impact..


5 replies

Userlevel 4
Badge +6

Hey @vic-a563d7 !

 

Correct, if you currently have a user logged in to an identified user ID and they want to switch to another app user ID that is custom, you can just use the login() method and pass in that app user ID rather than calling logout() first. Calling logout() first will cause us to generate an anonymous app user ID which can complicate things more when just trying to switch from one identified user ID to another. 

 

You don't need to call configure each time a screen is open and it should only be called once. This is because once it is called, the same instance is shared throughout your app by accessing the .shared instance in the SDK. We recommend calling it early on in your apps lifecycle to ensure that everything from the entitlement side runs smoothly and that the user is authenticated. If your app has logic on it that might change based on entitlements before the settings page is hit in this instance then if you do not configure before that then you would not be able to gain access to whatever is behind those entitlements. 

 

Let me know if that helps and if you have any other questions. 

Badge +5

Ok yes I would definitely like to avoid calling logout() and generate anon IDs. But what I am asking if it is ok to call login() without logout() for different users.

Maybe this examples would be easier to confirm that I understood:

  • Application has login screen and the rest is behind auth
  • UserA launches the app and is prompted for login creds (cant configure yet during app launch).
  • UserA authenticates and now I am able to configure with the userA_id.
  • UserA logs off (I assume I do nothing here yet?)
  • We are back on the login screen
  • UserB logs in and now I call login() but not configure()?

Is this the suggested way?

If so, is there a way to know if the SDK is configured so I don’t call configure() twice?

Is it bad that the user is logged off but the SDK is still configured in memory with the previous user’s ID?

 

Userlevel 4
Badge +6

Hey There,

 

Yes, to switch accounts you are able to call login() directly while another app user ID is currently logged in without calling the logout() method first. We have a small callout of this here.

 

If so, is there a way to know if the SDK is configured so I don’t call configure() twice?

In order to do this, I recommend just calling configure early on in your apps lifecycle and making sure that you dont call it again. After configuration, the same instance is shared throughout your app by accessing the .shared instance in the SDK. More information on this can be found here

 

Is it bad that the user is logged off but the SDK is still configured in memory with the previous user’s ID?

I wouldn't recommend this, I would recommend making sure to call login() as soon as you have the desired app user ID just to make sure that everything is synced up perfectly! 

Badge +5

sorry more questions since it’s not super clear. 

I wouldn't recommend this, I would recommend making sure to call login() as soon as you have the desired app user ID just to make sure that everything is synced up perfectly! 

Above that you seemed to say it’s ok to not log out and call login() again. But the above seems to contradict the premise since UserA has to log out and we don’t know when UserB will log back in. At that time, between 2 users, the SDK is still in memory with UserA’s id stored.

Just trying to see what is the suggested common flow for a common app that has a login screen. The entire app is behind a login, but I am not clear how to treat the Purchases SDK when multiple users log in one after the other or even the same user logging back in and out.

In react native, if the component where the configure() is called is unmounted, will the Purchases SDK still be active and “shared”?

Badge +5

I was able to find isConfigured() based on similar issues I think. The component that I have is inside the authenticated path of the application so it fires the load each time there is a user login, this is why I think I need this method to be able to not configure twice. 

Could you confirm this is a good setup?

1- First user to ever login is the one that will configure() with his app user ID.

2- When that first user logs out, the code does nothing.

3- When another user logs in (or even the same first user again) we know the SDK is configured and only call login() with the newly signing in user.

Reply