Search code examples
typescriptvercelnext.js13next-auth

authOptions is not a valid Route export field


Here is my authOptions code which is running perfectly on localhost.

import NextAuth, { NextAuthOptions } from "next-auth";
import GoogleProvider from "next-auth/providers/google";

export const authOptions: NextAuthOptions = {
  providers: [
    GoogleProvider({
      clientId: process.env.GOOGLE_CLIENT_ID as string,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
    }),
  ],
  pages: {
    signIn: "/signin",
  },
};

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };

The problem that I'm facing while deploying my project on vercel is: enter image description here


Solution

  • Please use it like below in app/api/auth/[...nextauth]/route.js

    import NextAuth from 'next-auth'
    import authOptions from '../../../../lib/configs/auth/authOptions'
    
    const handler = NextAuth(authOptions)
    
    export { handler as GET, handler as POST }