fix(sim-auth): always send signup name and validate credentials
This commit is contained in:
@@ -147,11 +147,17 @@
|
||||
});
|
||||
};
|
||||
|
||||
const getAuthPayload = () => ({
|
||||
name: $('authName').value.trim() || undefined,
|
||||
email: $('authEmail').value.trim(),
|
||||
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 }),
|
||||
|
||||
Reference in New Issue
Block a user