@ackplus/nest-auth-client

中文文档
2.18.0发布于 2026/11/03MITTypeScriptESM + CJS近 30 天下载 2384

NestJS authentication for REST APIs

原始使用文档
文档目录10 节
  1. Why use it
  2. Install
  3. Minimal example
  4. What's included
  5. Configuration
  6. React Native
  7. Documentation
  8. Companion packages
  9. Links
  10. License

@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: '[email protected]',
  password: 'correct horse battery staple',
  firstName: 'Alice',     // any extra field flows through to UserRegisteredEvent
});

await auth.login({
  credentials: { email: '[email protected]', password: 'correct horse battery staple' },
});

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

What's included

CapabilityNotes
Auth flowssignup, login, logout, logoutAll, refresh, passwordlessSend, switchTenant
MFAsend2fa, verify2fa, setupTotp, verifyTotpSetup, getMfaStatus, recovery codes
Password managementforgotPassword, verifyForgotPasswordOtp, resetPassword, changePassword
Email/phone verificationsendEmailVerification, verifyEmail, sendPhoneVerification, verifyPhone
Auto-refresh401 → refresh → retry once, with RefreshQueue deduplication so N parallel 401s only fire one refresh
Header or cookie modeaccessTokenType: 'header' | 'cookie' | null (auto-detect)
Storage adaptersMemoryStorage, LocalStorageAdapter, SessionStorageAdapter, CookieStorageAdapter, custom
HTTP adaptersFetchAdapter (default) or createAxiosAdapter(yourAxiosInstance), custom
EventsonTokensSet, onTokenRefreshed, onTokensRemoved, onLogout, onError, onSessionVerified
UtilitiesdecodeJwt, 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

SectionWhat's there
AuthClientEvery method with TS signatures and examples
ConfigAll AuthClientConfig options
Storage AdaptersBuilt-ins and how to write your own
HTTP AdaptersFetch (default), axios, custom
EventsSubscription API
UtilitiesJWT helpers, role/permission checks

Companion packages

PackageUse when
@ackplus/nest-authThe NestJS backend module
@ackplus/nest-auth-reactReact provider, hooks, guards, and Next.js App Router helpers (recommended for React)
@ackplus/nest-auth-contractsShared 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.

License

MIT

版本与发布记录

@ackplus/nest-auth-client 共发布 110 个版本,首次发布于 2025/12/27;过去 12 个月发布了 110 个版本。

版本发布日期距今
2.18.0latest2026/11/034 天前
2.16.02026/10/2711 天前
2.15.02026/10/2612 天前
2.14.12026/10/2414 天前
2.14.02026/10/1226 天前
2.13.12026/10/1028 天前

其他发布通道:beta → 2.0.0-beta.26。

关于 @ackplus/nest-auth-client 的常见问题

@ackplus/nest-auth-client 是什么?

NestJS authentication for REST APIs

如何安装 @ackplus/nest-auth-client?

在项目目录运行 npm install @ackplus/nest-auth-client,或使用 pnpm add / yarn add / bun add。

@ackplus/nest-auth-client 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@ackplus/nest-auth-client 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@ackplus/nest-auth-client 可以商用吗?

@ackplus/nest-auth-client 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@ackplus/nest-auth-client 的下载量有多少?

根据 npm 官方下载统计,@ackplus/nest-auth-client 在 2026/10/05 – 2026/11/03 这 30 天内被下载 2,384 次,日均约 79 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@ackplus/nest-auth-client 还在维护吗?

最新版本 2.18.0 发布于 2026/11/03(4 天前);至今共发布 110 个版本,其中过去 12 个月发布了 110 个;首次发布于 2025/12/27。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。