fix(transporte): allow phone/whatsapp as identifier in send-otp and verify-otp
This commit is contained in:
parent
1c1efef474
commit
9f6253eb04
@ -81,20 +81,23 @@ const server = http.createServer(async (req, res) => {
|
||||
// 1.1. Autenticación: Enviar OTP de seguridad por WhatsApp & Email
|
||||
if (pathname === '/api/auth/send-otp' && req.method === 'POST') {
|
||||
const body = await getJsonBody();
|
||||
if (!body.identifier) {
|
||||
const identifier = body.identifier || body.phone || body.whatsapp;
|
||||
if (!identifier) {
|
||||
return sendJson(400, { success: false, error: 'Se requiere número de WhatsApp o identificador' });
|
||||
}
|
||||
const result = await authService.sendOtp(body.identifier, body.email);
|
||||
const result = await authService.sendOtp(identifier, body.email);
|
||||
return sendJson(result.success ? 200 : 400, result);
|
||||
}
|
||||
|
||||
// 1.2. Autenticación: Validar OTP de 6 dígitos e iniciar sesión / registro
|
||||
if (pathname === '/api/auth/verify-otp' && req.method === 'POST') {
|
||||
const body = await getJsonBody();
|
||||
if (!body.identifier || !body.code) {
|
||||
const identifier = body.identifier || body.phone || body.whatsapp;
|
||||
const code = body.code || body.otp;
|
||||
if (!identifier || !code) {
|
||||
return sendJson(400, { success: false, error: 'Identificador y código OTP requeridos' });
|
||||
}
|
||||
const result = await authService.verifyOtp(body);
|
||||
const result = await authService.verifyOtp({ ...body, identifier, code });
|
||||
return sendJson(result.success ? 200 : 400, result);
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user