NextAuth 5:主机必须受信任

NextAuth 5: Host must be trusted

提问人:Tomas Lukac 提问时间:11/18/2023 更新时间:11/18/2023 访问量:19

问:

我刚刚使用 NextJs 14 应用程序成功配置了 NextAuth 5。然后我在另一台 PC 上签出该项目,创建了相同的文件,现在在导航到时出现以下错误.envhttp://localhost:3000/api/auth/signin

[auth][error][N]: Host must be trusted. URL was: http://localhost:3000/api/auth/signin. Read more at https://errors.authjs.dev#n
    at C:\Users\me\projects\my-project\.next\server\chunks\687.js:364:39815
    at nc (C:\Users\me\projects\my-project\.next\server\chunks\687.js:364:41457)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async C:\Users\me\projects\my-project\node_modules\next\dist\compiled\next-server\app-route.runtime.prod.js:6:41304

与以下页面

enter image description here

任何想法,应该是什么情况,或者我错过了哪个选项?

.env

AUTH_GITHUB_ID=id
AUTH_GITHUB_SECRET=secret
AUTH_SECRET=secret generated using https://generate-secret.vercel.app/32

src/auth.ts

import type { NextAuthConfig } from "next-auth"
import NextAuth from "next-auth"
import GitHub from "next-auth/providers/GitHub"
import { DrizzleAdapter } from "@auth/drizzle-adapter"
import { db } from "@/db"

export const authConfig = {
  providers: [GitHub],
  adapter: DrizzleAdapter(db),
  callbacks: {
    /* does not return ID by default */
    async session({session, user}) {
      session.user.id = user.id
      return session
    },
  }
} satisfies NextAuthConfig

export const { 
  handlers, 
  auth, 
  signOut 
} = NextAuth(authConfig)

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

import { handlers } from "@/auth";

export const { GET, POST } = handlers;
下一个.js 下一个身份验证 下一个身份验证.js

评论


答:

0赞 Tomas Lukac 11/18/2023 #1

我正在运行命令而不是 ,所以没有被选中。npm run startnpm run dev.env