I am trying to authenticate users with Discord using the "identify" and "guilds" scopes. It seems to be possible to add the user info provided by Discord into the token into token.profile (note I am also including the guilds array there as well) using this code:
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;
},
But, as soon as I add a session function that adds the profile object into the session, the session becomes null all the time even when signed in, and the login screen from Discord prompts me to enter username and password instead of just automatically letting me in.
// @ts-ignore
async session(session, token) {
console.log("token", token);
console.log("session", session);
// @ts-ignore
session.profile = token.profile;
return session;
},
As a side-note, the reason I have to add so many @ts-ignores in the session function is that it expects a Promise<WithAdditionalParams<Session>> while I only return a Promise<Session>, not sure how to fix that.
Can anyone help me add the information I receive from Discord into the session so that I can use it in my application?