Nest Authbeta

Entities

Every TypeORM entity in `@ackplus/nest-auth`.

The library ships fourteen entities, exported as a bundle:

import { NestAuthEntities } from '@ackplus/nest-auth';
 
@Module({
  imports: [
    TypeOrmModule.forFeature(NestAuthEntities),
  ],
})

See Database Setup for migration and schema generation.

The bundle

EntityTablePurpose
NestAuthUsernest_auth_usersAuth-only user fields (email, phone, password hash, MFA flag)
NestAuthIdentitynest_auth_identitiesOAuth provider linkage (provider + providerId)
NestAuthSessionnest_auth_sessionsActive sessions with refresh token + user-data snapshot
NestAuthAccessKeynest_auth_access_keysAPI key pairs
NestAuthRolenest_auth_rolesRoles, scoped per guard and per tenant
NestAuthPermissionnest_auth_permissionsPermissions, scoped per guard
NestAuthRolePermissionnest_auth_role_permissionsRole↔permission many-to-many
NestAuthTenantnest_auth_tenantsTenant rows
NestAuthUserAccessnest_auth_user_accessesPer-tenant user membership + roles
NestAuthPlatformAccessnest_auth_platform_accessesCross-tenant roles for staff
NestAuthMFASecretnest_auth_mfa_secretsTOTP secrets, per device
NestAuthOTPnest_auth_otpsOne-time codes (email/phone verify, password reset, MFA)
NestAuthTrustedDevicenest_auth_trusted_devicesTrust tokens for MFA bypass
NestAuthAdminUsernest_auth_admin_usersAdmin console users

High-level relationships

                ┌────────────────┐
                │ NestAuthUser   │
                └──┬──────────┬──┘
       ┌──────────┘  │  │  │  │  │
       │             │  │  │  │  └────────────┐
   ┌───▼───┐  ┌──────▼──┐ │  │ ┌──────────┐ ┌─▼────────┐
   │ Iden- │  │ Session │ │  │ │ MFASecret│ │ OTP      │
   │ tity  │  └─────────┘ │  │ └──────────┘ └──────────┘
   └───────┘               │  │
                  ┌────────▼──▼─────┐
                  │ UserAccess      │
                  │  (tenantId,     │
                  │   roles[])      │
                  └────────┬────────┘

                  ┌────────▼────────┐
                  │ NestAuthTenant  │
                  └─────────────────┘

NestAuthUser → NestAuthSession, → NestAuthIdentity, → NestAuthOTP, → NestAuthMFASecret, → NestAuthAccessKey, → NestAuthTrustedDevice — all ON DELETE CASCADE. Removing a user removes everything attached to them.

Entity field tables

The complete field listing for each entity is auto-generated from the source — see API Reference: Types and search for INestAuthUser, INestAuthSession, etc. The interfaces in @ackplus/nest-auth-contracts mirror the entity columns exactly.

Indexes you'll want

These ship with the entities, but if you're hand-rolling SQL (Database Setup option 3), make sure you add:

TableIndex
nest_auth_usersemail (unique), phone (unique)
nest_auth_sessionsuserId, refreshToken
nest_auth_identities(provider, providerId) (unique), userId
nest_auth_otps(userId, type), expiresAt
nest_auth_user_accesses(userId, tenantId) (unique), tenantId
nest_auth_access_keyspublicKey (unique), userId

Extending vs replacing

Don't subclass NestAuthUser to add business fields. Create your own AppUser table with an authUserId foreign key — see User Model. The library's entities are stable; everything else is yours.

On this page