-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discord provider is missing user.id in the session object #62
Comments
I have the same error using github. Did you find a solution? |
The soluzion is adding a callback inside the auth properties, thats add the userid
|
[auth][error] JWTSessionError: Read more at https://errors.authjs.dev#jwtsessionerror
[auth][cause]: TypeError: Cannot read properties of undefined (reading 'id')
at Object.session (eval at instantiateModule (file:///C:/.../auth/node_modules/vite/dist/node/chunks/dep-G-px366b.js:54755:28), <anonymous>:18:31)
at Module.session (file:///C:/.../auth/node_modules/@auth/core/lib/actions/session.js:35:52)
at async AuthInternal (file:///C:/.../auth/node_modules/@auth/core/lib/index.js:35:24)
at async Module.Auth (file:///C:/.../auth/node_modules/@auth/core/index.js:104:29)
at async Module.getSession (eval at instantiateModule (file:///C:/.../auth/node_modules/vite/dist/node/chunks/dep-G-px366b.js:54755:28), <anonymous>:56:20)
at async eval (eval at instantiateModule (file:///C:/.../auth/node_modules/vite/dist/node/chunks/dep-G-px366b.js:54755:28), <anonymous>:16:19)
at async AstroComponentInstance.render (eval at instantiateModule (file:///C:/.../auth/node_modules/vite/dist/node/chunks/dep-G-px366b.js:54755:28), <anonymous>:44:7)
at async Object.render (eval at instantiateModule (file:///C:/.../auth/node_modules/vite/dist/node/chunks/dep-G-px366b.js:54755:28), <anonymous>:356:7)
at async Module.renderChild (eval at instantiateModule (file:///C:/.../auth/node_modules/vite/dist/node/chunks/dep-G-px366b.js:54755:28), <anonymous>:36:5)
[auth][details]: {} Doesn't work for me, I just get an error message when I try to log in, where should I add this? |
For me i added it like this to the auth config, but i only tested it for github, not for discord. t3-stack did the same, in order to add the user.id to every object
|
Plss solve this |
I use this to get user ID
|
But that does not retrieve the actual discord ID does it? it returns a unique identificatory number but not the actual discord ID right? |
I think it is. https://github.com/nextauthjs/next-auth/blob/main/packages/core/src/providers/discord.ts#L164-L168 After reading this repo code, I came to know that 'id' is forwarded as 'token.sub' |
For those struggling - the solution I used was a small function to extract it from the
|
And what if it has no avatar, then the image url is: 'https://cdn.discordapp.com/embed/avatars/0.png' @fearandesire |
Great point! I haven't come across this issue yet myself. That said, I just offered a solution that works for my needs. I'm not sure what to do in the event they don't have an avatar. |
Following up, the solution provided by @willnode works! I explored this option for a site I recently launched, and the solution I provided prior was the cause of a silly bug as some users did not have avatars. To clarify, for me -- this solution returns the User ID. I don't seem to get any UUID-like string as @Cocodrulo got here |
I dont know why, sometimes token.sub gives the discord ID but other times it return thar strange UUID-like string. I was finally getting the discord ID and then suddenly token.sub was that kind of string again. I don't really understand. |
Any update on a fix for this issue or alternative work arounds? I get the same issues above when using the callbacks, either Would love to continue using the library but I need that ID, there's really no point without it |
I love this 😂 Very clever, I'm just concerned it will break if Discord randomly changes their avatar naming pattern. Edit: And yes, as pointed out already, users with no avatar break this logic anyway |
problem here is that not everyone has a profile picture, so if you don't have one, it won't work because the avatar string is empty |
All right here is my hacky solution because I don't need access to the users email import Discord from '@auth/core/providers/discord';
import { defineConfig } from 'auth-astro';
export default defineConfig({
providers: [
Discord({
clientId: import.meta.env.DISCORD_CLIENT_ID,
clientSecret: import.meta.env.DISCORD_CLIENT_SECRET,
async profile(profile) {
return {
name: profile.username,
email: profile.id,
image: `https://cdn.discordapp.com/avatars/${profile.id}/${profile.avatar}.png`,
};
},
}),
],
}); gives me this from the {
user: {
name: 'arknoodle',
email: '223864942615461888',
image: 'https://cdn.discordapp.com/avatars/223864942615461888/656ffa166759d7f24a73295a68ba023e.png'
},
expires: '2024-09-10T23:21:08.634Z'
} |
If I want to add guild scope, to know which servers the user is on in Discord, how do I do it? |
Which version are u using? |
using the discord API |
If I log the session, I only get this JSON Object back and the
user.id
is missing for some reasonSession Object :
auth.config.ts :
The text was updated successfully, but these errors were encountered: