提问人:José Cardozo 提问时间:4/26/2023 更新时间:8/3/2023 访问量:174
getServerSession() return { user: { name: undefined, email: undefined, image: undefined } }
getServerSession() return { user: { name: undefined, email: undefined, image: undefined } }
问:
我有一个服务器端组件,这个文件是 *.jsx,我需要有用户记录的 id 来执行 http 请求,但是当我运行此行会话时 catch { user: { name: undefined, email: undefined, image: undefined } }const session = await getServerSession(authOptions);
我正在使用
- 下一个身份验证:“^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);
答: 暂无答案
评论