简体   繁体   中英

How to query Moralis roles with React?

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

You need to specify Moralis.Role and to add userMasterKey

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM