@ackplus/nest-auth-client

NestJS authentication for REST APIs
20,047 4
Install
npm install @ackplus/nest-auth-client
Latest Version:2.14.0
License:MIT
Last Updated:Oct 12, 2026
Links: GitHub  ·  npm
Maintainer: ckhandla94

@ackplus/nest-auth-client

npm version npm downloads license

Framework-agnostic JavaScript/TypeScript client for @ackplus/nest-auth. Zero peer dependencies. Works anywhere modern JS runs — browsers, Node 18+, React Native, Cloudflare Workers, Deno, Bun.

📚 Full documentation: ack-solutions.github.io/nest-auth/docs/client


Why use it

The official client for the @ackplus/nest-auth backend. Use it directly from Vue, Angular, Svelte, vanilla JS, or as the foundation under @ackplus/nest-auth-react.

It handles the parts of auth that are tedious to write by hand: token persistence, automatic refresh on 401 with concurrent-request deduplication, cookie/header mode switching, MFA flows, multi-tenant context, and an event subscription API.

Install

pnpm add @ackplus/nest-auth-client

No peer dependencies. TypeScript definitions ship in the package.

Minimal example

import { AuthClient } from '@ackplus/nest-auth-client';

const auth = new AuthClient({
  baseUrl: 'https://api.example.com',
});

await auth.signup({
  email: 'alice@example.com',
  password: 'correct horse battery staple',
  firstName: 'Alice',     // any extra field flows through to UserRegisteredEvent
});

await auth.login({
  credentials: { email: 'alice@example.com', password: 'correct horse battery staple' },
});

if (auth.getIsAuthenticated()) {
  const user = await auth.getSessionUserData();
  console.log('Hello', user.email);
}

What's included

Capability Notes
Auth flows signup, login, logout, logoutAll, refresh, passwordlessSend, switchTenant
MFA send2fa, verify2fa, setupTotp, verifyTotpSetup, getMfaStatus, recovery codes
Password management forgotPassword, verifyForgotPasswordOtp, resetPassword, changePassword
Email/phone verification sendEmailVerification, verifyEmail, sendPhoneVerification, verifyPhone
Auto-refresh 401 → refresh → retry once, with RefreshQueue deduplication so N parallel 401s only fire one refresh
Header or cookie mode accessTokenType: 'header' | 'cookie' | null (auto-detect)
Storage adapters MemoryStorage, LocalStorageAdapter, SessionStorageAdapter, CookieStorageAdapter, custom
HTTP adapters FetchAdapter (default) or createAxiosAdapter(yourAxiosInstance), custom
Events onTokensSet, onTokenRefreshed, onTokensRemoved, onLogout, onError, onSessionVerified
Utilities decodeJwt, isTokenExpired, hasRole, hasPermission, hasAnyAccess, hasAllAccess

Configuration

new AuthClient({
  baseUrl: 'https://api.example.com',
  storage: new LocalStorageAdapter('myapp_'),
  httpAdapter: new FetchAdapter(),
  accessTokenType: 'header',     // or 'cookie' or null (auto-detect)
  autoRefresh: true,
  refreshThreshold: 60,          // seconds before expiry
  onTokenRefreshed: (tokens) => { /* … */ },
  onLogout: () => { window.location.href = '/login'; },
  onError: (err) => console.error(err),
});

Full config reference →

React Native

import AsyncStorage from '@react-native-async-storage/async-storage';
import { AuthClient, type StorageAdapter } from '@ackplus/nest-auth-client';

const RNStorage: StorageAdapter = {
  get:    (k) => AsyncStorage.getItem(k),
  set:    (k, v) => AsyncStorage.setItem(k, v),
  remove: (k) => AsyncStorage.removeItem(k),
  clear:  () => AsyncStorage.clear(),
};

export const auth = new AuthClient({
  baseUrl: 'https://api.example.com',
  storage: RNStorage,
});

Documentation

Section What's there
AuthClient Every method with TS signatures and examples
Config All AuthClientConfig options
Storage Adapters Built-ins and how to write your own
HTTP Adapters Fetch (default), axios, custom
Events Subscription API
Utilities JWT helpers, role/permission checks

Companion packages

Package Use when
@ackplus/nest-auth The NestJS backend module
@ackplus/nest-auth-react React provider, hooks, guards, and Next.js App Router helpers (recommended for React)
@ackplus/nest-auth-contracts Shared TS types (already a transitive dep of this package)

All four packages release together with the same version number. Pin them all to the same version.

Links

License

MIT

Related Packages

@ackplus/nest-crud-request

Framework-agnostic query builder for REST APIs - build complex queries with filt...

15,220 2
rasedi-sdk

Universal Rasedi Payment Gateway SDK for React, Vue, Angular, React Native, and...

965
auth.js

A simple authentication and authorization module for building APIs when using fr...

2,037
@propeller-commerce/propeller-sdk-v2

TypeScript GraphQL client for Propeller eCommerce V2 Platform - works with React...

8,078 1
quick-start-cli

通过Quick-start-cli可以快速搭建一个基于webpack的前端项目

4,225 53

Version History

Version Released License
2.14.0 MIT
2.13.1 MIT
2.13.0 MIT
2.12.0 MIT
2.11.1 MIT
Pre-releases (31)
Version Released License
2.0.0-beta.26 MIT
2.0.0-beta.25 MIT
2.0.0-beta.23 MIT
2.0.0-beta.22 MIT
2.0.0-beta.21 MIT