How can I implement authentication for a React SPA?

If I have a react SPA, how can I integrate it with with BetterAuth + Express? I want to do for auth for a React SPA, without any frameworks like NextJS, Remix, etc.
2 Replies
bekacru
bekacru6mo ago
You can mount the server on Express and use the client SDK on the React side, and it should work. But, keep in mind that since Better Auth relies on cookies, your frontend and backend need to be deployed using a subdomain setup, otherwise, cross-domain cookies won't work properly.
squishycantaloupe
squishycantaloupeOP6mo ago
Oh, I wonder if this will cause issues because my staging url might be staging-site.com and my api server will still be api.prod.com

Did you find this page helpful?