Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
cd33724
Expose missing sign-in error state in tests
austinywang May 6, 2026
239560a
Surface sign-in failures where users can act
austinywang May 6, 2026
f975e88
Merge remote-tracking branch 'origin/main' into issue-3617-sign-in-er…
austinywang May 6, 2026
d52dab0
Keep auth UI changes within Swift file budgets
austinywang May 6, 2026
8f37f3d
Treat web auth cancellation as dismissal
austinywang May 6, 2026
13f41d5
Keep raw auth errors out of Settings copy
austinywang May 6, 2026
3f650e6
Retry macOS CI after Zig download instability
austinywang May 6, 2026
ab73452
Preserve sign-in progress while callbacks settle
austinywang May 6, 2026
9aeb58f
Restart stalled external PR status contexts
austinywang May 6, 2026
4b4d085
Short-circuit failed browser sign-in awaits
austinywang May 6, 2026
20fad03
Make macOS CI tolerate transient Zig downloads
austinywang May 6, 2026
1fe62ed
Integrate main before final CI verification
austinywang May 6, 2026
ce5f2ce
Restart stalled CircleCI workflow after merge
austinywang May 6, 2026
4020b5e
Merge origin/main into issue-3617-sign-in-error-surface
austinywang May 12, 2026
f4bfd12
Hide auth logger helper
austinywang May 12, 2026
7e597fc
Restart stalled external status contexts
austinywang May 12, 2026
414cfc0
Avoid duplicate sign-in error assignment
austinywang May 12, 2026
63256c6
Merge remote-tracking branch 'origin/main' into issue-3617-sign-in-er…
austinywang May 12, 2026
82aa2e1
Await sign-in token persistence
austinywang May 12, 2026
40b30ac
Restart stalled external status contexts
austinywang May 12, 2026
dc27731
Clear stale web auth sessions
austinywang May 12, 2026
970f399
Guard stale web auth completions
austinywang May 12, 2026
2bfa476
Fix web auth session actor isolation
austinywang May 12, 2026
9b9b0b6
Mark auth sign-in state sendable
austinywang May 12, 2026
d1e1c09
Fix credential sign-in error state
austinywang May 13, 2026
ec1e057
Merge origin/main into issue-3617-sign-in-error-surface
austinywang May 13, 2026
375e19e
Merge origin/main into issue-3617-sign-in-error-surface
austinywang May 14, 2026
0d177da
Clear credential sign-in errors at attempt start
austinywang May 14, 2026
599ce3b
Surface browser sign-in timeout errors
austinywang May 15, 2026
32e2f96
Show generic copy for auth sign-in errors
austinywang May 15, 2026
51e928b
Guard async sign-in state publication
austinywang May 17, 2026
9c0b630
Import auth core in auth manager tests
austinywang May 17, 2026
c87e5b9
Guard stale callback sign-in errors
austinywang May 17, 2026
646a325
Merge remote-tracking branch 'origin/main' into issue-3617-sign-in-er…
austinywang May 18, 2026
4fe4bd1
Guard superseded credential sign-ins
austinywang May 18, 2026
3cadbcb
fix: guard stale sign-in error state
austinywang May 18, 2026
c8d8d17
fix: keep credential sign-in supersession internal
austinywang May 18, 2026
3cf371c
Merge remote-tracking branch 'origin/main' into issue-3617-sign-in-er…
austinywang May 18, 2026
6b87919
Merge remote-tracking branch 'origin/main' into issue-3617-sign-in-er…
austinywang May 18, 2026
8739c40
fix: clear stale apply sign-in errors
austinywang May 18, 2026
da3e087
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang May 19, 2026
5e20521
Fix timed-out sign-in callback race
austinywang May 19, 2026
b8af3fa
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang May 19, 2026
39fcbe4
Merge remote-tracking branch 'origin/main' into issue-3617-sign-in-er…
austinywang May 19, 2026
7ecf7d6
Localize sign-in failure copy
austinywang May 19, 2026
30c0278
Return authoritative sign-in await state
austinywang May 19, 2026
826b0b0
merge: resolve main into sign-in error surface
austinywang May 19, 2026
1ae341e
Merge origin/main into issue-3617-sign-in-error-surface
austinywang May 22, 2026
385f953
Merge origin/main into issue-3617-sign-in-error-surface
austinywang May 24, 2026
d64f5f3
Merge branch 'main' of https://github.com/manaflow-ai/cmux into issue…
austinywang May 31, 2026
ba35199
Merge remote-tracking branch 'origin/main' into issue-3617-sign-in-er…
austinywang May 31, 2026
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to cmux are documented here.

