Skip to content

Commit

Permalink
Added property to control auto dismissing web auth
Browse files Browse the repository at this point in the history
  • Loading branch information
142hitesh committed Jan 31, 2023
1 parent df79c36 commit 37b9a52
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Sources/TeslaSwift/TeslaWebLoginViewContoller.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import WebKit
public class TeslaWebLoginViewController: UIViewController {
var webView = WKWebView()
var result: ((Result<URL, Error>) -> Void)?

public var shouldDismiss: Bool = true

required init?(coder: NSCoder) {
fatalError("not supported")
Expand All @@ -32,7 +34,9 @@ extension TeslaWebLoginViewController: WKNavigationDelegate {
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if let url = navigationAction.request.url, url.absoluteString.starts(with: "https://auth.tesla.com/void/callback") {
decisionHandler(.cancel)
self.dismiss(animated: true, completion: nil)
if shouldDismiss {
self.dismiss(animated: true, completion: nil)
}
self.result?(Result.success(url))
} else {
decisionHandler(.allow)
Expand All @@ -41,7 +45,9 @@ extension TeslaWebLoginViewController: WKNavigationDelegate {

public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error) {
self.result?(Result.failure(TeslaError.authenticationFailed))
self.dismiss(animated: true, completion: nil)
if shouldDismiss {
self.dismiss(animated: true, completion: nil)
}
}
}

Expand Down

0 comments on commit 37b9a52

Please sign in to comment.