Refreshing NextAuth Discord provider user details
Not sure how to phrase this so will try to describe in detail:
My website uses the nextauth discord provider (and no other sign in). When a user with an account changes their discord name and then signs in, it doesn't update. When a user changes their discord profile picture (that i'm using as their profile picture on my website) the link breaks (see image).
Is there a way to fetch the user's current username/profile picture on signin and update the database?
Thanks
Solution:Jump to solution
You can type it properly like this (refer the added lines)
```ts
import type { DiscordProfile } from "next-auth/providers/discord";
...
11 Replies
I'm pretty sure that you get the latest profile details in the
signIn
callback, and from there you can update your database values. You get the profile param there which is what you are looking for.
https://next-auth.js.org/configuration/callbacks#sign-in-callbackCallbacks | NextAuth.js
Callbacks are asynchronous functions you can use to control what happens when an action is performed.
this was really helpful, thank you - profile seems to be the wrong type though - logging out profile helped me find that the new url should be profile.image_url, but the profile only has 4 properties (image doesn't actually exist)
not sure where this typegen is coming from
disgusting code but it will have to do for now
i'm sorry for the crime i've comitted if anyone can help me get the correct profile type i'd appreciate it
Solution
You can type it properly like this (refer the added lines)
Add the lines to next-auth.d.ts file
awesome, thanks so much @shiroyasha9 that's looking good now ❤️
Glad to be here 🤝🏼
Hey, whats is this theme ? 😉
"I'm a vim user btw" 🤪
the theme is catppuccin, there is a VS Code extension for it as well!
Sweet, thanks ! 😉