## [Unreleased]

### Fixed
- Surface Settings > Sign In failures in Account settings instead of only logging ASWebAuthenticationSession and callback errors ([#3617](https://github.com/manaflow-ai/cmux/issues/3617))
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

## [0.64.3] - 2026-05-05

### Added
Expand Down Expand Up @@ -63,6 +68,7 @@ All notable changes to cmux are documented here.
- Gemini and Rovo Dev session hooks with sessions piped into Vault ([#3530](https://github.com/manaflow-ai/cmux/pull/3530), [#3535](https://github.com/manaflow-ai/cmux/pull/3535))
- iMessage mode for agent prompts ([#3252](https://github.com/manaflow-ai/cmux/pull/3252))
- Settings sidebar shell and unified config utility window with cmux, Ghostty, and synced tabs ([#3024](https://github.com/manaflow-ai/cmux/pull/3024), [#3244](https://github.com/manaflow-ai/cmux/pull/3244), [#3400](https://github.com/manaflow-ai/cmux/pull/3400))
- Settings > Sign In for connecting a cmux account from Account settings
- Make `cmux.json` the canonical settings file with JSONC parsing and legacy `settings.json` fallback ([#3409](https://github.com/manaflow-ai/cmux/pull/3409), [#3424](https://github.com/manaflow-ai/cmux/pull/3424))
- Configurable `cmux.json` workspace and tab bar plus-button actions ([#3084](https://github.com/manaflow-ai/cmux/pull/3084), [#3348](https://github.com/manaflow-ai/cmux/pull/3348))
- Configurable surface tab bar font size ([#2645](https://github.com/manaflow-ai/cmux/pull/2645))
Expand Down
12 changes: 12 additions & 0 deletions GhosttyTabs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
063BC42CEE257D6213A2E30C /* WindowAndDragTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BEE83F8394D90ACACD8E19DD /* WindowAndDragTests.swift */; };
A36170000000000000000001 /* AuthManagerSignInErrorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36170000000000000000002 /* AuthManagerSignInErrorTests.swift */; };
2907A0032907A0032907A003 /* AppDelegateIssue2907RoutingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2907A0042907A0042907A004 /* AppDelegateIssue2907RoutingTests.swift */; };
0F2C25F9170130F8DC09DD1B /* WorkspaceManualUnreadTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1D301919B10F22B8708E8883 /* WorkspaceManualUnreadTests.swift */; };
A11EAA000000000000000000 /* AppearanceSettingsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A11EAA000000000000000001 /* AppearanceSettingsTests.swift */; };
Expand All @@ -25,7 +26,9 @@
C2B6A97D1F2E4C71A8B9D001 /* BrowserOmnibarPerformanceSupportTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C2B6A97D1F2E4C71A8B9D002 /* BrowserOmnibarPerformanceSupportTests.swift */; };
3023A1003023A1003023A100 /* ConfigSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3023B1003023B1003023B100 /* ConfigSource.swift */; };
3023A1013023A1013023A101 /* ConfigSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3023B1013023B1013023B101 /* ConfigSettingsView.swift */; };
A36170000000000000000005 /* AuthSettingsRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36170000000000000000006 /* AuthSettingsRow.swift */; };
350DAC5EBD38642A3E81471A /* AuthManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 312DE7503B4658DD173121B8 /* AuthManager.swift */; };
A36170000000000000000003 /* AuthManagerErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = A36170000000000000000004 /* AuthManagerErrors.swift */; };
36CE99ED050785B5E96B72BB /* AuthCallbackRouter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61A19A4145F034965110CF87 /* AuthCallbackRouter.swift */; };
4378399A7C0245EF8186F306 /* OmnibarAndToolsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B09C007F42697761B5F1A2AB /* OmnibarAndToolsTests.swift */; };
46F6AC15863EC84DCD3770A2 /* TerminalAndGhosttyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 02FC74F2C27127CC565B3E8C /* TerminalAndGhosttyTests.swift */; };
Expand Down Expand Up @@ -461,7 +464,9 @@
2F0C05000000000000000001 /* MainWindowFocusController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainWindowFocusController.swift; sourceTree = "<group>"; };
3023B1003023B1003023B100 /* ConfigSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings/ConfigSource.swift; sourceTree = "<group>"; };
3023B1013023B1013023B101 /* ConfigSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings/ConfigSettingsView.swift; sourceTree = "<group>"; };
A36170000000000000000006 /* AuthSettingsRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Settings/AuthSettingsRow.swift; sourceTree = "<group>"; };
312DE7503B4658DD173121B8 /* AuthManager.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AuthManager.swift; sourceTree = "<group>"; };
A36170000000000000000004 /* AuthManagerErrors.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = AuthManagerErrors.swift; sourceTree = "<group>"; };
FEED0000000000000000F001 /* FeedCoordinator.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = FeedCoordinator.swift; sourceTree = "<group>"; };
FEED0000000000000000F004 /* FeedPanelView.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = FeedPanelView.swift; sourceTree = "<group>"; };
FEED0000000000000000F012 /* FeedPermissionActionPolicy.swift */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.swift; path = FeedPermissionActionPolicy.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -522,6 +527,7 @@
A50019A1 /* SettingsNavigation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsNavigation.swift; sourceTree = "<group>"; };
A50019B1 /* SettingsSearchAliases.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSearchAliases.swift; sourceTree = "<group>"; };
A50019B3 /* SettingsSearchIndexTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSearchIndexTests.swift; sourceTree = "<group>"; };
A36170000000000000000002 /* AuthManagerSignInErrorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthManagerSignInErrorTests.swift; sourceTree = "<group>"; };
B37A00000000000000000002 /* BetaFeaturesSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BetaFeaturesSettingsView.swift; sourceTree = "<group>"; };
B37A00000000000000000008 /* SettingsCardNote.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsCardNote.swift; sourceTree = "<group>"; };
A5001012 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -883,6 +889,7 @@
61A19A4145F034965110CF87 /* AuthCallbackRouter.swift */,
43430FA5929121E2EAAB3091 /* AuthEnvironment.swift */,
312DE7503B4658DD173121B8 /* AuthManager.swift */,
A36170000000000000000004 /* AuthManagerErrors.swift */,
5B1EA8948C5F126FE63CFB4E /* AuthSettingsStore.swift */,
);
name = Auth;
Expand Down Expand Up @@ -968,6 +975,7 @@
children = (
3023B1003023B1003023B100 /* ConfigSource.swift */,
3023B1013023B1013023B101 /* ConfigSettingsView.swift */,
A36170000000000000000006 /* AuthSettingsRow.swift */,
A11EAB000000000000000001 /* AppearanceSettings.swift */,
A11EAC000000000000000001 /* GhosttyTerminalAppearance.swift */,
A11EAD000000000000000001 /* WorkspaceAppearanceResolution.swift */,
Expand Down Expand Up @@ -1235,6 +1243,7 @@
C2B6A97D1F2E4C71A8B9D002 /* BrowserOmnibarPerformanceSupportTests.swift */,
A5008382 /* CommandPaletteSearchEngineTests.swift */,
A50019B3 /* SettingsSearchIndexTests.swift */,
A36170000000000000000002 /* AuthManagerSignInErrorTests.swift */,
970226F3C99D0D937CD00539 /* BrowserConfigTests.swift */,
58C7B1B978620BE162CC057E /* BrowserPanelTests.swift */,
D0B1000DA1B2C3D4E5F60001 /* CmuxWebViewDragRoutingTests.swift */,
Expand Down Expand Up @@ -1741,9 +1750,11 @@
FEED0000000000000000F00B /* FeedPreviewWindowController.swift in Sources */,
FEED0000000000000000F00D /* FeedButtonStyleDebugWindowController.swift in Sources */,
FEED0000000000000000F00F /* FeedTextEditorDebugWindowController.swift in Sources */,
A36170000000000000000005 /* AuthSettingsRow.swift in Sources */,
36CE99ED050785B5E96B72BB /* AuthCallbackRouter.swift in Sources */,
D9FEC58D5BACCF76459F1BBE /* AuthEnvironment.swift in Sources */,
350DAC5EBD38642A3E81471A /* AuthManager.swift in Sources */,
A36170000000000000000003 /* AuthManagerErrors.swift in Sources */,
698944F99A6ADFBA24A7BFB9 /* AuthSettingsStore.swift in Sources */,
ACE4FE1A8F1CC6C0B6A673AB /* VMClient.swift in Sources */,
ACE4FE2A8F1CC6C0B6A673AB /* VMClientSocketCommands.swift in Sources */,
Expand Down Expand Up @@ -1852,6 +1863,7 @@
A5008381 /* BrowserFindJavaScriptTests.swift in Sources */,
A5008383 /* CommandPaletteSearchEngineTests.swift in Sources */,
A50019B2 /* SettingsSearchIndexTests.swift in Sources */,
A36170000000000000000001 /* AuthManagerSignInErrorTests.swift in Sources */,
E12E88F82733EC42F32C36A3 /* BrowserConfigTests.swift in Sources */,
1F14445B9627DE9D3AF4FD2E /* BrowserPanelTests.swift in Sources */,
D0B1000CA1B2C3D4E5F60001 /* CmuxWebViewDragRoutingTests.swift in Sources */,
Expand Down
29 changes: 29 additions & 0 deletions Resources/Localizable.xcstrings
Original file line number Diff line number Diff line change
Expand Up @@ -106451,6 +106451,35 @@
}
}
},
"settings.account.error.signInFailed": {
"extractionState": "manual",
"localizations": {
"en": {
"stringUnit": {
"state": "translated",
"value": "Sign in failed. Try again."
}
},
"ja": {
"stringUnit": {
"state": "translated",
"value": "サインインに失敗しました。もう一度お試しください。"
}
},
"uk": {
"stringUnit": {
"state": "translated",
"value": "Не вдалося ввійти. Спробуйте ще раз."
}
},
"ko": {
"stringUnit": {
"state": "translated",
"value": "로그인에 실패했습니다. 다시 시도하세요."
}
}
}
},
"rightSidebar.mode.feed": {
"extractionState": "manual",
"localizations": {
Expand Down
82 changes: 40 additions & 42 deletions Sources/Auth/AuthManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import AppKit
import AuthenticationServices
import CMUXAuthCore
import Foundation
import OSLog
import StackAuth
#if canImport(Security)
import Security
Expand Down Expand Up @@ -31,32 +32,6 @@ private final class AuthPresentationContext: NSObject, ASWebAuthenticationPresen
}
}

