nextjs auth doesn't return all properties
Unanswered
Spectacled Caiman posted this in #help-forum
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
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 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
Spectacled CaimanOP
what exactly is
token.sub and what can i do with it?Sun bear
You could do it lke here and console log the profile to see what information discord provided:
Token.sub is the email address
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
@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
Spectacled CaimanOP
im using discord provider and the issue is nothing to do with roles, its getting the actual user's information.
token.sub is supposed to be the discord user Id but when I log it, it is a uuid. I'm using next-auth v5 beta@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
Sun bear
Cant you do it like here only for discord instead of google and log the profile.
The links i sent were just to show how its working its not 1:1 usable
The links i sent were just to show how its working its not 1:1 usable