小编Luk*_*Luk的帖子

Next.js 13.4 和 NextAuth 类型错误:“AuthOptions”不可分配给类型“never”

我目前正在开发 Next.js 13.4 项目,并尝试使用应用程序/路由器设置 NextAuth。但是,我遇到了似乎无法解决的类型错误。

这是我的 Route.ts 文件:

import NextAuth, { AuthOptions } from "next-auth";
import DiscordProvider from "next-auth/providers/discord";

export const authOptions: AuthOptions = {
  providers: [
    DiscordProvider({
      clientId: process.env.CLIENT_ID as string,
      clientSecret: process.env.CLIENT_SECRET as string,
    }),
  ],
  session: {
    strategy: "jwt",
  },
  secret: process.env.NEXTAUTH_SECRET,
}

const handler = NextAuth(authOptions);

export { handler as GET, handler as POST }
Run Code Online (Sandbox Code Playgroud)

这是运行“npm run build”时的错误消息:

- info 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/Luk/Documents/Workspace/zerotwo-dash/src/app/api/auth/[...nextauth]/route"), "GET" …
Run Code Online (Sandbox Code Playgroud)

typeerror typescript next.js next-auth

17
推荐指数
2
解决办法
1万
查看次数

标签 统计

next-auth ×1

next.js ×1

typeerror ×1

typescript ×1