enum AuthManagerError: LocalizedError {
case invalidCallback
case missingAccessToken
case missingRefreshToken

var errorDescription: String? {
switch self {
case .invalidCallback:
return String(
localized: "settings.account.error.invalidCallback",
defaultValue: "The sign-in callback was invalid."
)
case .missingAccessToken:
return String(
localized: "settings.account.error.missingAccessToken",
defaultValue: "Account access token is unavailable."
)
case .missingRefreshToken:
return String(
localized: "settings.account.error.missingRefreshToken",
defaultValue: "Account refresh token is unavailable."
)
}
}
}

protocol StackAuthTokenStoreProtocol: TokenStoreProtocol, Sendable {
func seed(accessToken: String, refreshToken: String) async
func clear() async
Expand Down Expand Up @@ -128,6 +103,7 @@ final class AuthManager: ObservableObject {
@Published private(set) var isLoading = false
@Published private(set) var isRestoringSession = false
@Published private(set) var didCompleteBrowserSignIn = false
@Published private(set) var lastSignInError: AuthSignInError?
@Published var selectedTeamID: String? {
didSet {
guard selectedTeamID != oldValue else { return }
Expand Down Expand Up @@ -186,9 +162,9 @@ final class AuthManager: ObservableObject {
private var webAuthSession: ASWebAuthenticationSession?

func beginSignIn() {
guard webAuthSession == nil else { return }
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
loginPollTask?.cancel()
webAuthSession?.cancel()
webAuthSession = nil
lastSignInError = nil
isLoading = true

let signInURL = AuthEnvironment.signInURL()
Expand All @@ -205,24 +181,34 @@ final class AuthManager: ObservableObject {
self.webAuthSession = nil
}
if let error {
NSLog("auth.webauth failed: %@", "\(error)")
let nsError = error as NSError
if Self.shouldSuppressWebAuthError(nsError) {
Self.authLogger.debug("auth.webauth cancelled by user")
return
}
self.lastSignInError = .message(nsError.localizedDescription)
Self.authLogger.error("auth.webauth failed: domain=\(nsError.domain, privacy: .public) code=\(nsError.code, privacy: .public) description=\(nsError.localizedDescription, privacy: .private)")
return
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
}
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
guard let callbackURL else {
self.lastSignInError = .authManager(.invalidCallback)
return
}
guard let callbackURL else { return }
do {
try await self.handleCallbackURL(callbackURL)
} catch {
NSLog("auth.webauth callback failed: %@", "\(error)")
Self.authLogger.error("auth.webauth callback failed: \(String(describing: error), privacy: .private)")
}
}
}
session.presentationContextProvider = AuthPresentationContext.shared
session.prefersEphemeralWebBrowserSession = false

if session.start() {
webAuthSession = session
} else {
NSLog("auth.webauth: session.start() returned false")
webAuthSession = session
if !session.start() {
Self.authLogger.error("auth.webauth session.start returned false")
webAuthSession = nil
lastSignInError = .message("")
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
isLoading = false
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
}
Expand Down Expand Up @@ -395,18 +381,26 @@ final class AuthManager: ObservableObject {

func handleCallbackURL(_ url: URL) async throws {
guard let payload = AuthCallbackRouter.callbackPayload(from: url) else {
throw AuthManagerError.invalidCallback
let error = AuthManagerError.invalidCallback
lastSignInError = .authManager(error)
throw error
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}

isLoading = true
defer { isLoading = false }

await tokenStore.seed(
accessToken: payload.accessToken,
refreshToken: payload.refreshToken
)
try await refreshSession()
didCompleteBrowserSignIn = true
do {
await tokenStore.seed(
accessToken: payload.accessToken,
refreshToken: payload.refreshToken
)
try await refreshSession()
didCompleteBrowserSignIn = true
lastSignInError = nil
} catch {
lastSignInError = Self.signInError(from: error)
Comment thread
austinywang marked this conversation as resolved.
Resolved
throw error
}
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
}

func seedTokensFromCLI(refreshToken: String, accessToken: String?) async {
Expand Down Expand Up @@ -434,6 +428,7 @@ final class AuthManager: ObservableObject {
do {
try await refreshSession()
authLog("seedTokensFromCLI: success user=\(currentUser?.primaryEmail ?? "nil")")
lastSignInError = nil
} catch {
authLog("seedTokensFromCLI: refreshSession failed: \(error)")
}
Expand Down Expand Up @@ -505,6 +500,7 @@ final class AuthManager: ObservableObject {
isAuthenticated = true
selectedTeamID = Self.resolveTeamID(selectedTeamID: selectedTeamID, teams: result.teams)
didCompleteBrowserSignIn = true
lastSignInError = nil
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
authLog("applySignInResult: user=\(result.email ?? "nil") teams=\(result.teams.count) teamID=\(selectedTeamID ?? "nil")")
}

Expand Down Expand Up @@ -568,6 +564,7 @@ final class AuthManager: ObservableObject {
availableTeams = teams
isAuthenticated = true
selectedTeamID = Self.resolveTeamID(selectedTeamID: selectedTeamID, teams: teams)
lastSignInError = nil
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
authLog("signInWithCredential: success user=\(user.primaryEmail ?? "nil") teams=\(teams.count) teamID=\(selectedTeamID ?? "nil")")
didCompleteBrowserSignIn = true
}
Expand All @@ -576,6 +573,7 @@ final class AuthManager: ObservableObject {
try? await client.signOut()
await tokenStore.clear()
clearSessionState(clearSelectedTeam: true)
lastSignInError = nil
}

/// Cached access token for fast synchronous reads (no actor hops).
Expand Down
69 changes: 69 additions & 0 deletions Sources/Auth/AuthManagerErrors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import AuthenticationServices
import Foundation
import OSLog

enum AuthManagerError: LocalizedError, Equatable {
case invalidCallback
case missingAccessToken
case missingRefreshToken

var errorDescription: String? {
switch self {
case .invalidCallback:
return String(
localized: "settings.account.error.invalidCallback",
defaultValue: "The sign-in callback was invalid."
)
case .missingAccessToken:
return String(
localized: "settings.account.error.missingAccessToken",
defaultValue: "Account access token is unavailable."
)
case .missingRefreshToken:
return String(
localized: "settings.account.error.missingRefreshToken",
defaultValue: "Account refresh token is unavailable."
)
}
}
}

enum AuthSignInError: Equatable {
case authManager(AuthManagerError)
case message(String)

var localizedMessage: String {
switch self {
case .authManager(let error):
return error.errorDescription ?? Self.genericLocalizedMessage
case .message:
return Self.genericLocalizedMessage
Comment thread
lawrencecchen marked this conversation as resolved.
Resolved
}
Comment thread
austinywang marked this conversation as resolved.
Resolved
}
Comment thread
austinywang marked this conversation as resolved.
Resolved

private static var genericLocalizedMessage: String {
String(
localized: "settings.account.error.signInFailed",
defaultValue: "Sign in failed. Try again."
)
}
}

extension AuthManager {
nonisolated static let authLogger = Logger(
subsystem: Bundle.main.bundleIdentifier ?? AuthKeychainServiceName.stableFallback,
category: "auth"
)

static func signInError(from error: Error) -> AuthSignInError {
if let authError = error as? AuthManagerError {
return .authManager(authError)
}
return .message((error as NSError).localizedDescription)
}

static func shouldSuppressWebAuthError(_ error: NSError) -> Bool {
error.domain == ASWebAuthenticationSessionError.errorDomain
&& error.code == ASWebAuthenticationSessionError.canceledLogin.rawValue
}
}
Loading
Loading