@emmert/auth-client
v0.22.0
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 response = await [...code to fetch token here...]
return {
accessToken: response.accessToken,
refreshToken: response.refreshToken
}
},
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();