Package path ./providers/credentials is not exported from package

Hi,

I’m using next-auth v5, and it seems that MoralisNextAuthProvider() isn’t being accepted as provider when trying to configure the auth.ts file:

import { MoralisNextAuthProvider } from '@moralisweb3/next'
import { nanoid } from 'nanoid'
import NextAuth from 'next-auth'

export const { handlers, signIn, signOut, auth } = NextAuth({
  providers: [MoralisNextAuthProvider()],
  pages: {
    signIn: '/',
    error: '/404',
    signOut: '/'
  },
  session: {
    strategy: 'jwt'
  },
  callbacks: {
    jwt: async ({ token, user }: any) => {
      user && (token.user = user)

      return token
    },
./node_modules/@moralisweb3/next/lib/auth/MoralisNextAuthProvider.js:55:1

Module not found: Package path ./providers/credentials is not exported from package C:\Users\user\Documents\GitHub\project\node_modules\next-auth (see exports field in C:\Users\user\Documents\GitHub\project\node_modules\next-auth\package.json)

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./node_modules/@moralisweb3/next/lib/auth/index.js
./node_modules/@moralisweb3/next/lib/index.js

Thanks for your help!

Hi @NeckRawfeel

I dont think MoralisNextAuthProvider is meant to be used like that. Are you referring to any documentation for this?

Next auth only accepts certain web2 providers.

Hello @johnversus, @NeckRawfeel

I’m also getting the same error , I was referring to this doc here

Here is the auth.js code

import NextAuth from "next-auth";
import { MoralisNextAuthProvider } from "@moralisweb3/next";

export const { handlers, signIn, signOut, auth } = NextAuth({
  providers: [MoralisNextAuthProvider()],
  callbacks: {
    async jwt({ token, user }) {
      if (user) {
        token.user = user;
      }
      return token;
    },
    async session({ session, token }) {
      session.user = token.user;
      return session;
    },
  },
});

But I’m getting this error when I tried to genereate a message for generating a signature

Here is the code

"use client";
import { useAccount, useConnect, useDisconnect, useSignMessage } from "wagmi";
import { useState } from "react";
import { useAuthRequestChallengeEvm } from "@moralisweb3/next";

export default function App() {
  const { connector: activeConnector, isConnected, address } = useAccount();
  const { connectAsync, connectors, error, isLoading, pendingConnector } =
    useConnect();
  const { disconnectAsync } = useDisconnect();
  const [data, setData] = useState(null);

  const { signMessageAsync } = useSignMessage();
  const { requestChallengeAsync } = useAuthRequestChallengeEvm();

  const handleAuth =
    ({ connector }) =>
    async () => {
      if (isConnected) {
        await disconnectAsync();
      }

      try {
        const userData = await connectAsync({ connector });
        setData(JSON.stringify(userData, null, 2));
        const { accounts, chainId } = userData;

        const { message } = await requestChallengeAsync({
          address: accounts,
          chainId: chainId,
        });

        const signature = await signMessageAsync({ message });

        console.log(signature);
      } catch (error) {
        console.error(error);
      }
    };

  return (
    <>
      {isConnected && <div>Connected to {activeConnector.name}</div>}
      {data && <pre>{data}</pre>}

      {connectors.map((connector) => (
        <button key={connector.id} onClick={handleAuth({ connector })}>
          {connector.name}
          {isLoading &&
            pendingConnector?.id === connector.id &&
            " (connecting)"}
        </button>
      ))}

      {error && <div>{error.message}</div>}
    </>
  );
}

Error Screen Shot Attached Below , can you please help me to resolve this ?

Let me know in case of any calrification .

Hi @rust @NeckRawfeel

I have tried the final code mentioned in the tutorial and it seem to work as expected. All I did it add the .env file with required variables, install the packages and ran the server.

I would recommend you to delete the existing node modules, lock file and try installing the packages using yarn

you folks can just downgrade your next-auth to a <5 version

npm install [email protected]

the one that’s used officialy is 4.10.3