[auth][错误] UnknownAction:无法解析 /api/auth/providers 处的操作。了解更多信息 https://errors.authjs.dev#unknownact​​ion

Moh*_*shi 2 next.js next-auth

尝试使用 next-auth authjs-v5 beta 教程设置 next-auth 并收到此未知操作错误,我无法弄清楚问题是什么,并且该网站也没有提到修复程序,只是说了错误名称,没有其他内容

我的包.json

{
  "name": "nextlearn",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@auth/core": "^0.26.3",
    "@auth/prisma-adapter": "^1.3.3",
    "@hookform/resolvers": "^3.3.4",
    "@prisma/client": "^5.9.1",
    "@radix-ui/react-label": "^2.0.2",
    "@radix-ui/react-slot": "^1.0.2",
    "bcrypt": "^5.1.1",
    "class-variance-authority": "^0.7.0",
    "clsx": "^2.1.0",
    "lucide-react": "^0.314.0",
    "next": "^14.1.0",
    "next-auth": "^5.0.0-beta.9",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "react-hook-form": "^7.49.3",
    "react-icons": "^5.0.1",
    "tailwind-merge": "^2.2.0",
    "tailwindcss-animate": "^1.0.7",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@types/bcrypt": "^5.0.2",
    "@types/node": "^20",
    "@types/react": "^18",
    "@types/react-dom": "^18",
    "autoprefixer": "^10.0.1",
    "eslint": "^8",
    "eslint-config-next": "^14.1.0",
    "postcss": "^8",
    "prisma": "^5.9.1",
    "tailwindcss": "^3.3.0",
    "typescript": "^5"
  }
}


Run Code Online (Sandbox Code Playgroud)

授权.ts

import NextAuth from "next-auth"
import { PrismaAdapter } from "@auth/prisma-adapter"
import authConfig from "./auth.config"
import {db} from "@/lib/db"

export const { handlers:{GET,POST}, auth } = NextAuth({
  adapter: PrismaAdapter(db),
  session: { strategy: "jwt" },
  ...authConfig,
})
Run Code Online (Sandbox Code Playgroud)

auth.config.ts

import Github from "next-auth/providers/github"

// eslint-disable-next-line import/no-anonymous-default-export
export default {
  providers: [Github(
    {
      clientId: process.env.GITHUB_ID??"",
      clientSecret: process.env.GITHUB_SECRET??"",
    }
  )],
} 
Run Code Online (Sandbox Code Playgroud)

应用程序/api/auth/[...nextauth]/route.ts

export {GET,POST} from "@/auth"
Run Code Online (Sandbox Code Playgroud)

错误

任何修复将不胜感激。

我尝试将版本更改为较低版本到 v4.XX.XX 它可以工作,但我希望它可以在 v5 beta 上工作,我尝试删除 node_modules 但它仍然不起作用

小智 5

升级到 next-auth v5 时遇到同样的问题。为我解决这个问题的是AUTH_URL从我的 .env 文件中删除密钥。

此评论为我指明了正确的方向:https://github.com/nextauthjs/next-auth/issues/9819#issuecomment-1912903196