@emmert/auth-client
TypeScript icon, indicating that this package has built-in type declarations

0.22.0 • Public • Published

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

NPM
npm install @emmert/auth-client

Yarn
yarn 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();

Readme

Keywords

none

Package Sidebar

Install

npm i @emmert/auth-client

Weekly Downloads

0

Version

0.22.0

License

MIT

Unpacked Size

40.2 kB

Total Files

21

Last publish

Collaborators

  • paco3346
  • robbyemmert