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

    Module auth.schemas

    Authentication validation schemas for WayrApp Backend API

    This module provides comprehensive Zod validation schemas for all authentication-related operations in the WayrApp language learning platform. It serves as the data validation foundation for user registration, login, token management, and password operations, ensuring data integrity, security compliance, and consistent validation behavior across all authentication endpoints.

    The schemas implement industry-standard security practices including strong password requirements, email validation, and comprehensive input sanitization. They are designed to prevent common security vulnerabilities such as weak passwords, injection attacks, and malformed data processing while maintaining user-friendly error messages that guide users toward successful authentication.

    Key security features include enforced password complexity requirements with uppercase, lowercase, numeric, and special character validation, email format validation to prevent malformed addresses, username sanitization to prevent injection attacks, and comprehensive input length validation to prevent buffer overflow and denial-of-service attacks.

    The module integrates seamlessly with the Express validation middleware system, providing automatic request validation, type safety through TypeScript inference, and consistent error handling across all authentication endpoints. It supports the application's distributed architecture by ensuring consistent validation behavior across multiple nodes and services.

    All schemas are designed for high performance with minimal validation overhead, utilizing Zod's efficient parsing engine and optimized regular expressions for pattern matching. The schemas support internationalization considerations and are compatible with various authentication flows including social login integration and multi-factor authentication.

    Exequiel Trujillo

    1.0.0

    // Basic usage with validation middleware
    import { RegisterSchema, LoginSchema } from '@/shared/schemas/auth.schemas';
    import { validate } from '@/shared/middleware/validation';

    router.post('/auth/register', validate({ body: RegisterSchema }), authController.register);
    router.post('/auth/login', validate({ body: LoginSchema }), authController.login);
    // Type inference for request handlers
    import { RegisterRequest, LoginRequest } from '@/shared/schemas/auth.schemas';

    const registerUser = async (req: Request<{}, {}, RegisterRequest>) => {
    const { email, password, username } = req.body; // Fully typed
    // Registration logic here
    };
    // Manual validation in services
    import { PasswordSchema } from '@/shared/schemas/auth.schemas';

    const validatePassword = (password: string) => {
    const result = PasswordSchema.safeParse(password);
    if (!result.success) {
    throw new Error(result.error.errors[0].message);
    }
    return result.data;
    };

    Type Aliases

    RegisterRequest
    LoginRequest
    RefreshTokenRequest
    PasswordUpdateRequest

    Variables

    PasswordSchema
    RegisterSchema
    LoginSchema
    RefreshTokenBodySchema
    PasswordUpdateSchema