Better Auth X Jstack integration
Hello @bekacru I'm having difficulty integrating Better Auth within this new stack that has been gaining a lot of traction rapidly, called Jstack
It basically is a Next.js app + a Hono app with an RPC setup & a custom router, and it's really good. At this point I tried everything I know to add Better Auth but in vain.
Would appreciate any kind of insights or ideas on this, i'd be happy to provide more info on the many approaches I tried.
Thanks a ton!
6 Replies
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
@Rakesh yes that's the thing, so i'm guessing a /api/auth/ catch all route for better auth handler, which is more specific than Jstack's catch all route /api/ so it worked for me. but how do we take advantage of the middlewares on the jstack?
I ended up defining betterAuth({}) twice, once on the nextjs app under lib, and once in the hono app in jstack.ts. I did the same for the database/drizzle.
I'm assuming this is correct since the Hono app is intended to be deployed on cloudflare workers, while the nextjs app on vercel, but i'm not sure if having 2 clients is the right approach. Maybe there is a way to define it once in Hono (server) and serve the endpoints through the router for the next app to use.
Let me know if you have any ideas regarding this, I will link a repo that has my current approach. Thanks a lot!
https://github.com/yahyazgour/jstack-betterauth
GitHub
GitHub - yahyazgour/jstack-betterauth
Contribute to yahyazgour/jstack-betterauth development by creating an account on GitHub.
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View
That's what I ended up doing, removed db and auth from nextjs server, defined both inside a hono jstack middlware. I created a procedure for each better auth endpoint inside the auth router.
https://github.com/yahyazgour/jstack-betterauth in case you want to check, thanks for the insight man!
GitHub
GitHub - yahyazgour/jstack-betterauth
Contribute to yahyazgour/jstack-betterauth development by creating an account on GitHub.
I used singelton pattern for db and auth definition. I'm not sure if they should be defined inside index.js insead of a middleware.
I would also love any ideas about improving the auth router since all the auth procedures use better auth handler()
Unknown User•3mo ago
Message Not Public
Sign In & Join Server To View