How can I get the currently logged in user? | Community
Skip to main content
Answered

How can I get the currently logged in user?

  • Dec 16, 2022 11:08 AM UTC
  • 13 replies
  • 2065 views

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.

Best answer by Aparna

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?

View original

13 replies

Forum|alt.badge.img+5
  • Employee
  • Answer
  • Dec 22, 2022 5:01 PM UTC

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?


  • New Participant
  • Feb 28, 2023 3:59 AM UTC

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?


  • New Participant
  • Sep 22, 2023 3:28 PM UTC

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?


  • New Participant
  • Nov 10, 2023 12:11 AM UTC

+1 For this issue for us as well.


  • New Participant
  • May 23, 2024 1:27 AM UTC

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. 


  • New Participant
  • Jun 26, 2024 9:25 AM UTC

I’m facing the same issue. Without a method to check if a user is logged in, it’s not possible to add this library to an existing production app where users are already logged in, and also have them be logged in to intercom. The only option would be to force users to log out so that they can log in again.

 

Unfortunately the Flutter workaround above doesn’t work as the React Native updateUser() does not have a callback argument. 


  • New Participant
  • Nov 8, 2024 1:07 PM UTC

Hello,

The new library version 8.1.0 includes the isUserLoggedIn() method, but it always returns true, even when I manually call the loginUnidentifiedUser() method.

Is anyone else experiencing this issue?

Thanks!

 

Nur Nahid
Expert User ✨
Forum|alt.badge.img+6
  • Expert User ✨
  • Nov 12, 2024 3:43 PM UTC

This might help you fix the issue. Check out the documentation here.