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

    Function validateTokenFormat

    • Validate JWT token format and structure without verification

      Performs basic structural validation of a JWT token without cryptographic verification. Checks that the token has the correct three-part format (header.payload.signature) and contains required JWT claims in the header and payload sections.

      This function is useful for quick format validation before attempting expensive cryptographic verification. It helps filter out obviously malformed tokens and provides early validation in authentication flows.

      Parameters

      • token: string

        JWT token string to validate

      Returns boolean

      True if token has valid JWT structure, false otherwise

      // Validate token format before verification
      const token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
      const isValidFormat = validateTokenFormat(token);

      if (isValidFormat) {
      // Proceed with cryptographic verification
      const decoded = jwt.verify(token, secret);
      } else {
      console.log('Invalid token format');
      }
      // Examples of validation results
      validateTokenFormat('invalid.token'); // false (only 2 parts)
      validateTokenFormat('not.a.jwt.token'); // false (4 parts)
      validateTokenFormat('valid.jwt.token'); // true (if properly formatted)