Skip to content

Restfit 1.0.4

Choose a tag to compare

@kyree-henry kyree-henry released this 08 Nov 17:33
· 15 commits to main since this release

Bug Fixes

Fixed Authorization Function Type Support

  • Issue: Authorization functions that return null or check authentication status were causing TypeScript compilation errors.
  • Fix: Updated ApiServiceConfig.authorization type to accept string | null | Promise<string | null>, allowing authorization functions to return null when the user is not authenticated.
  • Behavior: When an authorization function returns null or an empty string, the Authorization header is now automatically omitted from the request, preventing invalid authorization headers from being sent.

Example Usage:

const apiService = createApiService(MyService, {
  baseUrl: 'https://api.example.com',
  authorization: async () => {
    const isAuthenticated = true;
    if (isAuthenticated) {
      return await action.getAccessToken();
    }
    return null; // ✅ Now works correctly - no auth header will be added
  },
  authorizationType: 'Bearer'
});

Technical Details

  • Authorization functions can now safely return null without TypeScript errors
  • Empty strings are also handled and will skip authorization header addition
  • Backward compatible with existing string and function-based authorization configurations

Full Changelog: v1.0.3...v1.0.4