Auto populating new tables on user sign in

I created two models that are related to User in the same way Account and Session are. When a new user signs in User Session and Account all get populated with data, but GameData and UpgradeData dont seem to even with default values supplied. Ive looked through trpc.ts and auth.ts to see if I need to add anything in those files but I dont see anything related.
8 Replies
Taylor
Taylor16mo ago
do i need to create a new interface in the 'next-auth' module inside auth.ts?
Diogo
Diogo16mo ago
nextauth only populates the 4 default models what you can do is on signin event check if its a new user if it is then you can call prisma and insert a new row with user data it would be something like these events: { signIn: async (message) => { if (message.isNewUser) { await prisma.Gamedata.create({ data: { id: message.user.id, userId: message.user.id, }, }); } }, },
Taylor
Taylor16mo ago
Would be done in a routers file or in like authOptions within auth.ts'
Diogo
Diogo16mo ago
authoptions
Taylor
Taylor16mo ago
I dont have a great grasp on how data flows yet trying to work through it ahh okay I see I get autocomplete for an events option within authOptions. Will look in the docs to read about it
Diogo
Diogo16mo ago
Events | NextAuth.js
Events are asynchronous functions that do not return a response, they are useful for audit logs / reporting or handling any other side-effects.
Taylor
Taylor16mo ago
Okay got it working and another piece of the puzzle clicked into place for me. Thanks a lot
Diogo
Diogo16mo ago
youre welcome
Want results from more Discord servers?
Add your server