CyberCrime
CyberCrime

Reputation: 31

inappbrowser-reborn react native auth failed in android build release

I have an auth flow using react-native-inappbrowser-reborn. I have the redirect deeplink set up and working for both Android and iOS debug build. However on android when I build release, after login success the browser instantly dismiss and response:

{"message": "chrome tabs activity destroyed", "type": "dismiss"}

the redirect deeplink is demo://success?token='abc'

it work fine both iOS and android debug build and also iOS release build except android

AndroidManifest.xml

 <intent-filter android:label="demo app">
       <action android:name="android.intent.action.VIEW" />
       <category android:name="android.intent.category.DEFAULT" />
       <category android:name="android.intent.category.BROWSABLE" />
       <data android:scheme="demo" android:host="success"/> 
</intent-filter>

My login

onPress={async () => {
  try {
     //when login success web will redirect to this demo://sucess?token='abc'
     //Config.baseUrlTwo = "https://demo.com/"
     const browser = await InAppBrowser.openAuth(Config.baseUrlTwo + "oauth/authenticate",
              "demo://success",
              { forceCloseOnRedirection: false, showInRecents: true }
            );
            if (browser && browser.type === "success") {
              let token = "";
              let getToken = browser.url.match(/'([^']+)'/g) || [];
              if (getToken.length) {
                getToken = getToken.map((match) => match.slice(1, -1));
                token = getToken[0];
              } else if (browser.url.includes("%27")) {
                getToken = browser.url.split("%27") || [];
                if (getToken.length) {
                  token = getToken[1];
                }
              }
              if (token !== "") {
                props.dispatch(Login({ token, ...props }));
              }
            } else {
              Alert.alert(JSON.stringify(browser));
            }
          } catch (error) {
            Alert.alert(error.message);
          }
        }}

I have no idea where this bug come from

Upvotes: 2

Views: 530

Answers (1)

BD Tren
BD Tren

Reputation: 143

Please make sure:

  1. You wrap your code inside an if check: await InAppBrowser.isAvailable()
  2. The demo://success is working in Release App. Try enter that url in a note app and press the link if it can start the App
  3. Try switching forceCloseOnRedirection to true or false.

Bonus: As per their document, please also try adding RNInAppBrowserModule.onStart(this);, it will helps checking if the browser is supported/available and starting it as soon as the App start.

Upvotes: 0

Related Questions