npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@auth-strategy-manager/rest

v2.0.3

Published

REST API strategy for auth-strategy-manager

Downloads

65

Readme

@auth-strategy-manager/rest

REST API strategy for auth-strategy-manager. v2 aligns with @auth-strategy-manager/core ^2.0.0.

Documentation in other languages

Installation

npm install @auth-strategy-manager/rest @auth-strategy-manager/core axios

Use core 2.x with rest 2.x.

Usage

RestStrategy performs HTTP calls and builds AuthManagerData from responses using getToken. Persisting tokens and strategy name is done by AuthStrategyManager + AuthStorageManager from @auth-strategy-manager/core — not by this class.

import { AuthStrategyManager } from '@auth-strategy-manager/core';
import { RestStrategy } from '@auth-strategy-manager/rest';
import axios, { type AxiosRequestConfig } from 'axios';

const axiosInstance = axios.create({
  baseURL: 'https://api.example.com',
  timeout: 5000,
});

const restStrategy = new RestStrategy({
  name: 'my-rest',
  signInUrl: '/login',
  axiosInstance,
  getToken: (response, options) => {
    const data = (response as { data?: { access?: string; refresh?: string } }).data;
    if (options?.type === 'refresh') return data?.refresh ?? '';
    return data?.access ?? '';
  },
  checkAuth: { url: '/auth/me', method: 'GET' },
  signIn: { url: '/auth/login', method: 'POST' },
  signUp: { url: '/auth/register', method: 'POST' },
  refresh: { url: '/auth/refresh', method: 'POST' },
  // signOut omitted → RestStrategy.signOut() is a no-op; AuthStrategyManager still clears storage
});

const authManager = new AuthStrategyManager([restStrategy]);

await restStrategy.signIn<unknown, AxiosRequestConfig>({
  data: { email: '[email protected]', password: 'secret' },
});

const state = await authManager.checkAuth();
await authManager.signOut();

With a server sign-out endpoint:

const restStrategy = new RestStrategy({
  // ...same as above
  signOut: { url: '/auth/logout', method: 'POST' },
});

Configuration

RestConfig (Config)

Exported as RestConfig from this package.

import type { AxiosInstance, AxiosRequestConfig } from 'axios';

type UrlName = 'checkAuth' | 'signIn' | 'signUp' | 'signOut' | 'refresh';

type UrlConfig = {
  url: string;
  method?: AxiosRequestConfig['method'];
};

type RestConfig = Partial<Record<UrlName, UrlConfig>> & {
  name?: string;
  /** Redirect target for the sign-in page (app use) */
  signInUrl?: string;
  axiosInstance?: AxiosInstance;
  /** Map API responses to access / refresh strings */
  getToken?: (
    response: unknown,
    options?: { url?: string; type: 'access' | 'refresh' },
  ) => string;
  /**
   * Optional auth state extractor (cookie-only / BFF).
   * Use when your backend session is stored in HTTP-only cookies and API responses intentionally contain no tokens.
   */
  getIsAuthenticated?: (response: unknown, options?: { url?: string }) => boolean;
};

All URL entries are optional in the type — pass only what you call. Runtime methods still throw if a required URL for that operation is missing (e.g. signIn without signIn in config).

Parameters

| Field | Description | |--------|-------------| | checkAuth | Request used by checkAuth(). | | signIn | Request used by signIn(). | | signUp | Request used by signUp(). | | signOut | Optional. If omitted (or empty url), signOut() does not call the network; use AuthStrategyManager.signOut() to clear storage. | | refresh | Request used by refreshToken(). | | name | Strategy id (default: 'rest'). | | signInUrl | Optional app URL for the login screen. | | axiosInstance | Optional axios instance (default: axios.create()). | | getToken | Optional extractor; if missing, tokens in AuthManagerData stay empty unless you merge them yourself. | | getIsAuthenticated | Optional cookie-only extractor: return true for authenticated responses even when tokens are empty. |

API

RestStrategy

Constructor

constructor(config: RestConfig)

Methods

  • checkAuth(): Promise<AuthManagerData> — requires checkAuth URL. With AuthStrategyManager, checkAuth may be skipped when the class name stays RestStrategy and the refreshToken slot is only localStorage/sessionStorage and empty (access is not part of that check) — see core checkAuth docs.
  • signIn<T, D>(config?: D): Promise<T> — requires signIn URL; merges response with AuthManagerData.
  • signUp<T, D>(config?: D): Promise<T> — if signUp URL is missing in config, returns an unauthenticated AuthManagerData placeholder (no-op); otherwise merges response with AuthManagerData.
  • signOut(): Promise<void> — calls signOut URL when configured; otherwise no-op.
  • refreshToken(): Promise<AuthManagerData> — requires refresh in config; coalesces concurrent refresh calls.

Properties

  • name: string
  • axiosInstance: AxiosInstance
  • urls: Partial<Record<UrlName, UrlConfig>>
  • getToken? — same as config
  • signInUrl?: string
  • startUrl — get/set string (in-memory on the instance)

AuthManagerData shape

Matches @auth-strategy-manager/core (returned from checkAuth / refreshToken / merged into signIn / signUp results):

type AuthManagerData = {
  isAuthenticated: boolean;
  strategyName: string;
  accessToken: string;
  refreshToken?: string;
};

Token persistence

RestStrategy does not read or write localStorage / sessionStorage. Configure AuthStorageManager on AuthStrategyManager in core so tokens and flags match your app.

License

ISC