summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorojacobson <ojacobson@noreply.codeberg.org>2025-07-09 01:21:01 +0200
committerojacobson <ojacobson@noreply.codeberg.org>2025-07-09 01:21:01 +0200
commit948ecc916050a68c2e2ae7f0ddbc56a90db4785f (patch)
treef302b9b489a54a860e67084ac0116bfbd888a245
parent4eb0cc56696a3805538e5ce6d380ea26e097424c (diff)
parent1286754681cf37a5a01a6a2fcef0fa4a99cc65a9 (diff)
Stop sending `{}` to the `/api/auth/login` endpoint when the login form hasn't been touched.
Steps to reproduce: **Note**: You will need to watch the traffic in a DOM inspector; this has no user-observable symptoms because there's presently no error reporting for the login form. 1. In a new private tab, visit the `/login` page of a Pilcrow instance. 2. **Without touching the username or password fields**, click `sign in`. The client _should_ send a request to `/api/auth/login` with the following payload: ```json { "name": "", "password": "" } ``` However, it instead sends an empty payload, leading to a 422 Unprocessable Content response as the request is missing required fields. Subsequent requests, or any request after the user enters data in the input fields, are correctly serialized. Merges login-form-nulls into main.
-rw-r--r--ui/lib/components/LogIn.svelte4
-rw-r--r--ui/tests/lib/components/LogIn.svelte.test.js7
2 files changed, 9 insertions, 2 deletions
diff --git a/ui/lib/components/LogIn.svelte b/ui/lib/components/LogIn.svelte
index c49ea3b..b491583 100644
--- a/ui/lib/components/LogIn.svelte
+++ b/ui/lib/components/LogIn.svelte
@@ -1,8 +1,8 @@
<script>
let { legend = 'sign in', logIn = async (username, password) => {} } = $props();
- let username = $state();
- let password = $state();
+ let username = $state('');
+ let password = $state('');
let disabled = $state(false);
async function onsubmit(event) {
diff --git a/ui/tests/lib/components/LogIn.svelte.test.js b/ui/tests/lib/components/LogIn.svelte.test.js
index 00abb5c..0835870 100644
--- a/ui/tests/lib/components/LogIn.svelte.test.js
+++ b/ui/tests/lib/components/LogIn.svelte.test.js
@@ -31,4 +31,11 @@ describe('LogIn', async () => {
'my very creative and long password',
);
});
+
+ it('sends empty strings before being populated', async () => {
+ const signIn = screen.getByRole('button');
+ await user.click(signIn);
+
+ expect(mocks.logIn).toHaveBeenCalledExactlyOnceWith('', '');
+ });
});