我需要访问 Next-Auth/Nextjs 13.4 API 路由中的用户会话数据。我已经配置了 JWT 和 Session 回调;但是,我在回调函数中指定的用户数据不会转换为 getServerSession 在 API 路由中拉取的数据。但是,使用 useSession() 时,会话数据确实正确反映在客户端页面中,因此我不确定问题是什么。
[...nextauth]/route.js
import { connectToDB } from "@/app/server/db";
import NextAuth from "next-auth";
import CredentialsProvider from "next-auth/providers/credentials";
import bcrypt from 'bcrypt';
// Authorize function
async function authorize(credentials) {
const { email, password } = credentials;
const { db } = await connectToDB("Tenants");
const user = await db.collection("Users").findOne({ email });
if (user) {
const isPasswordValid = await bcrypt.compare(password, user.password);
if (!isPasswordValid) { return null; }
await db.collection("Users").updateOne({ email …Run Code Online (Sandbox Code Playgroud)