Skip to content

Bear auth contains a set of methods for managing JWT tokens in single page application.

License

Notifications You must be signed in to change notification settings

AckeeCZ/bear-auth

Repository files navigation

🐻 Bear Auth

Bear auth contains a set of methods for managing JWT tokens in single page applications.

Features

  • 🪶 Ultra-light
  • ♻️ Auto access token refreshment
    • If the authenticate method returns expiresIn and refreshToken, the @bear-auth/core will use the refresh token hook to maintain fresh access token.
  • 🛜 Network status detection
    • To avoid refreshing access token while the app is offline.
    • By default it uses navigator.onLine flag and the online event but can be changed via the setContinueWhenOnline 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.
  • 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'>

Packages

Examples