From e381b7d0fac1bf94e3257680c9af741e16b67817 Mon Sep 17 00:00:00 2001 From: Paul Schmiedmayer Date: Fri, 26 Jul 2024 15:38:26 -0700 Subject: [PATCH] Avoid Setting Data When No Data is Provided (#40) # Avoid Setting Data when no Data is Provided ## :recycle: Current situation & Problem - SpeziFirebase tries to write a document when no data should be created which can clash with possible security rules not allowing deletion. - No document should be created on updating elements. ## :gear: Release Notes - Avoid Setting Data When No Data is Provided ## :pencil: Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md). --- .../FirestoreAccountStorage.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/SpeziFirebaseAccountStorage/FirestoreAccountStorage.swift b/Sources/SpeziFirebaseAccountStorage/FirestoreAccountStorage.swift index be8c324..852634f 100644 --- a/Sources/SpeziFirebaseAccountStorage/FirestoreAccountStorage.swift +++ b/Sources/SpeziFirebaseAccountStorage/FirestoreAccountStorage.swift @@ -90,6 +90,10 @@ public actor FirestoreAccountStorage: Module, AccountStorageConstraint { do { switch result { case let .success(data): + guard !data.isEmpty else { + return + } + try await userDocument(for: identifier.accountId) .setData(data, merge: true) case let .failure(error): @@ -137,7 +141,7 @@ public actor FirestoreAccountStorage: Module, AccountStorageConstraint { switch result { case let .success(data): try await userDocument(for: identifier.accountId) - .setData(data, merge: true) + .updateData(data) case let .failure(error): throw error }