@emmert/jwt-client
v0.2.17
Published
JWT Token Management
Downloads
6
Readme
Auth Client
Tools for managing client-side authentication.
Features
- Store tokens in localStorage for later use even after browser refresh
- Automatically try to refresh 3 times before automatically logging the user out
- Automatically refresh auth tokens on a regular basis to keep them fresh
Installation
NPMnpm install @emmert/auth-client
Yarnyarn add @emmert/auth-client
Configuration & Setup
import { AuthClient } from "@emmert/auth-client";
const client = new AuthClient({
getNewToken: async (refreshToken) => {
const token = await [...code to fetch token here...]
},
onLogout: (reason: LogoutReason) => {
...handle logout here
},
onError:(e) => {
...log errors here
}
});
Reference
Load a new token
client.load();
Start polling for a new token on an interval
client.startPolling(10 * 60 * 1000); // Get a new token ever 10 minutes
Manually stop polling
client.stopPolling();