Skip to content

Commit

Permalink
Added functionality for creating a document in Firestore with every n…
Browse files Browse the repository at this point in the history
…ew user signup (#27)

Co-authored-by: Caitlin Kunchur <[email protected]>
  • Loading branch information
ananya-vasireddy and ckunchur authored Mar 12, 2023
1 parent 031a50e commit 4994d86
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import Account
import class FHIR.FHIR
import FirebaseAccount
import FirebaseAuth
import FirebaseFirestore
import Onboarding
import SwiftUI

Expand Down Expand Up @@ -42,6 +44,19 @@ struct AccountSetup: View {
.onReceive(account.objectWillChange) {
if account.signedIn {
onboardingSteps.append(.healthKitPermissions)

if let user = Auth.auth().currentUser {
let uid = user.uid
let name = user.displayName?.components(separatedBy: " ")
let firstName = name?[0] ?? ""
let lastName = name?[1] ?? ""
let data: [String: Any] = ["firstName": firstName, "id": uid, "lastName": lastName]
Firestore.firestore().collection("users").document(uid).setData(data) { err in
if let err = err {
print("Error updating document: \(err)")
}
}
}
// Unfortunately, SwiftUI currently animates changes in the navigation path that do not change
// the current top view. Therefore we need to do the following async procedure to remove the
// `.login` and `.signUp` steps while disabling the animations before and re-enabling them
Expand Down

0 comments on commit 4994d86

Please sign in to comment.