@@ -133,34 +133,36 @@ public void onFailure(@NonNull IntercomError intercomError) {
133133
134134 @ ReactMethod
135135 public void loginUserWithUserAttributes (ReadableMap params , Promise promise ) {
136- Boolean hasEmail = params .hasKey ("email" ) && params .getString ("email" ).length () > 0 ;
137- Boolean hasUserId = params .hasKey ("userId" ) && params .getString ("userId" ).length () > 0 ;
138- Registration registration = null ;
139- if (hasEmail && hasUserId ) {
140- registration = new Registration ().withEmail (params .getString ("email" )).withUserId (params .getString ("userId" ));
141- } else if (hasEmail ) {
142- registration = Registration .create ().withEmail (params .getString ("email" ));
143- } else if (hasUserId ) {
144- registration = Registration .create ().withUserId (params .getString ("userId" ));
145- } else {
146- Log .e (NAME , "loginUserWithUserAttributes called with invalid userId or email" );
147- Log .e (NAME , "You must provide userId or email" );
148- promise .reject (IntercomErrorCodes .IDENTIFIED_REGISTRATION , "Invalid userId or email" );
149- }
150- if (registration != null ) {
151- Intercom .client ().loginIdentifiedUser (registration , new IntercomStatusCallback () {
152- @ Override
153- public void onSuccess () {
154- promise .resolve (true );
155- }
136+ Boolean hasEmail = params .hasKey ("email" ) && IntercomHelpers .getValueAsStringForKey (params , "email" ).length () > 0 ;
137+ Boolean hasUserId = params .hasKey ("userId" ) && IntercomHelpers .getValueAsStringForKey (params , "userId" ).length () > 0 ;
138+ Registration registration = null ;
139+ String email = IntercomHelpers .getValueAsStringForKey (params , "email" );
140+ String userId = IntercomHelpers .getValueAsStringForKey (params , "userId" );
141+ if (hasEmail && hasUserId ) {
142+ registration = new Registration ().withEmail (email ).withUserId (userId );
143+ } else if (hasEmail ) {
144+ registration = Registration .create ().withEmail (email );
145+ } else if (hasUserId ) {
146+ registration = Registration .create ().withUserId (userId );
147+ } else {
148+ Log .e (NAME , "loginUserWithUserAttributes called with invalid userId or email" );
149+ Log .e (NAME , "You must provide userId or email" );
150+ promise .reject (IntercomErrorCodes .IDENTIFIED_REGISTRATION , "Invalid userId or email" );
151+ }
152+ if (registration != null ) {
153+ Intercom .client ().loginIdentifiedUser (registration , new IntercomStatusCallback () {
154+ @ Override
155+ public void onSuccess () {
156+ promise .resolve (true );
157+ }
156158
157- @ Override
158- public void onFailure (@ NonNull IntercomError intercomError ) {
159- Log .e ("ERROR" , intercomError .getErrorMessage ());
160- promise .reject (String .valueOf (intercomError .getErrorCode ()), intercomError .getErrorMessage ());
161- }
162- });
163- }
159+ @ Override
160+ public void onFailure (@ NonNull IntercomError intercomError ) {
161+ Log .e ("ERROR" , intercomError .getErrorMessage ());
162+ promise .reject (String .valueOf (intercomError .getErrorCode ()), intercomError .getErrorMessage ());
163+ }
164+ });
165+ }
164166 }
165167
166168 @ ReactMethod
0 commit comments