从 \'@/auth\' 导入 { auth };const page = async ({children}) => { const session = await auth(); 返回
import { auth } from "@/auth";
const page = async ({children}) => {
const session = await auth();
return <div>{children}</>
};
// My auth config
import { Pool } from "@neondatabase/serverless";
import NextAuth from "next-auth";
import PostgresAdapter from "@auth/pg-adapter";
import { authConfig } from "./auth.config";
export const { handlers, auth, signIn, signOut } = NextAuth(() => {
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
return {
adapter: PostgresAdapter(pool),
trustHost: true,
...authConfig,
};
});
登录时会话为空。虽然客户端对象始终有效,但问题出在服务器端页面上。只有偶尔,会话才会在页面导航期间填充。
我错过了什么?
我正在使用“next-auth”:“5.0.0-beta.20”。尝试降级到早期版本,但没有帮助。