How to use Better Auth (Elysia backend) with Next.js Server Actions & RSC
I’m running Better Auth inside an Elysia backend, and I’ve reverse-proxied its authentication API to my Next.js app at /api/auth/[...all].
This setup works fine — I can use authClient on the client side in Next.js to connect to the Elysia instance.
However, I’m not sure how to connect Better Auth inside Next.js server actions or RSC (React Server Components) to the Elysia instance.
Right now, I can only call the backend via a direct URL request, but doing so means I lose all the Better Auth type safety and full typings.
Does anyone know the proper way (or best practice) to make Better Auth work in server actions/RSC when the auth server is running externally in Elysia?
Also, English is not my native language, so if there’s any ambiguity, please don’t hesitate to question or ask for clarification. Thank you, everyone.
This setup works fine — I can use authClient on the client side in Next.js to connect to the Elysia instance.
However, I’m not sure how to connect Better Auth inside Next.js server actions or RSC (React Server Components) to the Elysia instance.
Right now, I can only call the backend via a direct URL request, but doing so means I lose all the Better Auth type safety and full typings.
Does anyone know the proper way (or best practice) to make Better Auth work in server actions/RSC when the auth server is running externally in Elysia?
Also, English is not my native language, so if there’s any ambiguity, please don’t hesitate to question or ask for clarification. Thank you, everyone.
Solution
GitHub
Example: Better Auth on a separate backend. Contribute to bytaesu/better-auth-separate-backend development by creating an account on GitHub.