Can anyone help me with extracting the banner and ID of the currently logged in user? Feel free to reach out at next@12 [email protected] I have successfully logged the profile details at the backend, but I'm facing issues pulling this information on the frontend. I'm new to next.js and encountering difficulties using next-auth with version 14. 😄
import DiscordProvider from "next-auth/providers/discord";
export const authOptions = {
providers: [
DiscordProvider({
clientId: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
authorization: { params: { scope: "identify guilds" } },
profile(profile) {
if (profile.avatar === null) {
const defaultAvatarNumber = parseInt(profile.discriminator) % 5;
profile.image_url = `https://cdn.discordapp.com/embed/avatars/${defaultAvatarNumber}.png`;
} else {
const format = profile.avatar.startsWith("a_") ? "gif" : "png";
profile.image_url = `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.${format}`;
}
return {
id: profile.id,
name: profile.username,
discriminator: profile.discriminator,
image: profile.image_url,
banner: profile.banner,
accentColor: profile.accentColor,
};
},
}),
],
callbacks: {
async session({ session, user, token }) {
if (session) {
session.accessToken = token.accessToken;
session.tokenType = token.tokenType;
session.discordUser = token.profile;
}
return session;
},
async signIn({ user, account, profile, email, credentials }) {
if (account.provider != "discord" && !user.id) {
return;
}
return {
user: {
name: user.name,
email: user.email,
image: user.image,
banner: profile.banner,
accentColor: profile.accentColor,
},
accessToken: user.accessToken,
expires: user.expires,
};
},
async jwt({ token, account, profile }) {
if (account) {
token.accessToken = account.access_token;
}
return token;
},
},
secret: process.env.NEXTAUTH_SECRET,
};
export default NextAuth(authOptions);