Skip to content

Commit dccf230

Browse files
authored
Fix crash with authenticator not initialized (#16426)
2 parents 7469e21 + 119c1fd commit dccf230

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

WooCommerce/Classes/AppDelegate.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5757
let stores = ServiceLocator.stores
5858
let analytics = ServiceLocator.analytics
5959
let pushNotesManager = ServiceLocator.pushNotesManager
60+
61+
/// This is important to initialize early as there are a few code points where the authenticator is used.
62+
ServiceLocator.authenticationManager.initialize()
6063
stores.initializeAfterDependenciesAreInitialized()
61-
setupAnalytics(analytics)
6264

65+
setupAnalytics(analytics)
6366
setupCocoaLumberjack()
6467
setupLibraryLogger()
6568
setupLogLevel(.verbose)
@@ -224,7 +227,7 @@ extension AppDelegate {
224227
ZendeskProvider.shared.initialize()
225228
}
226229

227-
/// Sets up the WordPress Authenticator.
230+
/// Sets up app analytics.
228231
///
229232
func setupAnalytics(_ analytics: Analytics) {
230233
analytics.initialize()

WooCommerce/Classes/ViewRelated/AppCoordinator.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,11 @@ private extension AppCoordinator {
238238

239239
/// Configures the WPAuthenticator for usage in both logged-in and logged-out states.
240240
func configureAuthenticator() {
241-
authenticationManager.initialize()
241+
if isRunningTests {
242+
/// This is needed to fix crashes in unit tests.
243+
/// The authenticator is initialized in AppDelegate when running the app.
244+
authenticationManager.initialize()
245+
}
242246
authenticationManager.setLoggedOutAppSettings(loggedOutAppSettings)
243247
authenticationManager.displayAuthenticatorIfLoggedOut = { [weak self] in
244248
guard let self, self.isLoggedIn == false else { return nil }

0 commit comments

Comments
 (0)