fix(sim-auth): always send signup name and validate credentials
This commit is contained in:
@@ -147,11 +147,17 @@
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAuthPayload = () => ({
|
const getAuthPayload = () => {
|
||||||
name: $('authName').value.trim() || undefined,
|
const email = $('authEmail').value.trim();
|
||||||
email: $('authEmail').value.trim(),
|
const explicitName = $('authName').value.trim();
|
||||||
password: $('authPassword').value,
|
const inferredName = email.includes('@') ? email.split('@')[0] : email;
|
||||||
});
|
|
||||||
|
return {
|
||||||
|
name: explicitName || inferredName || 'SecureCam User',
|
||||||
|
email,
|
||||||
|
password: $('authPassword').value,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const connectSocket = () => {
|
const connectSocket = () => {
|
||||||
if (!state.deviceToken) throw new Error('Register device first');
|
if (!state.deviceToken) throw new Error('Register device first');
|
||||||
@@ -227,9 +233,18 @@
|
|||||||
|
|
||||||
$('signUpBtn').addEventListener('click', async () => {
|
$('signUpBtn').addEventListener('click', async () => {
|
||||||
try {
|
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', {
|
const payload = await authFetch('/api/auth/sign-up/email', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(getAuthPayload()),
|
body: JSON.stringify(authPayload),
|
||||||
});
|
});
|
||||||
log('sign up', payload);
|
log('sign up', payload);
|
||||||
$('sessionBtn').click();
|
$('sessionBtn').click();
|
||||||
@@ -241,6 +256,10 @@
|
|||||||
$('signInBtn').addEventListener('click', async () => {
|
$('signInBtn').addEventListener('click', async () => {
|
||||||
try {
|
try {
|
||||||
const authPayload = getAuthPayload();
|
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', {
|
const payload = await authFetch('/api/auth/sign-in/email', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify({ email: authPayload.email, password: authPayload.password }),
|
body: JSON.stringify({ email: authPayload.email, password: authPayload.password }),
|
||||||
|
|||||||
Reference in New Issue
Block a user