Better AuthBA
Better Auth•7mo ago
Louca

Using BetterAuth with Mongoose

Hey, I discovered Better Auth recently and it looks great!

I'm building an app with Next.js, TypeScript and MongoDB, and I'm currently using Mongoose as my ODM. I'd like to introduce authentication using BetterAuth, but it seems like there is no adapter for Mongoose, only for MongoDB itself.

If I understand correctly, using the MongoDB adapter would force me to connect twice to the database: once for everything I'm already doing with Mongoose, and once with MongoClient only for BetterAuth. It doesn't seem very practical.

I've read the docs about creating a custom adapter, but I don't think I currently have the time for such thing, nor the required knowledge 😅
I've googled "BetterAuth and Mongoose" in every possible way, but I didn't find anyone's solution, so I'm wondering if there is any solution for me?
  • Is building an adapter easier than it seems?
  • Should I completely stop using Mongoose in favor to MongoClient? (my project is not too big yet for that if necessary)
  • Is there another solution I haven't thought about?
Thanks in advance for your help!

(It's my first time asking on a forum like that, so please feel free to ping me and ask for more details if necessary)
Was this page helpful?