Skip to content

Commit 5b52c77

Browse files
darinfcompnerd
authored andcommitted
implement User.delete (#68)
Modeled after `User.reload`.
1 parent 3c9de83 commit 5b52c77

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Sources/FirebaseAuth/FirebaseUser+Swift.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,33 @@ public final class User {
235235
// }
236236

237237
public func delete(completion: ((Error?) -> Void)?) {
238-
fatalError("\(#function) not yet implemented")
238+
deleteImpl() { error in
239+
if let completion {
240+
DispatchQueue.main.async {
241+
completion(error)
242+
}
243+
}
244+
}
239245
}
240246

241247
public func delete() async throws {
242-
fatalError("\(#function) not yet implemented")
248+
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, any Error>) in
249+
deleteImpl() { error in
250+
if let error {
251+
continuation.resume(throwing: error)
252+
} else {
253+
continuation.resume()
254+
}
255+
}
256+
}
257+
}
258+
259+
private func deleteImpl(completion: @escaping (Error?) -> Void) {
260+
let future = swift_firebase.swift_cxx_shims.firebase.auth.user_delete(impl)
261+
future.setCompletion({
262+
let (_, error) = future.resultAndError { AuthErrorCode($0) }
263+
completion(error)
264+
})
243265
}
244266

245267
public func sendEmailVerification(beforeUpdatingEmail email: String) async throws {

Sources/firebase/include/FirebaseAuth.hh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ user_reload(::firebase::auth::User user) {
5252
user.Reload());
5353
}
5454

55+
inline ::swift_firebase::swift_cxx_shims::firebase::VoidFuture
56+
user_delete(::firebase::auth::User user) {
57+
return ::swift_firebase::swift_cxx_shims::firebase::VoidFuture::From(
58+
user.Delete());
59+
}
60+
5561
inline ::swift_firebase::swift_cxx_shims::firebase::Future<
5662
::firebase::auth::AuthResult>
5763
user_reauthenticate_and_retrieve_data(

0 commit comments

Comments
 (0)