Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JuseAR27/Unisierra-eats/llms.txt

Use this file to discover all available pages before exploring further.

UniSierra Eats does not use JWTs or server-side cookies. Instead, the server returns a plain user object on successful login, and the frontend stores it as JSON in the browser’s localStorage under the key unisierra_sesion. Every page checks this key on load to decide what UI to show — authenticated nav, profile links, admin controls, or the public login/register buttons.

Session Object Structure

After a successful login the object stored in localStorage has the following shape:
{
  "id": 1,
  "nombre": "Ana López",
  "correo": "ana.lopez@unisierra.edu.mx",
  "rol_id": 2
}
FieldTypeDescription
idIntegerPrimary key of the user in the Usuarios table
nombreStringFull display name
correoStringInstitutional email address
rol_idInteger1 = Administrador, 2 = Estudiante

Registration

Registration fails immediately if the email address does not end in @unisierra.edu.mx. The server returns HTTP 400 with { "error": "Solo se permite el registro con correos institucionales (@unisierra.edu.mx)." }.
Endpoint: POST /api/registro Request body:
{
  "nombre": "Ana López",
  "correo": "ana.lopez@unisierra.edu.mx",
  "password": "mypassword123"
}
Success response (200 OK):
{
  "mensaje": "Usuario registrado con éxito",
  "id": 7
}
The email must be unique. If it already exists, the server returns HTTP 400 with { "error": "Error al registrar: Es posible que el correo ya esté en uso." }. Example fetch call (from app.js):
const res = await fetch('/api/registro', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        nombre: 'Ana López',
        correo: 'ana.lopez@unisierra.edu.mx',
        password: 'mypassword123'
    })
});
const data = await res.json();

if (res.ok) {
    alert("¡Registro exitoso! Ahora puedes iniciar sesión.");
} else {
    alert(data.error || "Error al registrar");
}

Login

Endpoint: POST /api/login Request body:
{
  "correo": "ana.lopez@unisierra.edu.mx",
  "password": "mypassword123"
}
Success response (200 OK):
{
  "mensaje": "Inicio de sesión exitoso",
  "usuario": {
    "id": 7,
    "nombre": "Ana López",
    "correo": "ana.lopez@unisierra.edu.mx",
    "rol_id": 2
  }
}
Error response (401 Unauthorized):
{
  "error": "Correo o contraseña incorrectos"
}

Login Examples

Students have rol_id === 2. After login the session is saved and the page reloads to reveal the authenticated nav bar.
const res = await fetch('/api/login', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
        correo: 'ana.lopez@unisierra.edu.mx',
        password: 'mypassword123'
    })
});
const data = await res.json();

if (res.ok) {
    // Persist session to localStorage
    localStorage.setItem('unisierra_sesion', JSON.stringify(data.usuario));

    // Students stay on the public site
    window.location.reload();
} else {
    alert(data.error || "Error al iniciar sesión");
}

Role-Based Redirect

Once data.usuario is received, app.js inspects rol_id to decide where to send the user:
rol_idRoleRedirect destination
1Administradoradmin/panel_admin.html
2EstudianteCurrent page reload (stays on public site)
if (data.usuario.rol_id === 1) {
    window.location.href = '../admin/panel_admin.html';
} else {
    window.location.reload();
}

Logout

Logout is entirely client-side: the session key is removed from localStorage and the user is sent back to the landing page.
localStorage.removeItem('unisierra_sesion');
window.location.href = 'index.html';
This is wired to the Salir button rendered in the nav bar whenever a session is detected.

Admin Registration

A separate endpoint registers a user with rol_id = 1 (Administrador). It accepts the same fields as the student registration endpoint. Endpoint: POST /api/admin/registro Request body:
{
  "nombre": "Carlos Admin",
  "correo": "carlos.admin@unisierra.edu.mx",
  "password": "securepassword"
}
Success response (200 OK):
{
  "message": "Nuevo administrador registrado con éxito."
}
The admin registration response uses the key message (English), while most other endpoints use mensaje (Spanish). This is an intentional difference in the source code.
The same @unisierra.edu.mx domain restriction applies. If the email already exists the server returns HTTP 400.
Passwords are stored in plaintext in the SQLite database. UniSierra Eats is a demo application and is not intended for production use with real credentials. Do not reuse passwords from other services.

Build docs developers (and LLMs) love