Repository navigation
Restfit 1.0.4
Bug Fixes
Fixed Authorization Function Type Support
- Issue: Authorization functions that return
nullor check authentication status were causing TypeScript compilation errors. - Fix: Updated
ApiServiceConfig.authorizationtype to acceptstring | null | Promise<string | null>, allowing authorization functions to returnnullwhen the user is not authenticated. - Behavior: When an authorization function returns
nullor 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
nullwithout 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