i'm currently trying to use the DiscordProvider
from next-auth
to authorize with discord using the OAuth2 flow so I can query the discord API once succesfully logged in, however; it seems that the jwt
callback is not being called, and i'm not sure why. For the record, it doesn't reach any console logs inside the jwt
callback
This is my my code:
import { type GetServerSidePropsContext } from "next";
import {
getServerSession,
type NextAuthOptions,
type DefaultSession,
} from "next-auth";
import DiscordProvider from "next-auth/providers/discord";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { env } from "~/env.mjs";
import { prisma } from "~/server/db";
export const authOptions: NextAuthOptions = {
callbacks: {
async jwt({ token, account }) {
console.log("i get here");
console.log("account", account);
console.log("token", token);
if (account) {
token.accessToken = account.access_token;
await console.log(token.accessToken);
}
return token;
},
async session({ session, token, user }) {
return {
...session,
user: {
...session.user,
id: user.id,
name: user.name,
},
};
},
},
adapter: PrismaAdapter(prisma),
providers: [
DiscordProvider({
clientId: env.DISCORD_CLIENT_ID,
clientSecret: env.DISCORD_CLIENT_SECRET,
token: "https://discord.com/api/oauth2/token",
userinfo: "https://discord.com/api/users/@me",
authorization: {
params: {
scope:
"identify email guilds applications.commands.permissions.update",
},
},
}),
],
};