Skip to content

Commit

Permalink
implement User.delete (#68)
Browse files Browse the repository at this point in the history
Modeled after `User.reload`.
  • Loading branch information
darinf authored Jun 4, 2024
1 parent 5579b7c commit 9e5eb07
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
26 changes: 24 additions & 2 deletions Sources/FirebaseAuth/FirebaseUser+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,33 @@ public final class User {
// }

public func delete(completion: ((Error?) -> Void)?) {
fatalError("\(#function) not yet implemented")
deleteImpl() { error in
if let completion {
DispatchQueue.main.async {
completion(error)
}
}
}
}

public func delete() async throws {
fatalError("\(#function) not yet implemented")
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) in
deleteImpl() { error in
if let error {
continuation.resume(throwing: error)
} else {
continuation.resume()
}
}
}
}

private func deleteImpl(completion: @escaping (Error?) -> Void) {
let future = swift_firebase.swift_cxx_shims.firebase.auth.user_delete(impl)
future.setCompletion({
let (_, error) = future.resultAndError { AuthErrorCode($0) }
completion(error)
})
}

public func sendEmailVerification(beforeUpdatingEmail email: String) async throws {
Expand Down
6 changes: 6 additions & 0 deletions Sources/firebase/include/FirebaseAuth.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ user_reload(::firebase::auth::User user) {
user.Reload());
}

inline ::swift_firebase::swift_cxx_shims::firebase::VoidFuture
user_delete(::firebase::auth::User user) {
return ::swift_firebase::swift_cxx_shims::firebase::VoidFuture::From(
user.Delete());
}

inline ::swift_firebase::swift_cxx_shims::firebase::Future<
::firebase::auth::AuthResult>
user_reauthenticate_and_retrieve_data(
Expand Down

0 comments on commit 9e5eb07

Please sign in to comment.