小编Sha*_*rif的帖子

Next-Auth getServerSession 未在 Nextjs 13.4 API 路由中检索用户数据

我需要访问 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)

javascript reactjs next.js next-auth next.js13

7
推荐指数
1
解决办法
1715
查看次数

标签 统计

javascript ×1

next-auth ×1

next.js ×1

next.js13 ×1

reactjs ×1