From 04e7d0779ae2a5e847c600006284f7c18b98ffeb Mon Sep 17 00:00:00 2001 From: Matiss Jurevics Date: Fri, 30 Jan 2026 10:20:00 +0000 Subject: [PATCH] fix(sim-auth): always send signup name and validate credentials --- Backend/public/mobile-sim.js | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/Backend/public/mobile-sim.js b/Backend/public/mobile-sim.js index c6339f9..3fd0e5b 100644 --- a/Backend/public/mobile-sim.js +++ b/Backend/public/mobile-sim.js @@ -147,11 +147,17 @@ }); }; - const getAuthPayload = () => ({ - name: $('authName').value.trim() || undefined, - email: $('authEmail').value.trim(), - password: $('authPassword').value, - }); + const getAuthPayload = () => { + const email = $('authEmail').value.trim(); + const explicitName = $('authName').value.trim(); + const inferredName = email.includes('@') ? email.split('@')[0] : email; + + return { + name: explicitName || inferredName || 'SecureCam User', + email, + password: $('authPassword').value, + }; + }; const connectSocket = () => { if (!state.deviceToken) throw new Error('Register device first'); @@ -227,9 +233,18 @@ $('signUpBtn').addEventListener('click', async () => { try { + const authPayload = getAuthPayload(); + if (!authPayload.email || !authPayload.password) { + throw new Error('Email and password are required'); + } + + if (authPayload.password.length < 8) { + throw new Error('Password must be at least 8 characters'); + } + const payload = await authFetch('/api/auth/sign-up/email', { method: 'POST', - body: JSON.stringify(getAuthPayload()), + body: JSON.stringify(authPayload), }); log('sign up', payload); $('sessionBtn').click(); @@ -241,6 +256,10 @@ $('signInBtn').addEventListener('click', async () => { try { const authPayload = getAuthPayload(); + if (!authPayload.email || !authPayload.password) { + throw new Error('Email and password are required'); + } + const payload = await authFetch('/api/auth/sign-in/email', { method: 'POST', body: JSON.stringify({ email: authPayload.email, password: authPayload.password }),