So, I’m trying to add an existing user to an existing role but I keep getting the Invalid session token error. I am using the master key for it though which is weird as I expected it to work.
Here is what I’m currently doing:
const roleQuery = new Moralis.Query(Moralis.Role);
roleQuery.equalTo("name", "testrole");
const role = await roleQuery.first({ useMasterKey: true });
const existingUserQuery = new Moralis.Query(Moralis.User);
existingUserQuery.equalTo("username", "testuser");
const existingUser = await existingUserQuery.first({ useMasterKey: true });
if (existingUser !== undefined) {
role?.getUsers().add(existingUser);
await role?.save(); // Also tried with save({useMasterKey: true}) but that didn't help.
}
When I log the role and user objects I see that it found them so I know it’s there and the master key worked otherwise I would not be able to see them.
Any idea what is going wrong here?