fixing updating current user log in: but not completely done
This commit is contained in:
@@ -18,20 +18,18 @@ class FirestoreService {
|
||||
|
||||
private var db = Firestore.firestore()
|
||||
|
||||
func getUser(userId: String) -> User? {
|
||||
func getUser(userId: String, completion: @escaping((_ user: User?) -> ())) {
|
||||
let docRef = db.collection(Collection.users.rawValue).document(userId)
|
||||
|
||||
var user:User? = nil
|
||||
|
||||
docRef.getDocument { (document, error) in
|
||||
if let document = document, document.exists {
|
||||
user = try? document.data(as: User.self)
|
||||
let returnedUser = try? document.data(as: User.self)
|
||||
completion(returnedUser)
|
||||
} else {
|
||||
user = nil
|
||||
print("user doesn't exist")
|
||||
completion(nil)
|
||||
}
|
||||
}
|
||||
|
||||
return user
|
||||
}
|
||||
|
||||
func createUser(user: User) {
|
||||
|
||||
@@ -143,13 +143,13 @@ final class AuthSessionStore: ObservableObject, SessionStore {
|
||||
}
|
||||
|
||||
private func getAndSetEnvironmentUserDetails(userId: String) {
|
||||
let firestoreUser: User? = self.firestoreService.getUser(userId: userId)
|
||||
|
||||
// if we get a user back, then set this to our instance to allow UI to get published with all user details
|
||||
if firestoreUser != nil {
|
||||
// TODO: prolly useless since we never set up a background thread for the rest of this code before
|
||||
DispatchQueue.main.async {
|
||||
self.user = firestoreUser
|
||||
self.firestoreService.getUser(userId: userId) {firestoreUser in
|
||||
// if we get a user back, then set this to our instance to allow UI to get published with all user details
|
||||
if firestoreUser != nil {
|
||||
// TODO: prolly useless since we never set up a background thread for the rest of this code before
|
||||
DispatchQueue.main.async {
|
||||
self.user = firestoreUser
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user