Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ extension AuthenticateWithAppleDialog: ASAuthorizationControllerDelegate {

// MARK: - Apple Provider Swift

public class AppleProviderSwift: AuthProviderSwift, DeleteUserSwift {
public class AppleProviderSwift: AuthProviderSwift {
public let scopes: [ASAuthorization.Scope]
let providerId = "apple.com"

Expand All @@ -139,7 +139,7 @@ public class AppleProviderSwift: AuthProviderSwift, DeleteUserSwift {
}

public func deleteUser(user: User) async throws {
let operation = AppleDeleteUserOperation(appleProvider: self)
let operation = ProviderDeleteUserOperation(provider: self)
try await operation(on: user)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ protocol EmailPasswordOperationReauthentication {
}

extension EmailPasswordOperationReauthentication {
// TODO: - @MainActor because User is non-sendable. Might change this once User is sendable in firebase-ios-sdk
@MainActor func reauthenticate() async throws {
guard let user = Auth.auth().currentUser else {
throw AuthServiceError.reauthenticationRequired("No user currently signed-in")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public protocol AuthenticatedOperation {

public extension AuthenticatedOperation {
func callAsFunction(on _: User,
_ performOperation: () async throws -> Void) async throws {
_ performOperation: @MainActor () async throws -> Void) async throws {
do {
try await performOperation()
} catch let error as NSError where error.requiresReauthentication {
Expand All @@ -45,3 +45,40 @@ public extension AuthenticatedOperation {
}
}
}

public protocol ProviderOperationReauthentication {
var authProvider: AuthProviderSwift { get }
}

public extension ProviderOperationReauthentication {
@MainActor func reauthenticate() async throws {
guard let user = Auth.auth().currentUser else {
throw AuthServiceError.reauthenticationRequired("No user currently signed-in")
}

do {
let credential = try await authProvider.createAuthCredential()
try await user.reauthenticate(with: credential)
} catch {
throw AuthServiceError.signInFailed(underlying: error)
}
}
}

@MainActor
public class ProviderDeleteUserOperation<Provider: AuthProviderSwift>: AuthenticatedOperation,
@preconcurrency ProviderOperationReauthentication {
let provider: Provider

public var authProvider: AuthProviderSwift { provider }

public init(provider: Provider) {
self.provider = provider
}

public func callAsFunction(on user: User) async throws {
try await callAsFunction(on: user) {
try await user.delete()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import SwiftUI

public protocol AuthProviderSwift {
@MainActor func createAuthCredential() async throws -> AuthCredential
@MainActor func deleteUser(user: User) async throws
}

public protocol AuthProviderUI {
Expand All @@ -25,10 +26,6 @@ public protocol AuthProviderUI {
var provider: AuthProviderSwift { get }
}

public protocol DeleteUserSwift {
@MainActor func deleteUser(user: User) async throws
}

public protocol PhoneAuthProviderSwift: AuthProviderSwift {
@MainActor func verifyPhoneNumber(phoneNumber: String) async throws -> String
}
Expand Down Expand Up @@ -282,13 +279,12 @@ public extension AuthService {
let operation = EmailPasswordDeleteUserOperation(passwordPrompt: passwordPrompt)
try await operation(on: user)
} else {
// Find provider by matching ID and ensure it can delete users
guard let matchingProvider = providers.first(where: { $0.id == providerId }),
let provider = matchingProvider.provider as? DeleteUserSwift else {
// Find provider by matching ID
guard let matchingProvider = providers.first(where: { $0.id == providerId }) else {
throw AuthServiceError.providerNotFound("No provider found for \(providerId)")
}

try await provider.deleteUser(user: user)
try await matchingProvider.provider.deleteUser(user: user)
}
}
} catch {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import FirebaseAuth
import FirebaseAuthSwiftUI
import SwiftUI

public class FacebookProviderSwift: AuthProviderSwift, DeleteUserSwift {
public class FacebookProviderSwift: AuthProviderSwift {
let scopes: [String]
let providerId = "facebook.com"
private let loginManager = LoginManager()
Expand Down Expand Up @@ -118,7 +118,7 @@ public class FacebookProviderSwift: AuthProviderSwift, DeleteUserSwift {
}

public func deleteUser(user: User) async throws {
let operation = FacebookDeleteUserOperation(facebookProvider: self)
let operation = ProviderDeleteUserOperation(provider: self)
try await operation(on: user)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import GoogleSignIn
import GoogleSignInSwift
import SwiftUI

public class GoogleProviderSwift: AuthProviderSwift, DeleteUserSwift {
public class GoogleProviderSwift: AuthProviderSwift {
let scopes: [String]
let clientID: String
let providerId = "google.com"
Expand Down Expand Up @@ -70,7 +70,7 @@ public class GoogleProviderSwift: AuthProviderSwift, DeleteUserSwift {
}

public func deleteUser(user: User) async throws {
let operation = GoogleDeleteUserOperation(googleProvider: self)
let operation = ProviderDeleteUserOperation(provider: self)
try await operation(on: user)
}
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import FirebaseCore
import SwiftUI

/// Configuration for a generic OAuth provider
public class OAuthProviderSwift: AuthProviderSwift, DeleteUserSwift {
public class OAuthProviderSwift: AuthProviderSwift {
public let providerId: String
public let scopes: [String]
public let customParameters: [String: String]
Expand Down Expand Up @@ -115,7 +115,7 @@ public class OAuthProviderSwift: AuthProviderSwift, DeleteUserSwift {
}

public func deleteUser(user: User) async throws {
let operation = OAuthDeleteUserOperation(oauthProvider: self)
let operation = ProviderDeleteUserOperation(provider: self)
try await operation(on: user)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,16 @@ public class PhoneProviderSwift: PhoneAuthProviderSwift {
presentingViewController.present(hostingController, animated: true)
}
}

public func deleteUser(user: User) async throws {
let operation = ProviderDeleteUserOperation(provider: self)
try await operation(on: user)
}
}

public class PhoneAuthProviderAuthUI: AuthProviderUI {
public var provider: AuthProviderSwift
public let id: String = "phone.com"
public let id: String = "phone"

public init(provider: PhoneAuthProviderSwift? = nil) {
self.provider = provider ?? PhoneProviderSwift()
Expand Down
Loading
Loading