I have 2 views, one changes the email and the other changes the password.
Everything works as expected with changing the email. ( I update User.current?.email, then User.current?.save.
User.current?.email = self.emailField.trimmingCharacters(in: .whitespaces).lowercased()
User.current?.save { result in
switch result {
case .success(_):
print("Successfully changed email")
User().getAdditionalUserInfo() { result in
switch result {
case .success(let user):
dump(user)
case .failure(let error):
self.isShowingAlert = self.lokalityAlert.alert(type: .error, message: error.message)
}
}
case .failure(let error):
print("Failed to update e-mail: \(error)")
self.isShowingAlert = self.lokalityAlert.alert(type: .error, message: error.message)
User.current?.email = currentVerifiedEmailContainer // return the email address
}
}
dumping user inside the success case of User().getAdditionalUserInfo when I change email works as expected.
However, when I run the same code, only this time, I change the password, dumping user
returns a User object with NIL values.
**_User ({})**
**- objectId: nil**
**- createdAt: nil**
**- updatedAt: nil**
**- ACL: nil**
**- username: nil**
**- email: nil**
**- emailVerified: nil**
**- password: nil**
**- authData: nil**
**- currentVerifiedEmailContainer: nil**
**- userProfile: nil**
**- userSettings: nil**
**- isVerifiedUser: nil**
**- isBanned: nil**
**- isPremiumUser: nil**
**- isFlagged: nil**
**- privacy: nil**
**- tos: nil**
Any idea what’s happening here?
func getAdditionalUserInfo(_ completion: @escaping (Result<User, ParseError>) -> Void) {
User.current?.fetch(includeKeys: ["userProfile"]) { result in
switch result {
case .success(let user):
// We found a match!
print("success getting user profile")
dump(user) // - User Object with nil values if we just changed the Password
completion(.success(user))
case .failure(let error):
// Failed to find match. Let's add it.
if error.code == ParseError.Code.objectNotFound {
// TODO: Create New Profile object here
dump(error)
completion(.failure(error))
} else {
dump(error)
completion(.failure(error))
}
}
}
}
}