This commit is contained in:
2026-02-18 21:53:01 +01:00
parent 4c0d8be018
commit 2534011506
2 changed files with 17 additions and 21 deletions

View File

@@ -12,7 +12,7 @@ final class AuthService: NSObject {
super.init() super.init()
} }
func login(presentationAnchor: ASPresentationAnchor) async throws { func login(presentationAnchor: ASPresentationAnchor?) async throws {
self.presentationAnchor = presentationAnchor self.presentationAnchor = presentationAnchor
let codeVerifier = generateCodeVerifier() let codeVerifier = generateCodeVerifier()
@@ -79,7 +79,7 @@ final class AuthService: NSObject {
self.authSession = webAuthSession self.authSession = webAuthSession
webAuthSession.start { started in let started = webAuthSession.start()
if !started { if !started {
DispatchQueue.main.async { DispatchQueue.main.async {
NotificationCenter.default.post( NotificationCenter.default.post(
@@ -90,7 +90,6 @@ final class AuthService: NSObject {
} }
} }
} }
}
private func handleCallback(url: URL, session: String) { private func handleCallback(url: URL, session: String) {
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true), guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true),

View File

@@ -55,6 +55,12 @@ struct LoginView: View {
.onReceive(NotificationCenter.default.publisher(for: .authCallbackReceived)) { notification in .onReceive(NotificationCenter.default.publisher(for: .authCallbackReceived)) { notification in
handleAuthCallback(notification.userInfo) handleAuthCallback(notification.userInfo)
} }
.onReceive(NotificationCenter.default.publisher(for: .authError)) { notification in
if let authError = notification.userInfo?["error"] as? AuthError {
isLoading = false
errorMessage = authError.errorDescription
}
}
} }
private func login() { private func login() {
@@ -62,21 +68,12 @@ struct LoginView: View {
errorMessage = nil errorMessage = nil
Task { Task {
do {
let authService = AuthService.shared let authService = AuthService.shared
await authService.login(presentationAnchor: nil as! ASPresentationAnchor) await authService.login(presentationAnchor: nil)
} catch {
await MainActor.run {
isLoading = false
errorMessage = error.localizedDescription
}
}
} }
} }
private func handleAuthCallback(_ userInfo: [AnyHashable: Any]?) { private func handleAuthCallback(_ userInfo: [AnyHashable: Any]?) {
// Handle OAuth callback
// In practice, this would exchange the code for tokens
Task { Task {
await authManager.checkAuthState() await authManager.checkAuthState()
await MainActor.run { await MainActor.run {