You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
use:enhance does not update form.message when running into a CSRF error #15737
Basically, when a form has use:enhance, it does not update form.message when running into a CSRF error when the ORIGIN variable is empty, during production build where ORIGIN is not specifically set.
the fact that the ORIGIN variable is empty, is not the thing that I report here.
It is the fact the form.message does not update, whilst the console's network tab DOES show in the response that there is a message key saying the CSRF error (see logs section).
Reproduction
To reproduce, you must start a new project using npx sv create with betterauth demo installed (since that gives a basic form with use:enhance) and the adapter-node.
Then build the project, using npm run build
Then run the build by going into the build folder and running node . (without adding any ORIGIN env variables)
Then open the link in your browser and go to /demos/better-auth/login (http://localhost:3000/demo/better-auth/login) and then just enter like test@test.com and test as password and then just click "Login"
in the browser console it should say 401 with the CSRF error, but on the frontend the form?.message does not update.
(it does update when the ORIGIN variable is set and then the database itself is not existing and then it does show "Unexpected error" in the form?.message)
Logs
xqEx-9sN.js:1 POST http://localhost:3000/demo/better-auth/login?/signInEmail 403 (Forbidden)
{
"message": "Cross-site POST form submissions are forbidden"
}
changed the title [-]use:enhance does not update form.message when running into a CORS error[/-][+]use:enhance does not update form.message when running into a CSRF error[/+]on Apr 21, 2026
Because THIS was the response from the request, I expected the message value to be shown in form.message
But nope, it does NOT render the +error.svelte, it shows completely nothing to the user/frontend. Not even to the backend.
Only when I open the console, I saw the error
Activity
Conduitry commentedon Apr 21, 2026
Are you talking about CORS errors or about the CSRF protection?
Miniontoby commentedon Apr 21, 2026
I am talking about the error that is in the logs section:
Wasn't sure what to call it.
CrossSite yeah that is CSRF, I guess, I thought CrORss Site being CORS
[-]use:enhance does not update form.message when running into a CORS error[/-][+]use:enhance does not update form.message when running into a CSRF error[/+]PatrickG commentedon Apr 22, 2026
What do you expect
form.messageto be? If there is a CSRF error your form action does not even run.I think we should render
+error.sveltein that case.Miniontoby commentedon Apr 23, 2026
Because THIS was the response from the request, I expected the message value to be shown in form.message
But nope, it does NOT render the +error.svelte, it shows completely nothing to the user/frontend. Not even to the backend.
Only when I open the console, I saw the error
fix: render the nearest error page when a form submission receives a …