How to query Moralis roles with React?

195 views Asked by At

I’m checking out Moralis for the first time today. Saw a few of the tutorials and read the documentation. Currently, I’m trying to query the Roles (_Role) but all I get is an empty array.

const { fetch: getStaffRole } = useMoralisQuery('_Role');

async function Check() {

  const q = new Moralis.Query('_Role');
  const r = await q.first();
  console.log('w functions:', r); //returns undefined

  const r2 = await getStaffRole();
  console.log('w hooks:', r2); //returns Array []

}

Code snippet of the query, Stack doesn't allow me to directly upload the image here.

—> Table permissions, table, & console logs

1

There are 1 answers

0
Giggioz On

You need to specify Moralis.Role and to add userMasterKey

  const result = await new Moralis.Query(Moralis.Role)
  .equalTo("name", 'admin')
  .first({ useMasterKey: true });