fixing updating current user log in: but not completely done

This commit is contained in:
talksik
2021-12-19 17:38:33 -08:00
parent 98e43dfde0
commit 4dc7b422e9
4 changed files with 30 additions and 27 deletions
@@ -14,7 +14,7 @@ struct OnboardingTrioView: View {
var body: some View {
VStack {
TabView {
OnboardingTemplateView(imgName: "undraw_through_the_park_lxnl", mainLeadingActText: "Be", mainHighlightedActText: "yourself", mainTrailingActText: "again.", subActText: "No more consuming endless feeds, media, fomo, anxiety...focus on you and be more present.")
OnboardingTemplateView(imgName: "undraw_through_the_park_lxnl", mainLeadingActText: "Be", mainHighlightedActText: "yourself", mainTrailingActText: "again.", subActText: "No more endless feeds, media, fomo, anxiety...focus on you and be more present.")
OnboardingTemplateView(imgName: "undraw_connection_b-38-q", mainLeadingActText: "Be picky about your ", mainHighlightedActText: "inner circle.", mainTrailingActText: "", subActText: "You are who you hang out with. We kept things minimal because less is more...and we care.")
@@ -24,19 +24,24 @@ final class PhoneVerificationViewModel : ObservableObject {
// TODO: set all in a transaction or batch write
// get user - 1 result set cost
var user = firestoreService.getUser(userId: userId)
print("user that was received from get: \(user?.id)")
if user == nil {// if empty, create user - 1 result set cost..prolly higher cost
print("creating new user with id: \(userId)")
let newUser = User(id: userId, phoneNumber: phoneNumber)
print("verify the id stayed the same: \(newUser.id)")
firestoreService.createUser(user: newUser)
} else { // if not, change last logged in value
// assign to nil so that server can fill it in
user!.lastLoggedInTimestamp = nil
self.firestoreService.getUser(userId: userId) {[weak self] resultingUser in
print("user that was received from get: \(resultingUser?.id)")
let _ = firestoreService.updateUser(user: user!)
if resultingUser == nil {// if empty, create user - 1 result set cost..prolly higher cost
print("creating new user with id: \(userId)")
let newUser = User(id: userId, phoneNumber: phoneNumber)
print("verify the id stayed the same: \(newUser.id)")
self?.firestoreService.createUser(user: newUser)
} else { // if not, change last logged in value
var user = resultingUser
// assign to nil so that server can fill it in
user!.lastLoggedInTimestamp = nil
let res = self?.firestoreService.updateUser(user: user!)
print(res)
}
}
}
}