Bear auth contains a set of methods for managing JWT tokens in single page applications.
- 🪶 Ultra-light
@bear-auth/core
: 4.6 kB (min + gzip)@bear-auth/react
: 0.55 kB (min + gzip)@bear-auth/storage
: 0.44 kB (min + gzip)
- ♻️ Auto access token refreshment
- If the
authenticate
method returns validexpiration
andrefreshToken
, the@bear-auth/core
will use the refresh token hook to maintain fresh access token.
- If the
- 🛜 Network status detection
- To avoid refreshing access token while the app is offline.
- By default it uses
navigator.onLine
flag and theonline
event but can be changed via thesetContinueWhenOnline
method.
- 🏗️ Highly customizable
- You can override almost all the default behaviour – storage, network, etc.
- 💨 Tree-shakeable & side-effect free
- The API has been designed as pure functions (rather than one heavy object) to support tree-shaking.
- 🙈 Framework agnostic
- The
@bear-auth/core
consists of just (promised-based) TypeScript vanilla methods. No attachment to library/framework. - There is currently one official integration for React but others can be easily implemented.
- The
- ✅ Strongly typed
- ✨ Multiple instances per origin
- 👨🚒 Custom error & guard functions for easier error handling
isBearAuthError(error: unknown): error is BearAuthError
isBearAuthError(error: unknown, ['bear-auth/retrieve-auth-session-failed']): error is BearAuthError<'bear-auth/retrieve-auth-session-failed'>