Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix authentication flow in demo app #36

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}
}