我刚刚用NextJs 14应用程序成功配置了NextAuth 5。然后我在另一台PC上 checkout 了项目,创建了相同的.env
文件,现在我在导航到http://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
字符串
与以下页面
x1c 0d1x的数据
有什么想法应该是什么情况下或哪个选项是我错过了?
.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;
型
1条答案
按热度按时间fjaof16o1#
我运行的是
npm run start
命令而不是npm run dev
命令,所以.env
没有被选中。