@ackplus/nest-auth

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

Authentication & authorization for NestJS — JWT/cookie sessions, refresh-token rotation, RBAC, multi-tenancy, MFA, OAuth/social login, passwordless, API keys, and a built-in admin console.

原始使用文档
文档目录9 节
  1. Why
  2. Install
  3. AI coding agents
  4. What's included
  5. Minimal example
  6. Documentation
  7. Companion packages
  8. Links
  9. License

@ackplus/nest-auth

npm version npm downloads license

Full-featured authentication module for NestJS. Sessions, MFA, OAuth, passwordless, multi-tenancy, RBAC, audit logging, and an embedded admin console — all type-safe end to end.

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


Why

Modern auth has a long checklist: email + password, OAuth, MFA, refresh-token rotation, RBAC, multi-tenancy, audit logs, an admin console. Most teams glue together five libraries (and own the integration risk) or buy a hosted vendor (and lose data ownership). @ackplus/nest-auth picks a third path: a single, modular library you install in your own NestJS app, backed by your own database.

Install

pnpm add @ackplus/nest-auth @ackplus/nest-auth-contracts

Required peer dependencies:

pnpm add @nestjs/common @nestjs/core @nestjs/typeorm @nestjs/swagger \
  @nestjs/event-emitter @nestjs/platform-express \
  typeorm class-validator class-transformer reflect-metadata rxjs

Optional, only if you enable the matching feature:

FeatureAdd
Cookie-mode sessionscookie-parser
Redis sessionsioredis
Google OAuthgoogle-auth-library
Facebook OAuthfb
Apple OAuthapple-auth
Rate limiting@nestjs/throttler

Full install guide →

AI coding agents

Using Claude Code, Codex, Cursor or another AI coding agent? Install the Nest Auth skill so it knows this SDK's real API:

npx @ackplus/nest-auth-skill

It detects your stack (or pass --stack backend) and only adds agent instruction files; your app is not changed.

What's included

CapabilityNotes
9 sign-in methodsEmail + password · phone + password · passwordless OTP · magic link · Google · Facebook · Apple · GitHub · API keys + custom OAuth providers
MFATOTP · email OTP · SMS OTP · recovery codes · trusted-device tokens
SessionsDatabase (default), Redis, or in-memory · auto-refresh · refresh-token rotation · password-hash-prefix invalidation
Multi-tenancydisabled / shared / isolated modes · tenant-aware decorators · per-request context
RBACRoles + permissions per guard namespace (web, api, mobile) · external IDP friendly
Embedded admin consoleBuilt-in React UI for users, roles, permissions, tenants, API keys
Hooks & eventsEvery lifecycle moment is overridable; full EventEmitter2 integration
Audit loggingStructured event hook for compliance
OpenAPIAuto-generated @nestjs/swagger spec for every endpoint

Minimal example

import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { EventEmitterModule } from '@nestjs/event-emitter';
import { NestAuthModule, NestAuthEntities } from '@ackplus/nest-auth';

@Module({
  imports: [
    EventEmitterModule.forRoot(),
    TypeOrmModule.forRoot({
      type: 'postgres',
      url: process.env.DATABASE_URL,
      entities: [...NestAuthEntities],
      synchronize: process.env.NODE_ENV === 'development',
    }),
    TypeOrmModule.forFeature([...NestAuthEntities]),

    NestAuthModule.forRoot({
      appName: 'My App',
      session: { jwt: { secret: process.env.JWT_SECRET! } },
      // emailAuth: { enabled: true },        // default
      // google: { clientId, clientSecret },  // opt-in OAuth
      // mfa: { enabled: true, required: true },
      // tenant: { enabled: true, mode: TenantModeEnum.SHARED },
    }),
  ],
})
export class AppModule {}

That's it — you immediately get POST /auth/signup, POST /auth/login, /auth/refresh-token, password-reset, MFA, OAuth callbacks, and the rest of the API. Wire EventEmitterModule.forRoot(), cookie-parser, and the AuthExceptionFilter from the setup checklist and ship.

Documentation

SectionWhat's there
Getting StartedInstall, database setup (3 paths), env vars, quickstart for backend / React / Next.js / vanilla
Core ConceptsSessions, user model, multi-tenancy, RBAC, MFA, events, audit
AuthenticationOne page per sign-in method
Backend ReferenceModule config, entities, decorators, guards, services, hooks, events, error codes, admin console
ProductionEmail/SMS wiring, JWT customization, scaling, CORS & security, testing
Recipes20 copy-paste solutions — referral codes, custom OAuth, tenant switcher, etc.
API ReferenceAuto-generated REST + TypeScript types
FAQ & TroubleshootingError codes → likely cause → fix

Companion packages

PackageUse when
@ackplus/nest-auth-clientVanilla JS / Vue / Angular / Svelte / React Native client
@ackplus/nest-auth-reactReact provider, hooks, guards, and Next.js App Router helpers
@ackplus/nest-auth-contractsShared TS types — consumed by all three

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

License

MIT

版本与发布记录

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

版本发布日期距今
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 的常见问题

@ackplus/nest-auth 是什么?

Authentication & authorization for NestJS — JWT/cookie sessions, refresh-token rotation, RBAC, multi-tenancy, MFA, OAuth/social login, passwordless, API keys, and a built-in admin console.

如何安装 @ackplus/nest-auth?

在项目目录运行 npm install @ackplus/nest-auth,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:rxjs(^7.8.0)、express(^4 || ^5)、typeorm(^0.3.21)、@nestjs/core(^10 || ^11)、@nestjs/common(^10 || ^11)、@nestjs/swagger(^10 || ^11)、@nestjs/typeorm(^10 || ^11)、class-validator(^0.14.1)、reflect-metadata(^0.1.13 || ^0.2.0)、class-transformer(^0.5.1)、@nestjs/event-emitter(^2 || ^3)、@nestjs/platform-express(^10 || ^11)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@ackplus/nest-auth 支持 TypeScript 吗?

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

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

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

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

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

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

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

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

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