-
-
Notifications
You must be signed in to change notification settings - Fork 69
User.current not returning all variables #37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Are you setting those custom keys from either the CloudCode or the Dashboard? If so, you need to fetch the data from your server because your local user doesn't have it and has no way to know it's been updated. What happens when you try?: let updatedUser = try User.current?.fetch()
print(updatedUser.emailVerified)
print(updatedUser.userId) If you are saving these custom values from the device itself and not seeing the values after, something else is going on. I don't see this being the case because this works in playgrounds Parse-Swift/ParseSwift.playground/Pages/4 - User - Continued.xcplaygroundpage/Contents.swift Lines 10 to 41 in e2dde15
Also, make sure you have the latest version of Parse-Swift, there was recently (12/17/20) a fix to fetch. |
Update, I need to look into fetch on the current user, but I suspect you are changing the custom keys from the server as I mentioned above. In order to get that info and save it to your current user you can do the following: var findUser = User.query()
findUser.where("objectId" == User.current!.objectId!) //Force unwrapping to be concise, but you should guard agains these
findUser.first(callbackQueue: .main) {
result in
switch result {
case .success(let updatedUser):
print("Successfully fetched latest user from ParseServer: \(updatedUser)")
User.current = updatedUser
print(User.current!.emailVerified!) //Will contain the latest value from the server
print(User.current!.userId!) //Will contain the latest value from the server
case .failure(let error):
print("Failed to update user: \(error)")
}
} |
After #38 is merged, you will be able to fetch User.current or Installation.current like I mentioned earlier: //Synchronous
let _ = try User.current?.fetch()
print(User.current?.emailVerified)
print(User.current?.userId)
//Asynchronous
User.current?.fetch { result in
switch result {
case .success(_):
print("Successfully fetched updated user from ParseServer: \(User.current!)")
case .failure(let error):
print("Failed to fetch user: \(error)")
}
} |
@cbaker6 I am sorry, I indeed didn't fetch the user. I thought this happend in the background code from ParseSwift. I now tried using your fetch code:
But I guess I need to wait for the merge since this didn't work. |
You should use the query block of code until the merge: var findUser = User.query()
findUser.where("objectId" == User.current!.objectId!) //Force unwrapping to be concise, but you should guard agains these
findUser.first(callbackQueue: .main) {
result in
switch result {
case .success(let updatedUser):
print("Successfully fetched latest user from ParseServer: \(updatedUser)")
User.current = updatedUser
print(User.current!.emailVerified!) //Will contain the latest value from the server
print(User.current!.userId!) //Will contain the latest value from the server
case .failure(let error):
print("Failed to update user: \(error)")
}
} |
The label |
When a user is logged in, and you request a custom key from the user, it returns
nil
even though there is a value for that user in the database.This is my ParseUser structure
This is what I call on launch
This is the log

This is an example of 3 users in Parse database

The text was updated successfully, but these errors were encountered: