0.22.0 • Published 4 years ago

@emmert/auth-client v0.22.0

Weekly downloads
20
License
MIT
Repository
-
Last release
4 years ago

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();
0.22.0

4 years ago

0.21.0

4 years ago

0.20.0

5 years ago

0.19.0

5 years ago

0.18.0

5 years ago

0.17.0

5 years ago

0.16.0

5 years ago

0.15.0

5 years ago

0.14.0

5 years ago

0.13.0

5 years ago

0.12.0

5 years ago

0.11.0

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.1

5 years ago

0.3.0

5 years ago

0.2.21

5 years ago

0.2.19

5 years ago

0.2.20

5 years ago

0.2.18

5 years ago