Skip to content

Commit

Permalink
Fix authentication flow in demo app
Browse files Browse the repository at this point in the history
  • Loading branch information
joemasilotti committed Oct 10, 2024
1 parent 9c7d6c2 commit 39e3fdc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Demo/Demo.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Foundation

struct Demo {
static let remote = URL(string: "https://hotwire-native-demo.dev/")!
static let remote = URL(string: "https://hotwire-native-demo.dev")!
static let local = URL(string: "http://localhost:45678")!

/// Update this to choose which demo is run
Expand Down
14 changes: 14 additions & 0 deletions Demo/SceneController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,18 @@ extension SceneController: NavigatorDelegate {
return .acceptCustom(HotwireWebViewController(url: proposal.url))
}
}

func visitableDidFailRequest(_ visitable: any Visitable, error: any Error, retryHandler: RetryBlock?) {
if let turboError = error as? TurboError, case let .http(statusCode) = turboError, statusCode == 401 {
promptForAuthentication()
} else if let errorPresenter = visitable as? ErrorPresenter {
errorPresenter.presentError(error) {
retryHandler?()
}
} else {
let alert = UIAlertController(title: "Visit failed!", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
navigator.rootViewController.present(alert, animated: true)
}
}
}

0 comments on commit 39e3fdc

Please sign in to comment.