Repository navigation
How to route from a modal context to a default context after an external OAuth deep link in Hotwire Native Android? #208
Replies: 1 comment 1 reply
|
The silent failure is expected behaviour given the contexts involved, and it comes down to what When you when (rule.newNavigationMode) {
NavigatorMode.DISMISS_MODAL -> dismissModalContextWithResult(rule)
NavigatorMode.TO_MODAL -> navigateToModalContext(rule)
NavigatorMode.IN_CONTEXT -> navigateWithinContext(rule)
}
private fun dismissModalContextWithResult(rule: NavigatorRule) {
navigateWhenReady {
...
sendModalResult(rule)
popModalsFromBackStack(rule)
}
}So no request is ever sent for Two ways to fix it1. Simplest — make the token exchange an in-context visit. Give the completion URL the same context you're routing from (i.e. { "patterns": ["/users/auth/token_login.*"], "properties": { "context": "modal" } }This keeps the whole flow inside the modal until the server decides you're done, which is usually what you want for an auth completion round-trip. 2. Route on the default navigator instead of the modal's. If you'd rather drive it from the deep link, don't call I'd start with #1 — it's a one-line path-config change and sidesteps both the |
Uh oh!
There was an error while loading. Please reload this page.
Hello! I'm building a Hotwire Native Android app (version 1.3.1) and struggling with completing an OAuth flow initiated from a modal screen.
The Setup:
I have a login screen configured with context: modal in my path_configuration.json.
I built a custom BridgeComponent (SignInWithOauthComponent) that intercepts the "Sign in with Google" button and launches a Chrome Custom Tab.
After OAuth completes in the browser, my Rails server redirects back to the app via a deep link: autism://auth-callback?token=...
My MainActivity (launchMode="singleTask") catches the deep link in onNewIntent, extracts the token, and posts it to a LiveData.
The SignInWithOauthComponent (still alive in the modal) observes this token and tries to complete the login by routing to the server:
val tokenLoginUrl = "/users/auth/token_login?token=$token"
navigator.route(tokenLoginUrl)
The Problem:
If the login screen is set to context: default, everything works perfectly. navigator.route() successfully makes the network request.
However, if the login screen is context: modal, navigator.route() fails silently. Absolutely no network request is sent to the server.
My Questions:
What is the recommended pattern/best practice for handling an external OAuth redirect back into a modal context?
How can I reliably force the mainNavigator to route to a default URL after receiving a deep link while a modal is currently presented?
Any advice or examples would be greatly appreciated! Thank you.
All reactions