[SOLVED] Update User by Id

Hello,

It’s possible to update user by id in moralis (not user connected) ?!

I think that you can do that only if you use master key, you can do that in a cloud function.

I already used this func but is not working

Moralis.Cloud.define(“updateUserById”, async (request) => {
const query = new Moralis.Query(“User”);
query.equalTo(“objectId”, request.params.selectedUser);
const user = await query.find({ useMasterKey: true });
user.set(“role”, request.params.role);
const result= await user.save()
return result;
});

There is a syntax for save that uses master key, you can find the syntax in documentation

1 Like

HI @aaron
Can you check through console.log whether you are getting the right ID or not?

Thank you guys i follow this solution [SOLVED] Can not update user attribute
and it works !