Storing Account Usename With Next Auth
I'm looking to store the username of an account when they sign in i.e
I see it's possible to extend the Prisma adapter and you can create your own
linkAccount
but that doesn't expose the name. Is it possible to add fields to the account adapter and extend that?
Thanks11 Replies
It seems the account interface isn't extendable so what may be better is making that field optional, having a custom callback when they sign in with that account and to get that information
You already have it on User model
What if you wanted to say display the name of both their Google account and Discord account and those are two different names?
In my case, I'm working on rewriting a Discord bot of mine and it's possible for me to store information about Discord users (i.e name, avatar) before they've signed in on my website
I'm thinking of making it so the account table works without having a user created for it so when my bot first creates a Discord user who hasn't signed in, it just stores that to the account table
It might just be work making a separate Discord users table to prevent breaking things with next auth
Relevant code is here:
https://github.com/AnswerOverflow/AnswerOverflow/blob/API/packages/api/src/router/accounts/discord-accounts.ts
and here:
https://github.com/AnswerOverflow/AnswerOverflow/blob/API/packages/auth/src/auth-options.ts
Here we go, I found an implementation I like
So when you link your account now, it fetches your Discord information and creates/updates it as its own table in the database, then creats the account with the provided account id action as the foreign key to the discord account
Only issue with this is it requires IDs to be unique, this would need to be revisited if i wanted to support multiple auth provides but that's not needed
Not sure if you check if that account already exist before creating a new one, would be good
It’s doing an upset with Prisma so it’ll create / update it in the same SQL call
Ok, looked https://github.com/AnswerOverflow/AnswerOverflow/blob/API/packages/api/src/router/accounts/discord-accounts.ts and here its just create
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Ah yeah that’s unfinished
Possibly, but then let’s say I want to store something like their discord discriminator then that becomes an unused field
Can u not add it to the User model? Thats what I do
edit - not exactly following ur idea with accounts existing before creation, nvm nvm
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Yeah it’s possible for some of them to be undefined, in my mind this way it’s more modular where let’s say you wanted to strip out discord support - all you have to do is delete the discord table and the thing that syncs it and you’re good
The main thing is I need to store a lot of users who may not have an account and need that to be as simple as possible - along with that I need their discord ID and name etc
My project is for displaying discord help channel messages on the web so it’s possible to index a users content and have their name / profile picture before they’ve signed into the website - so it needs to support displaying their information that way