Next.js Discord

Discord Forum

nextjs auth doesn't return all properties

Unanswered
Spectacled Caiman posted this in #help-forum
Open in Discord
Spectacled CaimanOP
When authorising with the scopes guilds, identify and guilds.join, i am not provided with the users guilds or id, only their name and avatar. How do i get these additional properties?
const scopes = 'guilds identify guilds.join';

export const authConfig: NextAuthConfig = {
  providers: [discord({
    clientId: process.env.CLIENT_ID,
    clientSecret: process.env.CLIENT_SECRET,
    authorization: `https://discord.com/api/oauth2/authorize?scope=${encodeURIComponent(scopes)}`,
  })]
}

6 Replies

Sun bear
You can check this:
https://authjs.dev/guides/role-based-access-control

You basically have to add custom values to the session.

I also like thos example:
https://github.com/mickasmt/next-auth-roles-template/blob/main/auth.ts
Sun bear
You could do it lke here and console log the profile to see what information discord provided:

import NextAuth from "next-auth"
import Google from "next-auth/providers/google"
 
export const { handlers, auth } = NextAuth({
  providers: [
    Google({
      profile(profile) {
        return { role: profile.role ?? "user", ... }
      },
    })
  ],
  callbacks: {
    jwt({ token, user }) {
      if(user) token.role = user.role
      return token
    },
    session({ session, token }) {
      session.user.role = token.role
      return session
    }
  }
})


Token.sub is the email address