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

    Function generateTokenPair

    • Generate both access and refresh tokens as a pair

      Convenience function that creates both access and refresh tokens simultaneously using the same user payload. This is the primary function used during user authentication and token renewal operations to provide a complete token set.

      The function combines generateAccessToken and generateRefreshToken to create a TokenPair object containing both tokens, ensuring consistency in token generation and simplifying authentication workflows.

      Parameters

      • payload: TokenPayload

        User information to encode in both tokens containing userId, email, and role properties

      Returns TokenPair

      Object containing both accessToken and refreshToken

      When JWT_SECRET or JWT_REFRESH_SECRET environment variables are not configured

      // Generate complete token pair for user login
      const payload = {
      userId: 'user-uuid-123',
      email: 'user@example.com',
      role: 'content_creator'
      };

      const tokens = generateTokenPair(payload);
      console.log(tokens.accessToken); // Short-lived token for API requests
      console.log(tokens.refreshToken); // Long-lived token for renewal
      // Typical usage in authentication controller
      const authResponse = {
      user: userInfo,
      tokens: generateTokenPair(tokenPayload)
      };