getServerSession() return { 用户:{ 名称:未定义,电子邮件:未定义,图像:未定义 } }

问题描述 投票:0回答:1

我有一个服务器端组件,该文件是 *.jsx,我需要用户记录 http 请求的 ID,但是当我运行此行时

const session = await getServerSession(authOptions);
session catch { user: { name: undefined, email: undefined, image:未定义 } }

我正在使用

  • 下一个验证:“^4.22.0”
  • 下一个”:13.2

这是我的 [...nextauth].ts 文件

import CredentialsProvider from "next-auth/providers/credentials";
import NextAuth, { NextAuthOptions } from 'next-auth';
import api from "../../../settings";

export const authOptions: NextAuthOptions = {
    session: {
        strategy: 'jwt'
    },
    pages: {
        signIn: "/auth/login",
        // error: "/auth/error",
        // signOut: "auth/logout"
    },
    secret: process.env.JWT_SECRET,
    providers: [
        CredentialsProvider({
            type: 'credentials',
            name: 'Ingresar',
            credentials: {},
            async authorize(credentials, req) {
                const { email, password } = credentials as {
                    email: string,
                    password: string
                };

                const res = await fetch(`${api}/login`, {
                    method: 'POST',
                    headers: { "Content-Type": "application/json" },
                    body: JSON.stringify({email, password})
                })
                const user = await res.json()
    
                // If no error and we have user data, return it
                if (res.ok && user) {
                    console.log(user)
                    return user
                }
                // Return null if user data could not be retrieved
                return null
            }
        })
    ]
}

export default NextAuth(authOptions);


typescript server-side next-auth nextjs13
1个回答
-1
投票

同样的问题?需要一些帮助...

© www.soinside.com 2019 - 2024. All rights reserved.