From 481259cac1ddafead2fc98d3344f85004daaa7e3 Mon Sep 17 00:00:00 2001 From: Ray Shih Date: Thu, 14 Sep 2017 15:55:25 +0900 Subject: [PATCH 1/2] Hot fix for the race condition problem Detail: https://github.com/auth0/react-native-auth0/issues/83 --- .../java/com/auth0/react/A0Auth0Module.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/android/src/main/java/com/auth0/react/A0Auth0Module.java b/android/src/main/java/com/auth0/react/A0Auth0Module.java index 1a2ec6ca..8be71605 100644 --- a/android/src/main/java/com/auth0/react/A0Auth0Module.java +++ b/android/src/main/java/com/auth0/react/A0Auth0Module.java @@ -5,6 +5,7 @@ import android.app.PendingIntent; import android.content.Intent; import android.net.Uri; +import android.os.Handler; import android.support.annotation.NonNull; import android.support.customtabs.CustomTabsIntent; import android.util.Base64; @@ -59,6 +60,7 @@ public void showUrl(String url, boolean closeOnLoad, Callback callback) { CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder(); CustomTabsIntent customTabsIntent = builder.build(); customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); + customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); customTabsIntent.launchUrl(activity, Uri.parse(url)); } else { final Intent intent = new Intent(Intent.ACTION_VIEW); @@ -125,13 +127,19 @@ String generateCodeChallenge(@NonNull String codeVerifier) { @Override public void onHostResume() { - if (this.callback != null) { - final WritableMap error = Arguments.createMap(); - error.putString("error", "a0.session.user_cancelled"); - error.putString("error_description", "User cancelled the Auth"); - this.callback.invoke(error); - this.callback = null; - } + new Handler().postDelayed(new Runnable() { + @Override + public void run() { + Callback cb = A0Auth0Module.this.callback; + if (cb != null) { + final WritableMap error = Arguments.createMap(); + error.putString("error", "a0.session.user_cancelled"); + error.putString("error_description", "User cancelled the Auth"); + cb.invoke(error); + A0Auth0Module.this.callback = null; + } + } + }, 100); } @Override @@ -143,4 +151,4 @@ public void onHostPause() { public void onHostDestroy() { } -} \ No newline at end of file +} From cd440c0d26015317a65d96ba01bc990840a9fd6b Mon Sep 17 00:00:00 2001 From: Martin Walsh Date: Thu, 5 Oct 2017 11:04:06 +0100 Subject: [PATCH 2/2] Use constant --- android/src/main/java/com/auth0/react/A0Auth0Module.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/auth0/react/A0Auth0Module.java b/android/src/main/java/com/auth0/react/A0Auth0Module.java index 8be71605..65081200 100644 --- a/android/src/main/java/com/auth0/react/A0Auth0Module.java +++ b/android/src/main/java/com/auth0/react/A0Auth0Module.java @@ -29,6 +29,7 @@ public class A0Auth0Module extends ReactContextBaseJavaModule implements Lifecyc private static final String US_ASCII = "US-ASCII"; private static final String SHA_256 = "SHA-256"; + private static final int CANCEL_EVENT_DELAY = 100; private final ReactApplicationContext reactContext; private Callback callback; @@ -139,7 +140,7 @@ public void run() { A0Auth0Module.this.callback = null; } } - }, 100); + }, CANCEL_EVENT_DELAY); } @Override