fixing it by just using setdata instead of worrying about add document
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
import Firebase
|
||||
import FirebaseFirestore
|
||||
import FirebaseFirestoreSwift
|
||||
|
||||
struct User: Identifiable, Codable {
|
||||
|
||||
@@ -75,7 +75,7 @@ class FirestoreService {
|
||||
|
||||
func createUser(user: User, completion: @escaping((_ state: ServiceState) -> ())) {
|
||||
do {
|
||||
let _ = try db.collection(Collection.users.rawValue).addDocument(from: user)
|
||||
let _ = try db.collection(Collection.users.rawValue).document(user.id!).setData(from: user)
|
||||
|
||||
completion(ServiceState.success("user created"))
|
||||
} catch {
|
||||
|
||||
@@ -106,7 +106,7 @@ struct AddBasicInfoView: View {
|
||||
Button {
|
||||
var updatedUser = self.authSessionStore.user
|
||||
updatedUser?.avatar = Avatars.avatarSystemNames[self.selectedAvatarIndex]
|
||||
updatedUser?.nickname = self.nickname
|
||||
updatedUser?.nickname = self.nickname
|
||||
|
||||
print("attempting to save information \(updatedUser)")
|
||||
|
||||
@@ -114,7 +114,7 @@ struct AddBasicInfoView: View {
|
||||
self.addInfoViewModel.updateUser(currUser: updatedUser!) {
|
||||
self.navigationStack.push(InnerCircleView())
|
||||
}
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Text("Save")
|
||||
.fontWeight(.heavy)
|
||||
|
||||
@@ -27,11 +27,13 @@ final class PhoneVerificationViewModel : ObservableObject {
|
||||
self.firestoreService.getUser(userId: userId) {[weak self] resultingUser in
|
||||
print("user that was received from get: \(resultingUser?.id)")
|
||||
|
||||
if resultingUser == nil {// if empty, create user - 1 result set cost..prolly higher cost
|
||||
print("creating new user with id: \(userId)")
|
||||
if resultingUser == nil {// if empty, create user
|
||||
let newUser = User(id: userId, phoneNumber: phoneNumber)
|
||||
print("verify the id stayed the same: \(newUser.id)")
|
||||
|
||||
print("creating new user with this object: \(newUser)")
|
||||
|
||||
self?.firestoreService.createUser(user: newUser) { res in
|
||||
print(res)
|
||||
completion(res)
|
||||
}
|
||||
} else { // if not, change last logged in value
|
||||
|
||||
Reference in New Issue
Block a user