T3 & Mongoose

I have an existing Discord bot which uses Mongoose to keep track of who uses it and store values relating to their account If I wanted to make a T3 app for the discord bot, how can I integrate my existing Mongoose database with NextAuth to allow users to login on the site @Josh
Solution:
Callbacks | NextAuth.js
Callbacks are asynchronous functions you can use to control what happens when an action is performed.
Jump to solution
20 Replies
sonor
sonorOP12mo ago
Essentialy, I want to add extra middleware to the DiscordProvider to compare with my MongoDB database, to check if the user exists, and if so attach an ID from their Mongoose record to their NextAuth session
Josh
Josh12mo ago
ah okay your looking for this
Solution
Josh
Josh12mo ago
Callbacks | NextAuth.js
Callbacks are asynchronous functions you can use to control what happens when an action is performed.
sonor
sonorOP12mo ago
oh a callback on signin seems like yeah thank you
Josh
Josh12mo ago
yessir you'll still use that adapter I linked eh actually I guess I can see why you're just using jwts if you're strictly using discord and already have their keys
sonor
sonorOP12mo ago
im a bit confused with that, would i better to just use JWT since im not already using prisma etc i didnt see the point in having a seperate DB just for sessions, but i still find nextauth a little confusing so maybe im thinking of it the complete wrong way
Josh
Josh12mo ago
the problem is jwts won't be persistent
sonor
sonorOP12mo ago
and the DB way would be?
Josh
Josh12mo ago
yeah
sonor
sonorOP12mo ago
ah okay
Josh
Josh12mo ago
cause you'd have the session in the db
sonor
sonorOP12mo ago
yeah gotcha hmm i see okay ill figure something out thank you for the help
Josh
Josh12mo ago
i actually really recommend building your own adapter tbh, it's pretty easy to just go rip out the core of the adapter in the one I linked then just modify it how you need to that's what I did with my boiler plate and it works like a charm, and makes the whole thing wayyyyyy less of a black box
sonor
sonorOP12mo ago
ah okay thats a good idea aswell might do that tbh
Josh
Josh12mo ago
GitHub
GitHub - GentikSolm/t3-app-dir: t3 app dir boilerplate
t3 app dir boilerplate. Contribute to GentikSolm/t3-app-dir development by creating an account on GitHub.
Josh
Josh12mo ago
this file in particular
Josh
Josh12mo ago
GitHub
t3-app-dir/src/server/auth.ts at main · GentikSolm/t3-app-dir
t3 app dir boilerplate. Contribute to GentikSolm/t3-app-dir development by creating an account on GitHub.
Josh
Josh12mo ago
I'm my example it's the drizzle adapters,I just modified it how I needed. you'd do the same thing but with mongo
Rhys
Rhys12mo ago
GitHub
AnswerOverflow/packages/auth at main · AnswerOverflow/AnswerOverflow
Indexing Discord Help Channel Questions into Google - AnswerOverflow/AnswerOverflow
Rhys
Rhys12mo ago
It’s not mongoose it’s MySQL but it doesn’t matter that much since the main thing is NextAuth and the custom adapters It syncs users who sign in with their existing Discord account from the bot
Want results from more Discord servers?
Add your server