Can I use better auth as authentication layer between hono backed and next js frontend?

I'm building platform that has hono js as backend, next js for web app, expo for mobile, prisma for db within turborepo. I'm using nextjs server side data fetching so I have to check authorisation on server side of next js. I know this case is too much complicated. Please if you have any near examples or suggestions, It would help a lot.
5 Replies
ayersss
ayersss3d ago
hi, i have a hono app as auth server and another backend for business logic. I am using jwt plugin for both client and auth server. You can call authClient.token() to get the token and send it as bearer token to ur backend to validate.
KiNFiSH
KiNFiSH2d ago
i hope you are using monorepo arch so i recommend you to split the workspace for backend / auth , web and also the mobile as well wit in the monorepo along shared configs
jalol
jalolOP2d ago
thank you very much. this was very helpful Yes. I'm using turborepo and splitting all shared code into packages (db, auth, tsconfig)
Platon
Platon2d ago
As others said, this is exactly what I’m doing for my personal project: turborepo monorepo setup - hono backend (with better auth) - NextJS frontend - additionally, payload cms for admin frontend, using Hono/better-auth exposed endpoints for admin tools It goes against turborepo suggestions that your apps shouldn’t export anything other apps use, so technically your better-auth/hono stuff should live in a package within your turborepo setup, and you should have a standalone hono app within your /apps that imports that package Ideally, your setup would be: - /packages/auth (better-auth export) - /packages/hono (hono exports like routes, middleware, and anything else you’ll use in multiple apps) - /apps/backend (serve hono app) - /apps/frontend Potentially merge the hono and better auth into one package, and have a separate package for your hono/better auth backend exports But you get the gist
KiNFiSH
KiNFiSH2d ago
it that is the case yeah you can use

Did you find this page helpful?