Axios interceptor library for automatic JWT token storage, transmission, and refresh. Current stable version 4.0.3 (released Oct 2023), actively maintained. Supports both web (localStorage/sessionStorage) and React Native (AsyncStorage). Key differentiator: parses JWT expiration to proactively refresh before every request, preventing 401 errors. Requires explicit token refresh function provided by user, supports rotating refresh tokens. ESM/CJS compatible, ships TypeScript types. Peer dependencies: @react-native-async-storage/async-storage (React Native only) and axios ^1.4.0.
npm install axios-jwtNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates setup of axios-jwt interceptor with token refresh, login, and logout functions.
Use the global axios client or a different axios instance inside the requestRefresh function to avoid infinite loops.
Update to use getBrowserLocalStorage or provide custom storage implementation.
Pass getBrowserLocalStorage for web, or create a custom storage for React Native.
Ensure your access token is a valid JWT with expiration. The library will not refresh if exp is missing.
Implement error handling inside requestRefresh, e.g., redirect to login on failure.
Ensure requestRefresh returns a string (accessToken) or IAuthTokens object with accessToken property.
Import getBrowserLocalStorage from 'axios-jwt' and pass it in config: { requestRefresh, getStorage: getBrowserLocalStorage }Call setAuthTokens after successful login, or check isLoggedIn() before attempting to get tokens.