dhe*_*jpv 5 authentication typescript discord next-auth
我正在尝试使用“identify”和“guilds”范围对 Discord 用户进行身份验证。似乎可以token.profile
使用以下代码将 Discord 提供的用户信息添加到令牌中(注意我也在那里包含了 guilds 数组):
async jwt(token, user, account, profile, isNewUser) {
if (profile) token.profile = profile;
if (account?.accessToken) token.accessToken = account.accessToken;
const data = await (
await fetch("https://discord.com/api/v8/users/@me/guilds", {
method: "GET",
headers: {
Authorization: `Bearer ${account?.accessToken}`,
},
})
).json();
// @ts-ignore
token.profile.guilds = data;
return token;
},
Run Code Online (Sandbox Code Playgroud)
但是,一旦我添加将对象session
添加profile
到会话中的功能,null
即使登录后,会话也会一直持续,并且 Discord 的登录屏幕会提示我输入用户名和密码,而不是自动让我进入。
// @ts-ignore
async session(session, token) {
console.log("token", token);
console.log("session", session);
// @ts-ignore
session.profile = token.profile;
return session;
},
Run Code Online (Sandbox Code Playgroud)
顺便说一句,我必须@ts-ignore
在函数中添加这么多 s 的原因session
是它预计一段Promise<WithAdditionalParams<Session>>
时间我只返回 a Promise<Session>
,不知道如何解决这个问题。
任何人都可以帮助我将从 Discord 收到的信息添加到 中,session
以便我可以在我的应用程序中使用它吗?