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

    Function generateRefreshToken

    • Generate JWT refresh token for token renewal

      Creates a long-lived JWT refresh token used to generate new access tokens without requiring user re-authentication. The token is signed with a separate JWT_REFRESH_SECRET for additional security and has a longer expiration time (default 7 days).

      Refresh tokens are stored securely by clients and used only for token renewal operations. They contain the same user information as access tokens but are designed for less frequent use and longer validity periods to balance security with user experience.

      Parameters

      • payload: TokenPayload

        User information to encode in the refresh token containing userId, email, and role

      Returns string

      Signed JWT refresh token string

      When JWT_REFRESH_SECRET environment variable is not configured

      // Generate refresh token for token renewal
      const payload = {
      userId: 'user-uuid-123',
      email: 'user@example.com',
      role: 'student'
      };

      const refreshToken = generateRefreshToken(payload);
      // Returns: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'
      // Refresh token usage in token renewal
      // Client sends refresh token to /auth/refresh endpoint
      // Server verifies refresh token and generates new token pair
      // Old refresh token can be revoked for security