React-moralis with Next.js

Has anyone got the react-moralis package to work with Next.js?

I am trying to do simple authentication and the metamask login does work as expected but after signing you get following response into the console:

RESTController.js:304 POST http://localhost:3000/undefined/users 404 (Not Found)

and the isAuthenticated will not be set correctly.

import React from "react";

import { MoralisProvider } from "react-moralis";

function MyApp({ Component, pageProps }) {

  return (

    <MoralisProvider

      appId={String(process.env.MORALIS_APP_ID)}

      serverUrl={String(process.env.MORALIS_SERVER_URL)}

    >

      <Component {...pageProps} />

    </MoralisProvider>

  );

}

export default MyApp;
import { useMoralis } from "react-moralis";

export default function Login() {

  const { authenticate, isAuthenticated } = useMoralis();

  return (

    <>

      <button onClick={() => authenticate()}>Login here</button>

    </>

  );

}

Not sure if Next.js requires some additional configuration or what could possibly be the solution for this?

1 Like

Anyone having this issueโ€ฆ just make sure your MoralisProvider is actually getting initialized lol.

2 Likes

Thanks alot for the inputs. This is very helpful for other Developers! :raised_hands:

Happy BUIDLing! :slight_smile:

I have the same issue as well it has not initialized the Application and it have some kind of error message when I try to Authenticate and do something else. As follow

Hi @Xenon It doesnโ€™t seem to me like itโ€™s a problem because of Moralis SDK. Please create a new topic and provide us as much information as possible, including your code. Thank you :raised_hands: