Auth service in microservice architecture
I'm trying to build a Hono backend setup with two separate services:
One serves as the auth server that handles all user-related logic (base path: /auth), and the other handles business logic (base path: /api).
In production, both will be hosted on the same domain. Locally, I'm using localhost:3000 for the business logic and localhost:3001 for auth.
Currently, I’m able to log in with Google OAuth via the auth server from the frontend but when I try to fetch data from the API backend, the session is null, which results in a 401 error.
I’ve looked through previous threads, and it seems like using the jwt plugin is a solution?
How should I configure the better-auth instance to work across both applications?
5 Replies
Cookies | Better Auth
Learn how cookies are used in Better Auth.
hi, thanks for the reference! I end up using bearer token for authentication
hey @Elwin.! i am using nextjs as frontend and express as backend i don't understand how i configure better auth and connect the two could you help or share your project so i could have a look and figure stuff out
@Ayaan Meman Are you using Server Actions or API endpoints in your Next.js app?
I’m working with a React SPA and two backend servers — one for better-auth and one for core business logic.
What I need is to verify the requests sent to the API backend. My frontend will pass the token, and I'm using jose to verify it.
So the api server does not have any better-auth config.
While my approach works for now but I think there might be a better way to do this
I also use jwt plugin and you'll need to add jwtClient in your authClient
then you can invoke getToken() and send it to the backend to verify
but seems like you only have one backend so no need for this complexity?
unless you are using server action / nextjs api endpoint
ok i get it i will try your aproch and let you know how it goes