WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Module authRoutes

    Authentication Routes Module for WayrApp Platform

    This module defines and configures all authentication-related HTTP routes for the WayrApp language learning platform. It serves as the primary entry point for user authentication operations including registration, login, token refresh, logout, and user profile retrieval. The module integrates comprehensive security measures, input validation, rate limiting, and error handling to provide a robust authentication system.

    The authentication routes follow RESTful conventions and implement security practices including JWT token-based authentication, bcrypt password hashing, request validation using Zod schemas, and rate limiting to prevent abuse. All routes are designed to work seamlessly with the frontend applications and provide consistent API responses with proper error handling.

    This module is a critical component of the application's security infrastructure, handling sensitive operations like user registration and authentication. It integrates with the AuthController for business logic, authentication middleware for security, validation middleware for input sanitization, and rate limiting middleware for abuse prevention. The routes are mounted at /api/v1/auth in the main application and serve both web and mobile client applications.

    Factory function that creates authentication routes.

    Express router configuration for user authentication endpoints.

    Exequiel Trujillo

    1.0.0

    // Import and mount authentication routes in main application
    import { createAuthRoutes } from '@/modules/users/routes/authRoutes';
    import express from 'express';

    const app = express();
    // authController is created in the dependency injection container
    app.use('/api/v1/auth', createAuthRoutes(authController));
    // Available authentication endpoints:
    // POST /api/v1/auth/register - User registration
    // POST /api/v1/auth/login - User login
    // POST /api/v1/auth/refresh - Token refresh
    // POST /api/v1/auth/logout - User logout (requires authentication)
    // GET /api/v1/auth/me - Get current user info (requires authentication)
    // Client usage example for user registration
    const response = await fetch('/api/v1/auth/register', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
    email: 'user@example.com',
    password: 'SecurePass123!',
    username: 'learner123'
    })
    });
    const { user, tokens } = await response.json();

    Functions

    createAuthRoutes