Skip to content

Commit

Permalink
Handle incomplete promise in web authentication (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
poovamraj committed Nov 10, 2023
1 parent ba0858b commit 8a05917
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion android/src/main/java/com/auth0/react/A0Auth0Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class A0Auth0Module extends ReactContextBaseJavaModule implements Activit
private final ReactApplicationContext reactContext;
private Auth0 auth0;
private SecureCredentialsManager secureCredentialsManager;
private Promise webAuthPromise;

public A0Auth0Module(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
Expand Down Expand Up @@ -141,6 +143,7 @@ public String getName() {

@ReactMethod
public void webAuth(String scheme, String redirectUri, String state, String nonce, String audience, String scope, String connection, int maxAge, String organization, String invitationUrl, int leeway, boolean ephemeralSession, ReadableMap additionalParameters, Promise promise) {
this.webAuthPromise = promise;
Map<String,String> cleanedParameters = new HashMap<>();
for (Map.Entry<String, Object> entry : additionalParameters.toHashMap().entrySet()) {
if (entry.getValue() != null) {
Expand Down Expand Up @@ -182,11 +185,13 @@ public void webAuth(String scheme, String redirectUri, String state, String nonc
public void onSuccess(Credentials result) {
ReadableMap map = CredentialsParser.toMap(result);
promise.resolve(map);
webAuthPromise = null;
}

@Override
public void onFailure(@NonNull AuthenticationException error) {
handleError(error, promise);
webAuthPromise = null;
}
});
}
Expand Down Expand Up @@ -241,6 +246,9 @@ public void onActivityResult(Activity activity, int requestCode, int resultCode,

@Override
public void onNewIntent(Intent intent) {
// NO OP
if(webAuthPromise != null) {
webAuthPromise.reject("a0.session.browser_terminated", "The browser window was closed by a new instance of the application");
webAuthPromise = null;
}
}
}

0 comments on commit 8a05917

Please sign in to comment.