Help in resolving CORS issue with Better Auth
This is my first time using Better Auth and I am pairing it with Elysia and a Solid SPA. The Elysia backend is a dedicated backend-for-frontend that will serve the frontend in production so they will share the same origin url.
I am currently running into CORS issues when I attempt to sign in using the username plug-in. Below are my configurations:
For my frontend SPA, here is my
vite.config.ts
. The thing to note about it is the server.proxy
configuration I have defined. When my frontend makes a request to http://localhost:3000/api/*
it'll route it to port 8000 instead as that is the port where my ElysiaJS backend runs on in a sidecar shell.
My frontend Better Auth client config is the following:
Moving on to the backend side of things, here is my Better Auth server config:
And here is my Elysia setup for Better Auth:
On the frontend, when I attempt to execute authClient.signIn.username(...)
I get the following error:
Clearly, http://localhost:3000
origin is not on that list which is why I'm getting hit with CORS, but I guess I'm wondering the question why since http://localhost:3000/api/auth
is there. And what is the recommended way to resolve this? Hoping to avoid explicit origins..0 Replies