From 65634ffd2088b80c95ce050f06f6b8c9d4f17801 Mon Sep 17 00:00:00 2001 From: Naresh-Narsing Date: Sun, 9 Feb 2025 17:38:45 +0530 Subject: [PATCH 1/2] Added isLoggedIn property to get currentuser object fetched from getCurrentUser method --- .../com/mparticle/react/MParticleModule.java | 5 +++-- ios/RNMParticle/RNMParticle.m | 3 ++- js/index.js | 19 +++++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/mparticle/react/MParticleModule.java b/android/src/main/java/com/mparticle/react/MParticleModule.java index 1e322c3..a1da551 100644 --- a/android/src/main/java/com/mparticle/react/MParticleModule.java +++ b/android/src/main/java/com/mparticle/react/MParticleModule.java @@ -287,9 +287,10 @@ public void getCurrentUserWithCompletion(Callback completion) { MParticleUser currentUser = MParticle.getInstance().Identity().getCurrentUser(); if (currentUser != null) { String userID = Long.toString(currentUser.getId()); - completion.invoke(null, userID); + boolean isLoggedIn = currentUser.isLoggedIn; + completion.invoke(null, userID, isLoggedIn); } else { - completion.invoke(null, null); + completion.invoke(null, null, false); } } diff --git a/ios/RNMParticle/RNMParticle.m b/ios/RNMParticle/RNMParticle.m index e042c3d..bdcde13 100644 --- a/ios/RNMParticle/RNMParticle.m +++ b/ios/RNMParticle/RNMParticle.m @@ -349,7 +349,8 @@ + (void)load { RCT_EXPORT_METHOD(getCurrentUserWithCompletion:(RCTResponseSenderBlock)completion) { - completion(@[[NSNull null], [[[MParticle sharedInstance] identity] currentUser].userId.stringValue]); + MParticleUser *currentUser = [[MParticle sharedInstance] identity].currentUser; + completion(@[[NSNull null], currentUser.userId.stringValue, @(currentUser.isLoggedIn)]); } RCT_EXPORT_METHOD(getUserIdentities:(NSString *)userId completion:(RCTResponseSenderBlock)completion) diff --git a/js/index.js b/js/index.js index f2ed42b..739aa43 100644 --- a/js/index.js +++ b/js/index.js @@ -164,8 +164,9 @@ const setLocation = (latitude, longitude) => { // ******** Identity ******** class User { - constructor (userId) { - this.userId = userId + constructor (userId, isLoggedIn = false) { + this.userId = userId; + this.isLoggedIn = isLoggedIn; } getMpid () { @@ -248,13 +249,15 @@ class IdentityRequest { class Identity { static getCurrentUser (completion) { - NativeModules.MParticle.getCurrentUserWithCompletion((error, userId) => { - if (error) { - console.log(error.stack) + NativeModules.MParticle.getCurrentUserWithCompletion( + (error, userId, isLoggedIn) => { + if (error) { + console.log(error.stack); + } + var currentUser = new User(userId, isLoggedIn); + completion(currentUser); } - var currentUser = new User(userId) - completion(currentUser) - }) + ); } static identify (IdentityRequest, completion) { From 890aa809229b2e3cc68ff030069ca296cb4cc9b6 Mon Sep 17 00:00:00 2001 From: Naresh-Narsing Date: Thu, 6 Mar 2025 20:19:14 +0530 Subject: [PATCH 2/2] Added isLoggedIn property in currentUser object --- js/index.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/js/index.js b/js/index.js index 739aa43..036b0f7 100644 --- a/js/index.js +++ b/js/index.js @@ -164,9 +164,8 @@ const setLocation = (latitude, longitude) => { // ******** Identity ******** class User { - constructor (userId, isLoggedIn = false) { - this.userId = userId; - this.isLoggedIn = isLoggedIn; + constructor (userId) { + this.userId = userId } getMpid () { @@ -249,15 +248,15 @@ class IdentityRequest { class Identity { static getCurrentUser (completion) { - NativeModules.MParticle.getCurrentUserWithCompletion( - (error, userId, isLoggedIn) => { - if (error) { - console.log(error.stack); - } - var currentUser = new User(userId, isLoggedIn); - completion(currentUser); + NativeModules.MParticle.getCurrentUserWithCompletion((error, userId, isLoggedIn) => { + if (error) { + console.log(error.stack); } - ); + var currentUser = new User(userId); + currentUser.isLoggedIn = isLoggedIn || false; + completion(currentUser); + } + ); } static identify (IdentityRequest, completion) {