nextjs 15 - Build fails for Next.js Failed to collect page data for apiauth[...nextauth] - Stack Overflow

In my local and development environment everything works fine. But when npm run build, the following er

In my local and development environment everything works fine. But when npm run build, the following error shows up.

import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import axios from "axios";

const authOptions = {
  providers: [
    CredentialsProvider({
      name: "Credentials",
      credentials: {
        phone: { label: "Phone", type: "text" },
        password: { label: "Password", type: "password" },
      },
      async authorize(credentials) {
        try {
          // Call your external login endpoint
          const response = await axios.post(
            process.env.NEXT_PUBLIC_API_BASE_URL + "/login",
            {
              payload: {
                username: credentials.phone,
                password: credentials.password,
              },
            }
          );
          // If login is successful, return the user object
          if (response.data) {
            return response.data;
          }
          return null;
        } catch (error) {
          console.error(
            "Error during login:",
            error.response?.data || error.message
          );
          return null;
        }
      },
    }),
  ],
  session: {
    strategy: "jwt",
  },
  callbacks: {
    async jwt({ token, user }) {
      // Merge user data into token on initial sign in
      if (user) token = { ...token, ...user };
      return token;
    },
    async session({ session, token }) {
      // Make token (user data) available in session
      session.user = token;
      return session;
    },
  },
  pages: {
    signIn: "/auth/login", // Custom sign-in page route if desired
    signOut: "/",
  },
};

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };

This is package.json script

 "scripts": {
    "dev": "next dev --turbopack -p 3500",
    "build": "next build --debug",
    "start": "next start",
    "lint": "next lint"
  },

The error in console:

Collecting page data ..TypeError: f is not a function at 17950 (C:\Users\Acer\Desktop....next\server\app\api\auth[...nextauth]\route.js:11:26405) at t (C:\Users\Acer\Desktop....next\server\webpack-runtime.js:1:128) at r (C:\Users\Acer\Desktop....next\server\app\api\auth[...nextauth]\route.js:36:219820)

I tried removing blocks of the [...nextauth]/route.js but it is not working

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744759125a4592063.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信