Turbo Native - Authentication login form redirect 302

I have a few urls in my app:

/ - Homepage (no auth required)
/login - Login Form (no auth required)
/admin - Displays dashboard for the logged in user (auth required)

If an unauthenticated user visits /admin then they are redirected (302 See Other) to /login. When the user logs in then they are redirected to /admin (302 See Other).

In my Hotwire native app (iOS) I want two things to happen.

When the unauthenticated user visits /admin I want a login modal to appear. Currently a new screen slides in and the request is made, the redirect is followed to /login.

If I add a path configuration to load /login in a modal a modal appears on top of the current view (which also contains the /login html):

{
  "settings": {},
  "rules": [
      {
        "patterns": ["/login"],
        "properties": {
          "context": "modal"
        }
      }
  ]
}

Is is possible to configure the server response / iOS app somehow to catch the 302 and not follow the redirect?

Do I need to add conditional logic in the controller to return a 401 unauthorised for the iOS app and handle that differently?

I don’t want to implement a native iOS authentication login pattern and jwt tokens.

1 Like

I’m dealing with the same issue. Have you found a reasonable work around?

This artile shows how to create a new coordinator and capture the 302.

  • One of the issues you will enconter after signing in is that your other tabs will already be loaded in your logged out state. There are various threads with with discussions are using native code to force reload every tab.
  • The other issue I’m encountering after signin is that the session expires if you close the app. So I’m currently working through the code to save the session or API token in the users keychain. I just need to figure out how to restore the session cookie on future visits.