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
sonor7mo 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
Josh7mo ago
ah okay your looking for this
Solution
Josh
Josh7mo ago
Callbacks | NextAuth.js
Callbacks are asynchronous functions you can use to control what happens when an action is performed.
sonor
sonor7mo ago
oh a callback on signin seems like yeah thank you
Josh
Josh7mo 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
sonor7mo 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
Josh7mo ago
the problem is jwts won't be persistent
sonor
sonor7mo ago
and the DB way would be?
Josh
Josh7mo ago
yeah
sonor
sonor7mo ago
ah okay
Josh
Josh7mo ago
cause you'd have the session in the db
sonor
sonor7mo ago
yeah gotcha hmm i see okay ill figure something out thank you for the help
Josh
Josh7mo 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
sonor7mo ago
ah okay thats a good idea aswell might do that tbh
Josh
Josh7mo 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
Josh7mo ago
this file in particular
Josh
Josh7mo 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
Josh7mo 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
Rhys7mo ago
GitHub
AnswerOverflow/packages/auth at main · AnswerOverflow/AnswerOverflow
Indexing Discord Help Channel Questions into Google - AnswerOverflow/AnswerOverflow
Rhys
Rhys7mo 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
More Posts
Function sometimes running twice when deployed to VercelI'm experiencing an issue with my NextJS app (create-t3-app starter) where an API route is intermittClerk Webhooks with Prisma (Sync database, user model)Hi, does anyone have a working example of how to sync user model via Prisma with Clerk? Clerk recommGetting role undefined in session even though it exist in db```ts interface UserRole { role: "pleb" | "admin"; } declare module "next-auth" { interface SesHow to filter-out images beyond certain size before the upload?Hey there. I'm having a trouble with restricting the size of images before the upload. I am using NeTheo, why you never use Docker? Why you always use Cloud based solutions?Theo, why you never use Docker? Why you always use Cloud based solutions that will gonna cost money How to handle after form submit with Server Actions ?Hello, I'm looking for the best way to know the form is succesfully submitted and a succesful respoNext-Auth v5 lacking provider authorization paramsI'm working with t3-turbo which has next-auth v5 and I'm not able to set authorization params like `Seeking Advice for a T3 Stack Application: Separating tRPC from NextJSI am currently planning to develop a web application using a T3 stack that includes tRPC, NextJS, anUploadThing `<UploadDropzone />` ComponentI'd like to have my file listed when I use the `<UploadDropzone />` component How can I have access Database & Serverless : handle connection spikes ?Hey, I'm running a Nextjs side project on Vercel & Mongo Atlas. My ORM is Mongoose (yep, didn't lea