Skip to content

Commit 85ce7d2

Browse files
author
Kadi Kraman
authored
Merge pull request #427 from envato/master
check promise before calling it in the android onActivityResult function
2 parents 1396514 + 005327a commit 85ce7d2

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,14 +371,18 @@ public void onFetchConfigurationCompleted(
371371
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
372372
if (requestCode == 0) {
373373
if (data == null) {
374-
promise.reject("authentication_error", "Data intent is null" );
374+
if (promise != null) {
375+
promise.reject("authentication_error", "Data intent is null" );
376+
}
375377
return;
376378
}
377379

378380
final AuthorizationResponse response = AuthorizationResponse.fromIntent(data);
379381
AuthorizationException exception = AuthorizationException.fromIntent(data);
380382
if (exception != null) {
381-
promise.reject("authentication_error", getErrorMessage(exception));
383+
if (promise != null) {
384+
promise.reject("authentication_error", getErrorMessage(exception));
385+
}
382386
return;
383387
}
384388

@@ -398,9 +402,13 @@ public void onTokenRequestCompleted(
398402
TokenResponse resp, AuthorizationException ex) {
399403
if (resp != null) {
400404
WritableMap map = TokenResponseFactory.tokenResponseToMap(resp, response);
401-
authorizePromise.resolve(map);
405+
if (authorizePromise != null) {
406+
authorizePromise.resolve(map);
407+
}
402408
} else {
403-
promise.reject("token_exchange_failed", getErrorMessage(ex));
409+
if (promise != null) {
410+
promise.reject("token_exchange_failed", getErrorMessage(ex));
411+
}
404412
}
405413
}
406414
};

0 commit comments

Comments
 (0)