Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit 3c345b6

Browse files
committed
Pass a new SignInError with SignInSource for specific sign in errors from GetStartedViewController.
1 parent a07b1de commit 3c345b6

File tree

4 files changed

+40
-12
lines changed

4 files changed

+40
-12
lines changed

WordPressAuthenticator/Navigation/NavigateToEnterAccount.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ private extension NavigateToEnterAccount {
1515
DDLogError("Failed to navigate from LoginPrologueViewController to GetStartedViewController")
1616
return
1717
}
18+
vc.source = .wpCom
1819

1920
navigationController?.pushViewController(vc, animated: true)
2021
}

WordPressAuthenticator/Signin/LoginPrologueViewController.swift

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ class LoginPrologueViewController: LoginViewController {
397397
DDLogError("Failed to navigate from LoginPrologueViewController to GetStartedViewController")
398398
return
399399
}
400+
vc.source = .wpCom
400401

401402
navigationController?.pushViewController(vc, animated: true)
402403
}
@@ -436,15 +437,6 @@ class LoginPrologueViewController: LoginViewController {
436437
navigationController?.pushViewController(toVC, animated: true)
437438
}
438439

439-
private func presentGetStartedView() {
440-
guard let toVC = GetStartedViewController.instantiate(from: .getStarted) else {
441-
DDLogError("Failed to navigate to GetStartedViewController")
442-
return
443-
}
444-
445-
navigationController?.pushViewController(toVC, animated: true)
446-
}
447-
448440
// Shows the VC that handles both Google login & signup.
449441
private func presentUnifiedGoogleView() {
450442
guard let toVC = GoogleAuthViewController.instantiate(from: .googleAuth) else {

WordPressAuthenticator/Unified Auth/View Related/Get Started/GetStartedViewController.swift

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,37 @@ import UIKit
22
import SafariServices
33
import WordPressKit
44

5+
/// The source for the sign in flow for external tracking.
6+
public enum SignInSource {
7+
/// Initiated from the WP.com login CTA.
8+
case wpCom
9+
/// Initiated from the WP.com login flow that starts with site address.
10+
case wpComSiteAddress
11+
/// Other unspecified sources.
12+
case other
13+
}
14+
15+
/// The error during the sign in flow.
16+
public enum SignInError: Error {
17+
case invalidWPComEmail(source: SignInSource)
18+
19+
init?(error: Error, source: SignInSource) {
20+
let error = error as NSError
21+
22+
switch error.code {
23+
case WordPressComRestApiError.unknown.rawValue:
24+
let restAPIErrorCode = error.userInfo[WordPressComRestApi.ErrorKeyErrorCode] as? String
25+
if restAPIErrorCode == "unknown_user" {
26+
self = .invalidWPComEmail(source: source)
27+
} else {
28+
return nil
29+
}
30+
default:
31+
return nil
32+
}
33+
}
34+
}
35+
536
class GetStartedViewController: LoginViewController, NUXKeyboardResponder {
637

738
private enum ScreenMode {
@@ -36,6 +67,8 @@ class GetStartedViewController: LoginViewController, NUXKeyboardResponder {
3667
// This is public so it can be set from StoredCredentialsAuthenticator.
3768
var errorMessage: String?
3869

70+
var source: SignInSource = .other
71+
3972
private var rows = [Row]()
4073
private var buttonViewController: NUXButtonViewController?
4174
private let configuration = WordPressAuthenticator.shared.configuration
@@ -509,14 +542,15 @@ private extension GetStartedViewController {
509542
// username instead.
510543
self.showSelfHostedWithError(error)
511544
} else {
545+
let signInError = SignInError(error: error, source: source) ?? error
512546
guard let authenticationDelegate = WordPressAuthenticator.shared.delegate,
513-
authenticationDelegate.shouldHandleError(error) else {
514-
self.displayError(error as NSError, sourceTag: self.sourceTag)
547+
authenticationDelegate.shouldHandleError(signInError) else {
548+
displayError(error as NSError, sourceTag: sourceTag)
515549
return
516550
}
517551

518552
/// Hand over control to the host app.
519-
authenticationDelegate.handleError(error) { customUI in
553+
authenticationDelegate.handleError(signInError) { customUI in
520554
// Setting the rightBarButtonItems of the custom UI before pushing the view controller
521555
// and resetting the navigationController's navigationItem after the push seems to be the
522556
// only combination that gets the Help button to show up.

WordPressAuthenticator/Unified Auth/View Related/Site Address/SiteAddressViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ private extension SiteAddressViewController {
588588
DDLogError("Failed to navigate from SiteAddressViewController to GetStartedViewController")
589589
return
590590
}
591+
vc.source = .wpComSiteAddress
591592

592593
vc.loginFields = loginFields
593594
vc.dismissBlock = dismissBlock

0 commit comments

Comments
 (0)