How to use retrieveInfoForUser to get user metadata?


#1

I’m trying to get metadata, ProviderId for Realm logged in User. However, I always get null result with ErrorCode.UNKNOWN_ACCOUNT

 val user : SyncUser? = SyncUser.current()

user?.let {
    val result = it.retrieveInfoForUser(user.identity, SyncCredentials.IdentityProvider.USERNAME_PASSWORD)

}

How to use this function properly to get SyncUserInfo? I don’t seem to have any other creds to pass to it, except user.identity id.


#2

This is how to do it in Swift - hopefully you’ll be able to convert the code as it’s pretty similar.

NB: user is the currently logged in user. By default this user only has access to THEIR meta data. Unless the user is an Admin, in which case they can query meta data for any user.

let targetUserName = "[email protected]"

user.retrieveInfo(forUser: targetUserName, identityProvider: .usernamePassword, completion: { (userInfo, error) in
                                if let userInfo = userInfo {
                                    print("SUCCESS")
                                    print(userInfo.metadata)
                                }
                                
                                if let error = error {
                                    print("ERROR")
                                    print(error)
                                }
                            })

Good luck!