Skip to content

Commit

Permalink
🗑 Fix user deletion method
Browse files Browse the repository at this point in the history
  • Loading branch information
benlmyers committed Feb 11, 2022
1 parent 6873381 commit 1402f09
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions Sources/EasyFirebase/Services/Auth/EasyUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(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)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/EasyFirebase/Services/Firestore/Removal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ extension EasyFirestore {
- parameter completion: The completion handler.
*/
public static func remove<T>(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)
}
}
Expand Down

0 comments on commit 1402f09

Please sign in to comment.