najm-auth 3.2.0 → 3.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -5
- package/dist/index.d.ts +25 -3
- package/dist/index.js +462 -423
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -129,9 +129,10 @@ auth({
|
|
|
129
129
|
database?: string // Default: 'default'
|
|
130
130
|
blacklistPrefix?: string // Default: 'auth:blacklist:'
|
|
131
131
|
|
|
132
|
-
// Registration
|
|
133
|
-
defaultRole?: string | null // Auto-assign role to new users
|
|
134
|
-
|
|
132
|
+
// Registration
|
|
133
|
+
defaultRole?: string | null // Auto-assign role to new users
|
|
134
|
+
publicRegistration?: boolean // Default: true; mounts POST /auth/register
|
|
135
|
+
bcryptRounds?: number // Default: 10 (valid: 4-31)
|
|
135
136
|
|
|
136
137
|
// Frontend
|
|
137
138
|
frontendUrl?: string // Password reset link base URL
|
|
@@ -181,7 +182,7 @@ All routes are prefixed with `/auth` and auto-registered by the plugin.
|
|
|
181
182
|
|
|
182
183
|
| Method | Path | Description | Auth |
|
|
183
184
|
|--------|------|-------------|------|
|
|
184
|
-
| `POST` | `/auth/register` | Register new user | None |
|
|
185
|
+
| `POST` | `/auth/register` | Register new user (omitted when `publicRegistration: false`) | None |
|
|
185
186
|
| `POST` | `/auth/login` | Login with email/password | None |
|
|
186
187
|
| `POST` | `/auth/refresh` | Refresh access token (cookie) | None (uses refresh cookie) |
|
|
187
188
|
| `POST` | `/auth/session/recover` | Reissue signed session without token rotation | Refresh cookie + recovery header |
|
|
@@ -194,7 +195,12 @@ All routes are prefixed with `/auth` and auto-registered by the plugin.
|
|
|
194
195
|
| `POST` | `/auth/oauth/google/link` | Link Google to the current user | ✅ Required |
|
|
195
196
|
| `GET` | `/auth/credential-setup/setup` | Read the pending setup session | Setup cookie |
|
|
196
197
|
| `POST` | `/auth/credential-setup/change` | Replace the temporary credential | Setup cookie |
|
|
197
|
-
| `POST` | `/auth/credential-setup/cancel` | Abandon the setup session | Setup cookie |
|
|
198
|
+
| `POST` | `/auth/credential-setup/cancel` | Abandon the setup session | Setup cookie |
|
|
199
|
+
|
|
200
|
+
Applications with an approval-owned onboarding flow should set
|
|
201
|
+
`publicRegistration: false`. This removes the unauthenticated route while
|
|
202
|
+
retaining `AuthService.registerUser()`, `provisionUser()`, and other internal
|
|
203
|
+
account-management APIs for trusted application services.
|
|
198
204
|
|
|
199
205
|
### Identity presets
|
|
200
206
|
|
package/dist/index.d.ts
CHANGED
|
@@ -169,6 +169,8 @@ interface AuthConfig {
|
|
|
169
169
|
frontendUrl: string;
|
|
170
170
|
/** Registration mode: 'active' auto-activates, 'pending' requires admin approval (default: 'active') */
|
|
171
171
|
registrationMode: 'active' | 'pending';
|
|
172
|
+
/** Whether the unauthenticated POST /auth/register route is mounted. */
|
|
173
|
+
publicRegistration: boolean;
|
|
172
174
|
/** When true, users with emailVerified=false are blocked from logging in (default: false) */
|
|
173
175
|
requireVerifiedEmail: boolean;
|
|
174
176
|
/** Cookie path for the refresh token. Scope to the refresh endpoint to limit exposure (default: '/') */
|
|
@@ -234,6 +236,13 @@ type AuthPluginConfig = {
|
|
|
234
236
|
frontendUrl?: string;
|
|
235
237
|
/** Registration mode: 'active' auto-activates new users, 'pending' requires admin approval (default: 'active') */
|
|
236
238
|
registrationMode?: 'active' | 'pending';
|
|
239
|
+
/**
|
|
240
|
+
* Mount the unauthenticated POST /auth/register route (default: true for
|
|
241
|
+
* backwards compatibility). Set false when onboarding belongs to an
|
|
242
|
+
* application-owned approval flow. Internal AuthService provisioning stays
|
|
243
|
+
* available.
|
|
244
|
+
*/
|
|
245
|
+
publicRegistration?: boolean;
|
|
237
246
|
/** Block login for users whose email is not verified (default: false) */
|
|
238
247
|
requireVerifiedEmail?: boolean;
|
|
239
248
|
/** Cookie path for the refresh token (default: '/'). Set e.g. '/auth' to keep it off unrelated routes. */
|
|
@@ -1652,7 +1661,6 @@ declare const authIdentityRateLimitKey: (ctx: Context) => Promise<string>;
|
|
|
1652
1661
|
declare class AuthController {
|
|
1653
1662
|
private authService;
|
|
1654
1663
|
constructor(authService: AuthService);
|
|
1655
|
-
registerUser(body: RegisterDto): Promise<SanitizedUser>;
|
|
1656
1664
|
loginUser(body: LoginDto): Promise<LoginResult>;
|
|
1657
1665
|
inviteUser(body: InviteUserDto): Promise<Omit<{
|
|
1658
1666
|
password: string;
|
|
@@ -1772,6 +1780,17 @@ declare class AuthIdentityContextService {
|
|
|
1772
1780
|
configure(): Promise<void>;
|
|
1773
1781
|
}
|
|
1774
1782
|
|
|
1783
|
+
/**
|
|
1784
|
+
* Public self-registration is isolated from the rest of the auth transport so
|
|
1785
|
+
* applications can omit this controller without disabling internal account
|
|
1786
|
+
* provisioning through AuthService.
|
|
1787
|
+
*/
|
|
1788
|
+
declare class RegistrationController {
|
|
1789
|
+
private authService;
|
|
1790
|
+
constructor(authService: AuthService);
|
|
1791
|
+
registerUser(body: RegisterDto): Promise<SanitizedUser>;
|
|
1792
|
+
}
|
|
1793
|
+
|
|
1775
1794
|
type IdentityResolver = (value: unknown) => string | null;
|
|
1776
1795
|
/**
|
|
1777
1796
|
* Build the identifier pipeline used by login lookup, lockout accounting, and
|
|
@@ -1811,7 +1830,10 @@ interface RunAsUser {
|
|
|
1811
1830
|
}
|
|
1812
1831
|
declare function runAsUser<T>(container: Container, user: RunAsUser, fn: () => Promise<T> | T): Promise<T>;
|
|
1813
1832
|
|
|
1814
|
-
declare const
|
|
1833
|
+
declare const AUTH_CORE_MODULE: readonly [typeof AuthService, typeof AuthSessionService, typeof CookieManager, typeof EncryptionService, typeof AuthGuard, typeof AuthController, typeof AuthResolver, typeof AuthIdentityContextService];
|
|
1834
|
+
declare const PUBLIC_REGISTRATION_MODULE: readonly [typeof RegistrationController];
|
|
1835
|
+
/** Full module retained for consumers that register the exported module directly. */
|
|
1836
|
+
declare const AUTH_MODULE: readonly [typeof AuthService, typeof AuthSessionService, typeof CookieManager, typeof EncryptionService, typeof AuthGuard, typeof AuthController, typeof AuthResolver, typeof AuthIdentityContextService, typeof RegistrationController];
|
|
1815
1837
|
|
|
1816
1838
|
declare class PermissionRepository {
|
|
1817
1839
|
db: TDb;
|
|
@@ -2765,4 +2787,4 @@ declare const authSeed: (config: AuthSeedConfig) => Record<string, SeedEntry>;
|
|
|
2765
2787
|
*/
|
|
2766
2788
|
declare function seedAuthData(config: SeedAuthDataConfig): Promise<SeedAuthDataResult>;
|
|
2767
2789
|
|
|
2768
|
-
export { AUTH_CONFIG, en as AUTH_EN, AUTH_LOCALES, AUTH_LOGIN_RATE_LIMIT_ENV, AUTH_MODULE, AUTH_PERMISSIONS, AUTH_ROLE, AUTH_SCHEMA, AUTH_SUPPORTED_LANGUAGES, AUTH_USER, type AssignPermissionDto, type AssignRoleDto, type AssignRoleParams, type AuthConfig, AuthController, AuthGuard, type AuthLoginRateLimitConfig, type AuthPluginConfig, AuthQueries, type AuthRateLimitEnvironment, AuthResolver, type AuthSchema, type AuthSeedConfig, AuthService, AuthSessionService, type AuthUser, CREDENTIAL_SETUP_CODES, CREDENTIAL_SETUP_MODULE, Can, CanCreate, CanDelete, CanList, CanRead, CanUpdate, type ChainableGuard, type ChangePasswordDto, type CheckPermissionDto, type ConfiguredOwnership, type ConfirmResetPasswordDto, CookieManager, type CreatePermissionDto, type CreateRoleDto, type CreateTokenDto, type CreateUserDto, type CredentialSetupChangeDto, type CredentialSetupCode, type CredentialSetupConfig, CredentialSetupController, type CredentialSetupOptions, type CredentialSetupPasswordOptions, type CredentialSetupPending, CredentialSetupRepository, CredentialSetupRequirementRepository, type CredentialSetupRequirementRow, CredentialSetupRequirementService, CredentialSetupService, type CredentialSetupSessionInfo, type CredentialSetupStarted, DEFAULT_AUTH_LOGIN_RATE_LIMIT, DEFAULT_CREDENTIAL_SETUP_COOKIE_NAME, DEFAULT_CREDENTIAL_SETUP_TTL_MS, type DefineRolesOptions, type EmailParam, EncryptionService, type GoogleOAuthConfig, IdentityConfig, type IdentityResolver, type InviteUserDto, type JwtConfig, type JwtPayload, type LanguageParam, type LoginDto, type LoginResult, NewPermission, NewRoleEntity, NewUser, type OAuthConfig, type OAuthProvider, Owned, type OwnedMethods, type OwnershipConfig, type OwnershipProvider, type OwnershipRule, OwnershipToken, type OwnershipTokenOptions, PASSWORD_SETUP_PURPOSE, PasswordSetupService, Permission, PermissionController, PermissionGuard, type PermissionIdParam, PermissionRepository, PermissionService, PermissionValidator, Policy, type ProvisionUserInput, type ProvisionUserWithPasswordInput, type ProvisionUserWithSetupInput, ROLES, ROLE_GROUPS, type RefreshTokenDto, type RegisterDto, type ResetPasswordDto, type ResolvedCredentialSetupConfig, ResolvedIdentityConfig, type ResourceAccessor, type ResourceGuards, type ResourceGuardsOptions, type RevokeTokenDto, Role, RoleController, RoleEntity, RoleGuard, type RoleIdParam, type RoleInput, RolePermission, RoleRepository, RoleService, type RoleType, RoleValidator, type RunAsUser, type SanitizedUser, ScopeContext, type ScopeResult, type SeedAuthDataConfig, type SeedAuthDataResult, type SeedUserConfig, type SessionCookieData, TOKEN_STATUS, TOKEN_TYPE, TemporaryCredentialInput, type TokenIdParam, type TokenPair, TokenRepository, TokenService, USER_STATUS, type UpdatePermissionDto, type UpdateRoleDto, type UpdateTokenDto, type UpdateUserDto, User, UserController, type UserIdInParam, type UserIdParam, type UserListQuery, UserRepository, UserService, UserValidator, type UserWithPermissions, type VerifyTokenDto, assignPermissionDto, assignRoleDto, assignRoleParams, auth$1 as auth, authIdentityRateLimitKey, authSeed, avatarsPath, calculateAge, calculateYearsOfExperience, changePasswordDto, checkPermissionDto, clean, configureOwnership, confirmResetPasswordDto, createIdentityResolver, createPermissionDto, createRoleDto, createTokenDto, createUserDto, credentialSetupChangeDto, credentialSetupError, defaultCredentialSetupPasswordSchema, defineRoles, emailParam, formatDate, getAuthLocale, getAvatarFile, inviteUserDto, isAdmin, isAdministrator, isAuth, isEmailIdentifier, isEmpty, isFile, isPath, join, languageParam, loginDto, normalizeAuthIdentifier, normalizeSetupPurpose, own, parseSchema, permissionIdParam, pickProps, refreshTokenDto, registerDto, resetPasswordDto, resolveAuthLoginRateLimitConfig, revokeTokenDto, roleIdParam, runAsUser, seedAuthData, tokenIdParam, updatePermissionDto, updateRoleDto, updateTokenDto, updateUserDto, userIdInParam, userIdParam, userListQuery, verifyTokenDto, where };
|
|
2790
|
+
export { AUTH_CONFIG, AUTH_CORE_MODULE, en as AUTH_EN, AUTH_LOCALES, AUTH_LOGIN_RATE_LIMIT_ENV, AUTH_MODULE, AUTH_PERMISSIONS, AUTH_ROLE, AUTH_SCHEMA, AUTH_SUPPORTED_LANGUAGES, AUTH_USER, type AssignPermissionDto, type AssignRoleDto, type AssignRoleParams, type AuthConfig, AuthController, AuthGuard, type AuthLoginRateLimitConfig, type AuthPluginConfig, AuthQueries, type AuthRateLimitEnvironment, AuthResolver, type AuthSchema, type AuthSeedConfig, AuthService, AuthSessionService, type AuthUser, CREDENTIAL_SETUP_CODES, CREDENTIAL_SETUP_MODULE, Can, CanCreate, CanDelete, CanList, CanRead, CanUpdate, type ChainableGuard, type ChangePasswordDto, type CheckPermissionDto, type ConfiguredOwnership, type ConfirmResetPasswordDto, CookieManager, type CreatePermissionDto, type CreateRoleDto, type CreateTokenDto, type CreateUserDto, type CredentialSetupChangeDto, type CredentialSetupCode, type CredentialSetupConfig, CredentialSetupController, type CredentialSetupOptions, type CredentialSetupPasswordOptions, type CredentialSetupPending, CredentialSetupRepository, CredentialSetupRequirementRepository, type CredentialSetupRequirementRow, CredentialSetupRequirementService, CredentialSetupService, type CredentialSetupSessionInfo, type CredentialSetupStarted, DEFAULT_AUTH_LOGIN_RATE_LIMIT, DEFAULT_CREDENTIAL_SETUP_COOKIE_NAME, DEFAULT_CREDENTIAL_SETUP_TTL_MS, type DefineRolesOptions, type EmailParam, EncryptionService, type GoogleOAuthConfig, IdentityConfig, type IdentityResolver, type InviteUserDto, type JwtConfig, type JwtPayload, type LanguageParam, type LoginDto, type LoginResult, NewPermission, NewRoleEntity, NewUser, type OAuthConfig, type OAuthProvider, Owned, type OwnedMethods, type OwnershipConfig, type OwnershipProvider, type OwnershipRule, OwnershipToken, type OwnershipTokenOptions, PASSWORD_SETUP_PURPOSE, PUBLIC_REGISTRATION_MODULE, PasswordSetupService, Permission, PermissionController, PermissionGuard, type PermissionIdParam, PermissionRepository, PermissionService, PermissionValidator, Policy, type ProvisionUserInput, type ProvisionUserWithPasswordInput, type ProvisionUserWithSetupInput, ROLES, ROLE_GROUPS, type RefreshTokenDto, type RegisterDto, RegistrationController, type ResetPasswordDto, type ResolvedCredentialSetupConfig, ResolvedIdentityConfig, type ResourceAccessor, type ResourceGuards, type ResourceGuardsOptions, type RevokeTokenDto, Role, RoleController, RoleEntity, RoleGuard, type RoleIdParam, type RoleInput, RolePermission, RoleRepository, RoleService, type RoleType, RoleValidator, type RunAsUser, type SanitizedUser, ScopeContext, type ScopeResult, type SeedAuthDataConfig, type SeedAuthDataResult, type SeedUserConfig, type SessionCookieData, TOKEN_STATUS, TOKEN_TYPE, TemporaryCredentialInput, type TokenIdParam, type TokenPair, TokenRepository, TokenService, USER_STATUS, type UpdatePermissionDto, type UpdateRoleDto, type UpdateTokenDto, type UpdateUserDto, User, UserController, type UserIdInParam, type UserIdParam, type UserListQuery, UserRepository, UserService, UserValidator, type UserWithPermissions, type VerifyTokenDto, assignPermissionDto, assignRoleDto, assignRoleParams, auth$1 as auth, authIdentityRateLimitKey, authSeed, avatarsPath, calculateAge, calculateYearsOfExperience, changePasswordDto, checkPermissionDto, clean, configureOwnership, confirmResetPasswordDto, createIdentityResolver, createPermissionDto, createRoleDto, createTokenDto, createUserDto, credentialSetupChangeDto, credentialSetupError, defaultCredentialSetupPasswordSchema, defineRoles, emailParam, formatDate, getAuthLocale, getAvatarFile, inviteUserDto, isAdmin, isAdministrator, isAuth, isEmailIdentifier, isEmpty, isFile, isPath, join, languageParam, loginDto, normalizeAuthIdentifier, normalizeSetupPurpose, own, parseSchema, permissionIdParam, pickProps, refreshTokenDto, registerDto, resetPasswordDto, resolveAuthLoginRateLimitConfig, revokeTokenDto, roleIdParam, runAsUser, seedAuthData, tokenIdParam, updatePermissionDto, updateRoleDto, updateTokenDto, updateUserDto, userIdInParam, userIdParam, userListQuery, verifyTokenDto, where };
|