Backend Auth + Frontend Framework Tutorial
Looking for a good tutorial on how to use Better-Auth in an architecture where it's on a server (i.e. Express) at api.myapp.com
And the frontend (i.e. next.js/react) at www.myapp.com does not have access to the database, it just calls the Better-Auth we setup on the above mentioned server, using a Better-Auth client.
Feels like this should be well documented example in the docs, but I cannot find much about this architecture.
Would like to know the proper config, and common issues and recommendations for this architecture choice.
2 Replies
It's documented. See Integrations section and read installation carefully. (There are some tips for separate server).
On nextJs it is done automatically. If you do not mention a baseURL it tries to send requests to the same domain as frontend. However if you mention a baseURL in the auth client config, then all client methods will send request to that URL when you call them, in your case to the express server. TThis way you don't have to configure DB access in your nextjs app.