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