hotwired / turbo-android

Android framework for making Turbo native apps
MIT License
424 stars 50 forks source link

Handling of redirect to external site #269

Closed MichalSznajder closed 1 year ago

MichalSznajder commented 1 year ago

I have web shop web application that uses Hotwire and I'm trying to create an native app around it. I am not sure how I should handle following payment scenario:

  1. User presses Start Payment button in my app
  2. I execute Turbo.visit(BANK_URL)
  3. Turbo Drive updates window.location.href with BANK_URL (kind of redirect to external url)
  4. Browser opens bank payment page
  5. User pays
  6. Bank redirect to my application

With Turbo Native it does not work since TurboWebChromeClient intercepts new window creation and I have CORS failures when fetch is executed to external page.

What is proper solution for this? I am thinking of creating separate TurboFragment with new WebView, visit BANK_URLand intercept redirect from bank to navigate on Turbo Native side.

Demo app also show usage of CutomTab but I am not sure if I can intercept redirect in this scenario.

MichalSznajder commented 1 year ago

I first tried with androidx.browser.customtabs.CustomTabsIntent to create separate Chrome instance and than use linking to go back to app. This works quite well.

In the end I ended with new activity with separate WebView since I have multple flavors and I didn't want to customize ANdroidManifest.xml for each flavour to allow deep linking.

kyrylo commented 12 months ago

@michalsznajder hi, I am not an Android developer, but I am facing a very similar issue. I figured out how to open a Chrome instance, but I am unsure how to use linking to go back to the app. Could you, please, share the way to achieve it or point me in the right direction?