I’m building an application where the backend is a standalone Node.js + Express server, and the frontend is a separate Next.js app. I’d like to integrate Better Auth for authentication and user management across both.
How can I properly configure Better Auth so that:
- The Express backend handles authentication logic and token validation securely.
- The Next.js frontend can interact with the backend for login, signup, and session management.
- Authentication state (like JWT or session cookies) is maintained between the two apps, even though they run on different domains or ports.
What’s the recommended setup for this architecture — including configuration examples, best practices, and potential pitfalls when separating frontend and backend?