NextAuth / Auth.js Support
Could convex have an
Auth.js
Adapter? https://authjs.dev/guides/adapters/creating-a-database-adapter I think convex should have one like clerk as its usedb y many who want more control over there auth. Ive been currently been trying to make a custom one in my app for my project and its a lot of config.Creating a database adapter | Auth.js
Custom adapters allow you to integrate with any (even multiple) database/back-end service, even if we don't have an official package available yet. The only requirement is that your database can support the models that Auth.js expects.
5 Replies
Hey @CodingWithJamal, some folks got it working, so you're on a good path.
For custom auth we do have an integration with Lucia that plays a bit nicer with Convex, check out
npm create convex@latest
(template is here: https://github.com/get-convex/templates/tree/main/template-nextjs-lucia-shadcn)
Will definitely look into adding official docs for NextAuth.oh i did not know this existed thanks
So i spent the last 4 hours using this template and porting it over from prisma (mySQL) to convex. Not sure if its helpful but i wanted to test for myself If convex could be used with next-auth easily.
After working with this, it was not to difficult. The main challenge was i didnt write must of the ui code, so most of my convex types I had to simply any on the client side for time sake.
But I made a custom adaper for next-auth in the
@lib/db/Adapeter.ts
file which just calls convex functions and returns there data. This is also not type safe at all as i was rushing to just see if it would work, but basically it just calls the http client and returns the data from functions.
I think if i started slow with a little minimal code, it would be more safe but I didnt feel like rewriting most of the types, but im happy to see convex can be used with the adaper, although i didnt try to mix this with the convex/react hooks yet.
https://github.com/PhantomByteCloud/website/tree/next-auth-saas-convexGitHub
GitHub - PhantomByteCloud/website at next-auth-saas-convex
Contribute to PhantomByteCloud/website development by creating an account on GitHub.
we now have a guide for setting up Convex with NextAuth: https://stack.convex.dev/nextauth
Convex with Auth.js (NextAuth)
Learn how to use Auth.js with your Next.js server and Convex backend to build a full-featured authentication system.
nice