In my nuxt app I am trying to call the aggregate function, but I get this error
âunauthorized: master key is requiredâ
I added masterKey in my Moralis start function
// plugin: moralis.js
import Moralis from "moralis/dist/moralis.min.js";
import {,
MORALIS_APP_ID,
MORALIS_SERVER_URL,
MORALIS_APP_ID_TESTNET,
MORALIS_SERVER_URL_TESTNET,
} from '@/constants/app';
export default async (ctx, inject) => {
let appId = MORALIS_APP_ID_TESTNET;
let serverUrl = MORALIS_SERVER_URL_TESTNET;
if(+ctx.env.app.defaultChainId === 56) {
appId = MORALIS_APP_ID;
serverUrl = MORALIS_SERVER_URL;
}
const masterKey = 'gdgdgdss'
await Moralis.start({ serverUrl, appId, masterKey });
inject("Moralis", Moralis);
};
// store: action
const arbitrageStartQuery = new this.$Moralis.Query("ArbitrageStart");
arbitrageStartQuery.skip(offset * RECORD_COUNT);
arbitrageStartQuery.limit(RECORD_COUNT)
arbitrageStartQuery.descending("block_timestamp")
arbitrageStartQuery.withCount();
const pipeline = [
{
lookup: {
from: "ArbitrageEnd",
localField: "block_number",
foreignField: "block_number",
as: "arbitrageEnd",
},
},
];
const res = await arbitrageStartQuery.aggregate(pipeline, {useMasterKey: true})