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

    Module Auth Utilities

    Authentication Utilities for Sovereign Node Operations

    This module provides comprehensive JWT token management and password security utilities for the WayrApp platform's authentication system. It serves as the core authentication infrastructure supporting user login, token refresh, password hashing, and security validation across the entire application.

    The module implements industry-standard security practices including JWT token generation with configurable expiration times, bcrypt password hashing with salt rounds, token format validation, expiration checking, and secure random token generation. All functions are designed to work seamlessly with the authentication middleware and controllers to provide a robust, secure authentication system.

    This utility module is extensively used by the AuthController for user authentication operations, the authentication middleware for token verification, and various other components throughout the application that require secure token handling and password management capabilities.

    Exequiel Trujillo

    1.0.0

    // Generate token pair for user authentication
    import { generateTokenPair } from '@/shared/utils/auth';

    const tokenPayload = {
    userId: 'user-uuid-123',
    email: 'user@example.com',
    role: 'student'
    };

    const tokens = generateTokenPair(tokenPayload);
    console.log(tokens.accessToken); // Short-lived JWT for API requests
    console.log(tokens.refreshToken); // Long-lived JWT for token renewal
    // Password hashing and verification
    import { hashPassword, comparePassword } from '@/shared/utils/auth';

    // Hash password during registration
    const hashedPassword = await hashPassword('userPassword123!');

    // Verify password during login
    const isValid = await comparePassword('userPassword123!', hashedPassword);
    console.log(isValid); // true
    // Token validation and extraction
    import { extractTokenFromHeader, validateTokenFormat, isTokenExpired } from '@/shared/utils/auth';

    const authHeader = 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
    const token = extractTokenFromHeader(authHeader);

    if (token && validateTokenFormat(token) && !isTokenExpired(token)) {
    // Token is valid and not expired
    console.log('Token is ready for verification');
    }

    Interfaces

    TokenPair
    TokenPayload

    Functions

    generateAccessToken
    generateRefreshToken
    generateTokenPair
    verifyRefreshToken
    hashPassword
    comparePassword
    extractTokenFromHeader
    validateTokenFormat
    isTokenExpired
    getTokenExpiration
    generateSecureToken