fix(auth): keep the typed email when the sign-in form shows an error - #77
Merged
ralyodio merged 1 commit intoJul 30, 2026
Merged
Conversation
The email field renders a value attribute so a visitor does not have to retype their address, but it read req.query.email. Every path that re-renders this page with an error is a POST, so the address is in the body: a wrong password, a password under 8 characters, an email that already has an account and a malformed email all came back with the field blank. Read the submitted body first and fall back to the query string, so an existing /?email=... link still prefills the field.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
authPage()inapps/pwa/src/routes/auth.mjsrenders the email input with avalueso a visitor does not have to type their address again. It reads that value fromreq.query.email.Every path that re-renders this page with an error is a POST, so the address is in
req.body, not the query string. All four error paths come back with the field blank:So mistyping your password on sign-in costs you your email address too.
Repro
Run against unmodified
main(df9d1e0), realauthRouter+ real libsql file db, no fault injection:The fix
Read the submitted body first, fall back to the query string:
The
/?email=...prefill keeps working, and the value still goes throughesc().Tests
New
apps/pwa/test/auth-form-email.test.mjs, 3 tests, same throwaway-libsql + skip-guard shape aslogout-csrf.test.mjs:valueattribute - now that submitted input is echoed,a\"><script>alert(1)</script><input x=\"round-trips through the field with no markup escaping it/?email=...still prefills, an empty form is empty (not\"undefined\"), and correct credentials still 302Stash-verified by reverting only the source change: 2 fail / 1 pass unpatched, 3/3 patched. The control passes both ways, so it is not vacuous.
Suites:
apps/pwa30 -> 33, rootnpm test204 -> 207, 0 failures before and after.Note for test 2: the assertion decodes HTML entities before comparing, because a browser decodes the attribute before submitting it. Comparing raw markup would measure the escaping instead of what reaches the server.