nextauthjs / next-auth

Authentication for the Web.
https://authjs.dev
ISC License
24.85k stars 3.51k forks source link

Error: `export const config` in C:\Users\Xolify\Documents\GitHub\confidentialclo\app/api/auth/login/route.ts is deprecated. Please change `runtime` property to segment export config. See https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config #8443

Closed XolifyDev closed 1 year ago

XolifyDev commented 1 year ago

Environment

From what I see this problem is only happening because of NextAuth. I have asked around and I have seen no one has this problem

/app/api/auth/[...nextauth].ts

import NextAuth, { AuthOptions, NextAuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google";
import DiscordProvider from "next-auth/providers/discord";
import { PrismaClient } from "@prisma/client";
import { config as config1 } from "@/config";
import Credentials from "next-auth/providers/credentials";
import bcrypt from "bcrypt";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { prisma } from "@/lib/db";

const handler = NextAuth({
  adapter: PrismaAdapter(prisma),
  providers: [
    // GoogleProvider({
    //   clientId: process.env.GOOGLE_CLIENT_ID,
    //   clientSecret: process.env.GOOGLE_CLIENT_SECRET,
    // }),
    Credentials({
      name: "credentials",
      credentials: {
        email: { label: "email", type: "text" },
        password: { label: "password", type: "password" },
      },
      async authorize(credentials) {
        if (!credentials?.email || !credentials?.password) {
          throw new Error("Invalid credentials");
        }

        const user = await prisma.user.findUnique({
          where: {
            email: credentials.email,
          },
        });

        if (!user || !user?.hashedPassword) {
          throw new Error("Invalid credentials");
        }

        const isCorrectPassword = await bcrypt.compare(
          credentials.password,
          user.hashedPassword
        );

        if (!isCorrectPassword) {
          throw new Error("Invalid credentials");
        }

        return user;
      },
    }),

    GoogleProvider({
      clientId: config1.google.clientId,
      clientSecret: config1.google.clientSecret,
    }),
  ],
  //   debug: process.env.NODE_ENV === "development",
  session: {
    strategy: "jwt",
  },
  callbacks: {
    session: async ({ session, token }) => {
      if (session?.user) {
        session.user.id = token.uid;
      }
      return session;
    },
    jwt: async ({ user, token }) => {
      if (user) {
        token.uid = user.id;
      }
      return token;
    },
    async signIn({ account, profile }) {
      console.log(account, profile, "ACCOUNT PROFILE");

      return true; // Do different verification for other providers that don't have `email_verified`
    },
  },
  pages: {
    signIn: "/login",
  },
  secret: "awdawd12312asdawd",
});

export { handler as GET, handler as POST };
export default handler;

Please help.

This project is for a customer and it is due in the next 2 days.

Reproduction URL

--no-link--

Describe the issue

When running npm run build it gives me this error

> Build error occurred
Error: `export const config` in C:\Users\Xolify\Documents\GitHub\confidentialclo\app/api/auth/login/route.ts is deprecated. Please change `runtime` property to segment export config. See https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config
    at getPageStaticInfo (C:\Users\Xolify\Documents\GitHub\confidentialclo\node_modules\next\dist\build\analysis\get-page-static-info.js:365:27)
    at async getStaticInfoIncludingLayouts (C:\Users\Xolify\Documents\GitHub\confidentialclo\node_modules\next\dist\build\entries.js:81:28)
    at async C:\Users\Xolify\Documents\GitHub\confidentialclo\node_modules\next\dist\build\entries.js:362:32
    at async Promise.all (index 2)
    at async Promise.all (index 0)
    at async createEntrypoints (C:\Users\Xolify\Documents\GitHub\confidentialclo\node_modules\next\dist\build\entries.js:482:5)
    at async Span.traceAsyncFn (C:\Users\Xolify\Documents\GitHub\confidentialclo\node_modules\next\dist\trace\trace.js:103:20)
    at async webpackBuildImpl (C:\Users\Xolify\Documents\GitHub\confidentialclo\node_modules\next\dist\build\webpack-build\impl.js:102:25)
    at async webpackBuild (C:\Users\Xolify\Documents\GitHub\confidentialclo\node_modules\next\dist\build\webpack-build\index.js:137:16)
    at async C:\Users\Xolify\Documents\GitHub\confidentialclo\node_modules\next\dist\build\index.js:586:123
- info Creating an optimized production build .

I do not know how to fix this problem.

How to reproduce

npm run build.

Expected behavior

npm run build should run like normal.

balazsorban44 commented 1 year ago

This is unrelated to NextAuth.js. I see you already opened an issue at https://github.com/vercel/next.js/issues/54697

XolifyDev commented 1 year ago

But I think it’s related to next auth as I have another api route and that’s not erroring…

XolifyDev commented 1 year ago

This issue is related to next auth not nextjs please help