From 1402f09ac0d5bf1c2b9594766ffd3b363f280735 Mon Sep 17 00:00:00 2001 From: Ben Myers Date: Fri, 11 Feb 2022 15:17:20 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=97=91=20Fix=20user=20deletion=20method?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- Sources/EasyFirebase/Services/Auth/EasyUser.swift | 5 +++-- Sources/EasyFirebase/Services/Firestore/Removal.swift | 3 ++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index db17119..3bfd2dd 100644 --- a/README.md +++ b/README.md @@ -287,7 +287,7 @@ user.updateDisplayName(to: "New_DisplayName", ofUserType: MyUser.self, completio // Update the current user's password user.updatePassword(to: "newPassword", completion: { error in }) // Delete the current user -user.delete(completion: { error in }) +user.delete(ofUserType: MyUser.self, completion: { error in }) ``` ## 📦 Storage Feature Showcase diff --git a/Sources/EasyFirebase/Services/Auth/EasyUser.swift b/Sources/EasyFirebase/Services/Auth/EasyUser.swift index eea7331..1df6c60 100644 --- a/Sources/EasyFirebase/Services/Auth/EasyUser.swift +++ b/Sources/EasyFirebase/Services/Auth/EasyUser.swift @@ -355,14 +355,15 @@ public extension EasyUser { ⚠️ **Warning!** This method will *not* ask for confirmation. Implement that within your app! + - parameter type: The type of the user - parameter completion: The completion handler */ - func delete(completion: @escaping (Error?) -> Void = { _ in }) { + func delete(ofUserType type: T.Type, completion: @escaping (Error?) -> Void = { _ in }) where T: EasyUser { guard assertAuthMatches() else { return } if let authUser = authUser { authUser.delete { error in completion(error) - // TODO: Delete the user object in Firestore. + EasyFirestore.Removal.remove(id: self.id, ofType: T.self, completion: completion) } } } diff --git a/Sources/EasyFirebase/Services/Firestore/Removal.swift b/Sources/EasyFirebase/Services/Firestore/Removal.swift index 11bea43..c8b1449 100644 --- a/Sources/EasyFirebase/Services/Firestore/Removal.swift +++ b/Sources/EasyFirebase/Services/Firestore/Removal.swift @@ -30,7 +30,8 @@ extension EasyFirestore { - parameter completion: The completion handler. */ public static func remove(id: DocumentID, ofType type: T.Type, completion: @escaping (Error?) -> Void = { _ in }) where T: Document { - db.collection(colName(of: T.self)).document(id).delete { error in + let collectionName = String(describing: T.self) + db.collection(collectionName).document(id).delete { error in completion(error) } }