I am trying to add the delete user functionality for iOS app as this is requirement for App Store approval.
I am crashing when I make the delete call, which succeeds in deleting the user. Code for delete below:
private func delete(user: User) async {
do {
try await user.delete()
print("Successfully deleted user")
} catch {
print("Failed to delete user: \(error.localizedDescription)")
self.errorMessage = ErrorMessage(errorText: error.localizedDescription)
}
}
The output of the console for crash:
Successfully deleted user
libc++abi: terminating due to uncaught exception of type realm::app::AppError: Cannot start a sync session for user ‘6627f075da767128555c229c’ because this user has been removed.
The calling code to delete is:
Button(action: {
guard let user = realmApp.currentUser else { return }
let subscriptions = realm.subscriptions
subscriptions.update {
subscriptions.removeAll()
}
Task {
await delete(user: user)
}
}) {
Text("Delete Account")
}
Not that I unsubscribe for any updates I’m currently receiving though I don’t know if that is needed.
I suspect this has something to do with deleting the user I am logged in as? But if I log the user out first before deleting him/here the delete function fails since I need to be logged in to make that call.
Is there anything I’m missing here or that I should check? This is one of the final pieces I need to complete before submitting to Apple. I have searched here and stack overflow, but could not find anything helpful.