Next.js Discord

Discord Forum

Error on api/auth/[...nextauth]/route.ts

Answered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
import NextAuth from "next-auth/next";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import prisma from "@/lib/prisma";
import GoogleProvider from "next-auth/providers/google";
import DiscordProvider from "next-auth/providers/discord"
import { NextAuthOptions } from "next-auth";
export const authOptions: NextAuthOptions = {

  adapter: PrismaAdapter(prisma),
  providers: [
    DiscordProvider({
      clientId: process.env.discord_id as string,
      clientSecret: process.env.discord_secret as string,
    }),
  ],
 callbacks: {
    async session({ session, user }) {
      if (user && session) {
        session.user.id = user.id;
      }
      return session;
    },
  },
};

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST };


C:\Users\hp\Desktop\Tests>next build
   ▲ Next.js 14.1.0
   - Environments: .env

   Creating an optimized production build ...
 ✓ Compiled successfully
   Linting and checking validity of types  ..Pages directory cannot be found at C:\Users\hp\Desktop\Tests\pages or C:\Users\hp\Desktop\Tests\src\pages. If using a custom path, please configure with the `no-html-link-for-pages` rule in your eslint config file.
   Linting and checking validity of types  ..Failed to compile.

.next/types/app/api/auth/[...nextauth]/route.ts:8:13
Type error: Type 'OmitWithTag<typeof import("C:/Users/hp/Desktop/Tests/app/api/auth/[...nextauth]/route"), "POST" | "GET" | "HEAD" | "OPTIONS" | "PUT" | "DELETE" | "PATCH" | "config" | "generateStaticParams" | ... 6 more ... | "maxDuration", "">' does not satisfy the constraint '{ [x: string]: never; }'.
  Property 'authOptions' is incompatible with index signature.
    Type 'AuthOptions' is not assignable to type 'never'.

   6 |
   7 | // Check that the entry is a valid entry
>  8 | checkFields<Diff<{
     |             ^
   9 |   GET?: Function
  10 |   HEAD?: Function
  11 |   OPTIONS?: Function
Answered by joulev
Move authOptions to a different file and import it to the route.ts file
View full answer

1 Reply

@Cape lion js import NextAuth from "next-auth/next"; import { PrismaAdapter } from "@next-auth/prisma-adapter"; import prisma from "@/lib/prisma"; import GoogleProvider from "next-auth/providers/google"; import DiscordProvider from "next-auth/providers/discord" import { NextAuthOptions } from "next-auth"; export const authOptions: NextAuthOptions = { adapter: PrismaAdapter(prisma), providers: [ DiscordProvider({ clientId: process.env.discord_id as string, clientSecret: process.env.discord_secret as string, }), ], callbacks: { async session({ session, user }) { if (user && session) { session.user.id = user.id; } return session; }, }, }; const handler = NextAuth(authOptions); export { handler as GET, handler as POST }; C:\Users\hp\Desktop\Tests>next build ▲ Next.js 14.1.0 - Environments: .env Creating an optimized production build ... ✓ Compiled successfully Linting and checking validity of types ..Pages directory cannot be found at C:\Users\hp\Desktop\Tests\pages or C:\Users\hp\Desktop\Tests\src\pages. If using a custom path, please configure with the `no-html-link-for-pages` rule in your eslint config file. Linting and checking validity of types ..Failed to compile. .next/types/app/api/auth/[...nextauth]/route.ts:8:13 Type error: Type 'OmitWithTag<typeof import("C:/Users/hp/Desktop/Tests/app/api/auth/[...nextauth]/route"), "POST" | "GET" | "HEAD" | "OPTIONS" | "PUT" | "DELETE" | "PATCH" | "config" | "generateStaticParams" | ... 6 more ... | "maxDuration", "">' does not satisfy the constraint '{ [x: string]: never; }'. Property 'authOptions' is incompatible with index signature. Type 'AuthOptions' is not assignable to type 'never'. 6 | 7 | // Check that the entry is a valid entry > 8 | checkFields<Diff<{ | ^ 9 | GET?: Function 10 | HEAD?: Function 11 | OPTIONS?: Function
Move authOptions to a different file and import it to the route.ts file
Answer