fix
This commit is contained in:
@@ -12,7 +12,7 @@ final class AuthService: NSObject {
|
||||
super.init()
|
||||
}
|
||||
|
||||
func login(presentationAnchor: ASPresentationAnchor) async throws {
|
||||
func login(presentationAnchor: ASPresentationAnchor?) async throws {
|
||||
self.presentationAnchor = presentationAnchor
|
||||
|
||||
let codeVerifier = generateCodeVerifier()
|
||||
@@ -79,7 +79,7 @@ final class AuthService: NSObject {
|
||||
|
||||
self.authSession = webAuthSession
|
||||
|
||||
webAuthSession.start { started in
|
||||
let started = webAuthSession.start()
|
||||
if !started {
|
||||
DispatchQueue.main.async {
|
||||
NotificationCenter.default.post(
|
||||
@@ -90,7 +90,6 @@ final class AuthService: NSObject {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func handleCallback(url: URL, session: String) {
|
||||
guard let components = URLComponents(url: url, resolvingAgainstBaseURL: true),
|
||||
|
||||
@@ -55,6 +55,12 @@ struct LoginView: View {
|
||||
.onReceive(NotificationCenter.default.publisher(for: .authCallbackReceived)) { notification in
|
||||
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() {
|
||||
@@ -62,21 +68,12 @@ struct LoginView: View {
|
||||
errorMessage = nil
|
||||
|
||||
Task {
|
||||
do {
|
||||
let authService = AuthService.shared
|
||||
await authService.login(presentationAnchor: nil as! ASPresentationAnchor)
|
||||
} catch {
|
||||
await MainActor.run {
|
||||
isLoading = false
|
||||
errorMessage = error.localizedDescription
|
||||
}
|
||||
}
|
||||
await authService.login(presentationAnchor: nil)
|
||||
}
|
||||
}
|
||||
|
||||
private func handleAuthCallback(_ userInfo: [AnyHashable: Any]?) {
|
||||
// Handle OAuth callback
|
||||
// In practice, this would exchange the code for tokens
|
||||
Task {
|
||||
await authManager.checkAuthState()
|
||||
await MainActor.run {
|
||||
|
||||
Reference in New Issue
Block a user