Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com>

Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.github.com>
Co-authored-by: eddgranados12 <eddgranados12@users.noreply.github.com>

implementacion de login, vistas, correcion de errores en vista registro, domicilios
This commit is contained in:
shinra32
2026-05-22 23:07:24 -06:00
parent b4ee3e7b49
commit c91b6e2091
52 changed files with 3940 additions and 4368 deletions

View File

@@ -26,33 +26,44 @@ def register(body: RegisterRequest):
if not body.email and not body.phone:
raise HTTPException(status_code=400, detail="Se requiere email o teléfono")
if len(body.password) < 6:
raise HTTPException(status_code=400, detail="La contraseña debe tener al menos 6 caracteres.")
try:
if body.email:
resp = supabase.auth.sign_up({"email": body.email, "password": body.password})
else:
resp = supabase.auth.sign_up({"phone": body.phone, "password": body.password})
except Exception as e:
raise HTTPException(status_code=400, detail=str(e))
error_msg = str(e)
if "already registered" in error_msg.lower() or "user already exists" in error_msg.lower():
raise HTTPException(status_code=400, detail="El usuario ya está registrado en el sistema de autenticación.")
if "signups are disabled" in error_msg.lower():
raise HTTPException(status_code=400, detail="El registro de nuevos usuarios está deshabilitado temporalmente.")
if "rate limit" in error_msg.lower():
raise HTTPException(status_code=400, detail="Límite de registros excedido por seguridad. Desactiva la confirmación de correos en Supabase o intenta más tarde.")
raise HTTPException(status_code=400, detail=error_msg)
auth_user = resp.user
if not auth_user:
raise HTTPException(status_code=400, detail="No se pudo crear el usuario en Supabase Auth")
# Crear entrada en public.users con el rol elegido
supabase_admin.table("users").upsert(
{
"id": str(auth_user.id),
"email": body.email,
"phone": body.phone,
"role": body.role,
}
).execute()
try:
supabase_admin.table("users").upsert(
{
"id": str(auth_user.id),
"role": body.role,
}
).execute()
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error al guardar el usuario: {e}")
# Si no hubo sesión (email confirmation pendiente) devolvemos token vacío con aviso
# Si no hubo sesión (email confirmation pendiente)
if not resp.session:
raise HTTPException(
status_code=202,
detail="Cuenta creada. Confirma tu email antes de iniciar sesión.",
status_code=400,
detail="Cuenta creada. Revisa tu correo para confirmar tu email antes de iniciar sesión.",
)
return TokenResponse(