getServerSideProps with next.js and Moralis DB

I have created a NEXT.js app calling from pages/api to get the data from moralisDB.
this is my code on api/index.js

import {Moralis} from 'moralis/node'

export default async function handler(req, res) {
    const {method} = req;
    const serverUrl = process.env.NEXT_PUBLIC_SERVER_URL;
    const appId = process.env.NEXT_PUBLIC_APP_ID;
    const moralisSecret = process.env.NEXT_MORALIS_SECRET;
    // Initialize Moralis Server side
    await Moralis.start({ serverUrl, appId, moralisSecret });
    // offer collection
    const tbOffer = Moralis.Object.extend(process.env.NEXT_OFFER_COLLECTION_NAME);
    if (method ==='GET'){

            const query = new Moralis.Query(tbOffer);
            const allOffers = await query.find();
        } catch (err){

I keep getting error response 500 with the response: Could not fetch keys with moralisSecret
It was working fine for a couple of days, and now it stopped.
I will appreciate any advice.


Try running the code without try-catch syntax.
I am guessing the error is in this line.
const query = new Moralis.Query(tbOffer);

Try to add console.log(tbOffer) and check if the data is present.

did you change anything since it was working? can you check that you have the expected moralisSecret?

Hi There,

I have exact the same problem…
The code was running fine, but since a couple days it stopped working…

My code looks like this:

            await Moralis.start({
                serverUrl: serverUrl,
                appId: appId,
                masterKey: masterKey,
                moralisSecret: moralisSecret

            await Moralis.enableWeb3({
                rpc: {
                    80001: '',
                    137: ''
                chainId: 137,
                privateKey: walletPrvKey

Hello can you please edit out your node ids.

Are you getting the Could not fetch keys with moralisSecret error? Also I don’t think you need masterKey if you’re using moralisSecret.