Answered

How can I get the currently logged in user?

  • 16 December 2022
  • 10 replies
  • 1121 views

Userlevel 1

I am using the React Native SDK and I would like to know the userId of the currently logged in user.

 

Use-case: after updating to the latest SDK, loginUserWithUserAttributes throws an exception when the user is already logged in.

But I have no way to know if the user is already logged into Intercom (after an app restart for example), and if logged it, if it is logged in using the correct user.

 

I could store this in my app, but this makes the code much more complex.

 

The best solution would be to have an Intercom method to return the currently logged user, if any.

icon

Best answer by Aparna 22 December 2022, 18:01

View original

10 replies

Hey @renaud​ ! Is this issue happening only after updating to the latest RN version? Have you installed as per this doc? Can you send us the full error logs?

We're facing the same issue after upgrading the intercom sdk to v4, what's the expected way to fix this? Every time the user re-opens the app this warning is logged, there's no way to know if a user is logged in.

 

Could you guys provide a method in the sdk to know if the user is logged in?

Same here, after upgrading the intercom, this error started happening too many times.

 

We can’t write workarounds for every service we use.

So either we need a method which will return if there is registered user already or this error shouldn’t be thrown by Intercom

I have the same problem. This method should not raise any exception if user is already logged-in or we should have a method that return the currently logged-in user

Same here, I see many people complaning about this. Any comment from the intercom team ?

We really need a way to check if a user is logged in.

Same here. Is there any way to prevent this?

Yeah not having a method to see if a logged in user exists and which user it is, is creating problems for us as well. Sad to see the only response to this issue from Intercom completely ignores the question.

Hey @renaud​ ! Is this issue happening only after updating to the latest RN version? Have you installed as per this doc? Can you send us the full error logs?

@Aparna this hasn’t solved the issue - please can you reply to the original question?

+1 For this issue for us as well.

Friends who use Intercom! I have a workaround. 

Caveat, I’m using Flutter, but I assume the React Native SDK has the same functionality. 

The updateUser function has a StatusCallback with options for onSuccess and onFailure. These can be used check if the user is logged in. Simply make an updateUser request (say a meaningless customAttribute update). You’ll get a success if the user is logged in to Intercom, and a failure if not logged in. 

In my case, I want to login an unidentified user if they’re not already logged. My implementation was: 
 

await Intercom.instance.updateUser(

         customAttributes: {'CheckLogin': Random().nextInt(99999)},

         statusCallback: IntercomStatusCallback(

                    onFailure: (error) async {

                      await Intercom.instance.loginUnidentifiedUser();

                    },

          ));

 

Note, the updateUser call did nothing if the value sent was the same as previous, so I added a randomizer. 

Reply