Skip to main content

Overview

The Usuario model represents a user entity in the Karma Ecommerce system. It contains the core authentication credentials and user identification information. This model is used throughout the authentication flow, including user registration and login operations.

TypeScript Interface

export interface Usuario {
    id: number,
    usuario: string,
    contrasena: string
}

Fields

id
number
required
Unique identifier for the user. This is typically auto-generated by the backend database.
usuario
string
required
Username for authentication. This serves as the user’s unique identifier for login purposes.
contrasena
string
required
User’s password for authentication. This should be stored securely (hashed) in the backend.

JSON Representation

{
  "id": 1,
  "usuario": "john_doe",
  "contrasena": "hashed_password_here"
}

Usage Example

User Login

import { Usuario } from './domain/models/usuario';

// Login response
const loggedInUser: Usuario = {
  id: 123,
  usuario: "jane_smith",
  contrasena: "encrypted_password"
};

User Registration

// Registration payload
const newUser = {
  usuario: "new_user",
  contrasena: "secure_password"
};

// Registration response includes the ID
const registeredUser: Usuario = {
  id: 456,
  usuario: "new_user",
  contrasena: "hashed_password"
};

UsuarioRepository

The UsuarioRepository abstract class defines the contract for user data operations:
abstract class UsuarioRepository {
  abstract loginUsuario(usuario: string, contrasena: string): Observable<Usuario>;
  abstract registrarUsuario(usuario: string, contrasena: string): Observable<Usuario>;
}
Both methods return an Observable<Usuario>, making the Usuario model the core response type for authentication operations.

AuthService

The AuthService implements the UsuarioRepository interface and handles HTTP communication with the authentication backend:
  • Login: GET /login/{usuario}/{contrasena} returns a Usuario object
  • Registration: POST /registro with credentials returns a Usuario object

Security Considerations

The contrasena field should never be stored in plain text. Always ensure passwords are properly hashed on the backend before storage. When transmitting credentials, use HTTPS to protect sensitive data in transit.

Source Code

The Usuario model is defined in:
  • Location: src/app/usuario/domain/models/usuario.ts
  • Repository: View on GitHub

See Also

Build docs developers (and LLMs) love