Skip to content

Commit 4fb0058

Browse files
committed
check promise before calling it in the android onActivityResult function
1 parent 24336ae commit 4fb0058

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

android/src/main/java/com/rnappauth/RNAppAuthModule.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,14 +300,18 @@ public void onFetchConfigurationCompleted(
300300
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
301301
if (requestCode == 0) {
302302
if (data == null) {
303-
promise.reject("Failed to authenticate", "Data intent is null" );
303+
if (promise != null) {
304+
promise.reject("Failed to authenticate", "Data intent is null" );
305+
}
304306
return;
305307
}
306-
308+
307309
final AuthorizationResponse response = AuthorizationResponse.fromIntent(data);
308310
AuthorizationException exception = AuthorizationException.fromIntent(data);
309311
if (exception != null) {
310-
promise.reject("Failed to authenticate", getErrorMessage(exception));
312+
if (promise != null) {
313+
promise.reject("Failed to authenticate", getErrorMessage(exception));
314+
}
311315
return;
312316
}
313317

@@ -327,9 +331,13 @@ public void onTokenRequestCompleted(
327331
TokenResponse resp, AuthorizationException ex) {
328332
if (resp != null) {
329333
WritableMap map = TokenResponseFactory.tokenResponseToMap(resp, response);
330-
authorizePromise.resolve(map);
334+
if (authorizePromise != null) {
335+
authorizePromise.resolve(map);
336+
}
331337
} else {
332-
promise.reject("Failed exchange token", getErrorMessage(ex));
338+
if (promise != null) {
339+
promise.reject("Failed exchange token", getErrorMessage(ex));
340+
}
333341
}
334342
}
335343
};

0 commit comments

Comments
 (0)