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
sonorOP13mo 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
Josh13mo ago
ah okay your looking for this
Solution
Josh
Josh13mo ago
Callbacks | NextAuth.js
Callbacks are asynchronous functions you can use to control what happens when an action is performed.
sonor
sonorOP13mo ago
oh a callback on signin seems like yeah thank you
Josh
Josh13mo 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
sonorOP13mo 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
Josh13mo ago
the problem is jwts won't be persistent
sonor
sonorOP13mo ago
and the DB way would be?
Josh
Josh13mo ago
yeah
sonor
sonorOP13mo ago
ah okay
Josh
Josh13mo ago
cause you'd have the session in the db
sonor
sonorOP13mo ago
yeah gotcha hmm i see okay ill figure something out thank you for the help
Josh
Josh13mo 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
sonorOP13mo ago
ah okay thats a good idea aswell might do that tbh
Josh
Josh13mo 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
Josh13mo ago
this file in particular
Josh
Josh13mo 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
Josh13mo 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
Rhys13mo ago
GitHub
AnswerOverflow/packages/auth at main · AnswerOverflow/AnswerOverflow
Indexing Discord Help Channel Questions into Google - AnswerOverflow/AnswerOverflow
Rhys
Rhys13mo 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