[英]next-auth/discord callbacks arent modifying data
I'm using next-auth/discord
however when using the session
callback to set a user id to the session it does not set the property.我正在使用next-auth/discord
,但是当使用session
回调将用户 ID 设置为 session 时,它不会设置该属性。
[...nextauth].js
import NextAuth from "next-auth/next";
import DiscordProvider from "next-auth/providers/discord";
export default NextAuth({
providers: [
DiscordProvider({
...
session: {
strategy: "jwt",
...
},
callbacks: {
async session({ session, user }) {
session.user.id = user.id;
return session;
}
}
})
]
});
/api/page.js
import { getSession } from 'next-auth/react';
export default async function handler(req, res) {
const session = await getSession({ req });
console.log(session);
}
This logs:这记录:
{
user: {
name: ...,
email: ...,
image: ...
},
expires: ...
}
With no user.id
property.没有user.id
属性。
Fixed it, callbacks should have been in NextAuth
object. Also callbacks shouldve been:修复它,回调应该在NextAuth
object 中。回调也应该是:
async jwt({ token, user }) {
if (user) {
token.id = user.id
}
return token
},
async session({ session, token }) {
session.user.id = token.id
return session
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.