@bymax-one/nest-auth 1.4.15 → 1.4.17

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/CHANGELOG.md CHANGED
@@ -18,6 +18,131 @@ what moves, and that note is the compatibility contract until strict SemVer begi
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [1.4.17] - 2026-11-07
22
+
23
+ ### Apply to a derived backend
24
+
25
+ - **`AuthExceptionFilter` now answers a request the HTTP layer refused with a client-error
26
+ envelope, not `auth.internal`.** Applies only where the filter is registered, and only on
27
+ Express (the filter writes through Express's `Response`; nothing here is defined for Fastify).
28
+ A malformed JSON body, a bare JSON string or number, a form body nested past the parser's
29
+ depth limit, and a path that cannot be decoded now answer `400 auth.validation` with the fixed
30
+ message `Malformed request`; the parser's own text, which could quote the start of the body, is
31
+ no longer in the response. An oversized body answers `413` and an unsupported charset or
32
+ content-encoding `415`, both `auth.validation`, where they answered `500 auth.internal`. A client that branched on `auth.internal` for these must branch on
33
+ `auth.validation` and the status. The 400 is recognised by having been raised before any route
34
+ matched (`req.route` unset), so a `BadRequestException` thrown by the application's own
35
+ middleware that runs before routing is answered the same generic way; one thrown from a
36
+ handler, guard, pipe or service keeps its message and `auth.internal`. The new `transportErrors`
37
+ section of `conformance/wire-contract.json` lists the rows; `errorCatalog.statuses` still holds
38
+ one status per code. No public member is added or changed.
39
+ - **A production deployment can no longer start with `secureCookies: false`.** `environment` is
40
+ `'production'` when unset, so a configuration that sets `secureCookies: false` without declaring
41
+ `environment: 'development'` or `'test'` now throws at startup, after the `SameSite=None` check,
42
+ with a message that contains "secureCookies is false but environment is 'production' (the default
43
+ when unset)." Remove the option, set it to `true`, or declare the environment. A session cookie
44
+ without `Secure` travels over plain HTTP, and a TLS-terminating proxy still serves HTTPS to the
45
+ browser. Omitting `secureCookies` and setting it to `true` are unchanged. No public member is
46
+ added or changed.
47
+ - **A refresh token that rotated a moment ago now stands for the session that replaced it, on
48
+ `POST /password/change` and `POST /sessions/revoke-all`.** A refresh of the caller's own session
49
+ that landed while the request was being handled turned the token it carried into a rotation
50
+ predecessor, and both routes answered `404 auth.session_not_found`; a password change left the
51
+ password unchanged. A presented token now counts when it is a live session or when its grace
52
+ pointer (`rp:{hash}`) names a live successor, and that successor is the session kept. It is one
53
+ hop, the pointer is read and never consumed or extended, and a token past the grace window is
54
+ still refused with `404`. The current password still gates the change. When the session to keep
55
+ cannot be resolved after the new password is written, every session still ends, as before; a
56
+ session that rotated while the new password was being hashed is no longer among them, since it
57
+ is the caller's device and now survives. `SessionService` gains a public
58
+ `resolveLiveSession(params)` returning the hash to keep, `assertLiveSession` takes
59
+ `params: LiveSessionParams`, and private `isLiveMember`, `resolveLiveMember` and `graceSuccessor`
60
+ replace the private `requireLiveMember`. In `PasswordResetService` the private `requireLiveCurrentSession` becomes
61
+ `resolveCurrentSession`, and `endOtherSessions` now takes the hash to keep.
62
+ - **A login no longer evicts a session when the store fails to read a session record.** The
63
+ session limit ranks sessions by the creation time in each one's detail record; a read the store
64
+ failed was ranked as the oldest, so a transient Redis fault could end a live, newest device. Now
65
+ no session is evicted by that login, one error is logged without any key or hash, and the limit
66
+ is checked again by the next login. An absent or unparseable detail record is not a fault and
67
+ still ranks as the oldest. While such reads fail no login evicts, so the limit is unenforced.
68
+ A private `readCreatedAt` appears in the `SessionService` declarations.
69
+
70
+ ### Fixed
71
+
72
+ - **Requests refused by the body parser no longer answer `500` or echo the body.** See the note
73
+ above.
74
+ - **A password change or revoke-all no longer fails when the caller refreshes the session
75
+ concurrently.** See the note above.
76
+ - **A store fault while ranking sessions no longer evicts a live session.** See the note above.
77
+ - **`secureCookies: false` in a production deployment is refused at startup.** See the note above.
78
+
79
+ ## [1.4.16] - 2026-11-06
80
+
81
+ ### Apply to a derived backend
82
+
83
+ - **`GET /sessions` now fails when the store cannot read one of the caller's session records.** A
84
+ listing that used to answer `200` with the unreadable session left out during a Redis fault
85
+ now answers `500` (`auth.internal` when `AuthExceptionFilter` is registered), as a failed
86
+ logout write does. A client that treated every `200` from this route as the complete list must
87
+ now handle the error. A session record that is absent or malformed is still left out of the
88
+ list, as before. A private method, `readSession`, appears in the `SessionService` declarations;
89
+ this change adds no public member.
90
+ - **`registerAsync` now accepts a factory with typed parameters, without a cast.** The options
91
+ factory is declared `(...args: never[])` instead of `(...args: unknown[])`, so
92
+ `useFactory: (config: ConfigService) => ...` type-checks under `strict`. A factory written with
93
+ `...args: unknown[]` keeps compiling, and the options it returns are checked as before: a secret
94
+ typed `string | undefined` is still refused.
95
+ - **A request whose `refreshToken` is present but malformed now answers `400 auth.validation`.** On
96
+ `POST /refresh`, `/logout`, `/sessions/revoke-all`, `GET /sessions` and the platform `refresh` and
97
+ `logout`, a body `refreshToken` that is not a string of 1 to 2048 characters used to be read as a
98
+ missing token: refresh answered `401`, logout answered `204`, revoke-all answered `404`, and the
99
+ listing ignored it. It is now refused with `400`, naming the field, before anything is done. An
100
+ omitted field and JSON `null` still mean no token. A client that sends `refreshToken: ''` when it
101
+ holds no token, the `?? ''` pattern, now gets the `400`; it should omit the field or send
102
+ `null`. The field is read only where the delivery mode reads the body, so in `cookie` mode a
103
+ value there is ignored.
104
+ - **`POST /sessions/revoke-all` and `POST /password/change` refuse a refresh token that names no
105
+ live session of the caller, with `404 auth.session_not_found`, before anything changes.** Both
106
+ keep the caller's own session and end the rest when given a token, so they need to know which
107
+ one it is. A well-formed token that named none kept nothing: revoke-all answered `204` and ended
108
+ every session the account had, the caller's own included, and a password change wrote the new
109
+ password and then did the same. A password change checks the current password first, so a wrong
110
+ one still answers `401`, then the session, then writes. `SessionService` gains a public method,
111
+ `assertLiveSession`, which the password change uses, and a private one, `requireLiveMember`;
112
+ `LiveSessionParams`, the type of its parameter, is exported from the package entry point.
113
+ `PasswordResetService` gains three private methods, `requireLiveCurrentSession`,
114
+ `endOtherSessions` and `endAllSessions`.
115
+
116
+ ### Fixed
117
+
118
+ - **A session listing no longer hides a session it could not read.** The list is the caller's
119
+ only view of their sessions, and a session left out of it is one they cannot revoke, so a read
120
+ fault on one record answered a list that looked complete. The index cleanup that ran after
121
+ every listing still runs, with the same candidates and the same guard that removes only members
122
+ whose refresh key is gone, so the fault costs the caller the list and the index nothing.
123
+ - **Logout no longer answers success while leaving the refresh session alive.** With a refresh
124
+ token that was present but malformed it blacklisted the access token, answered `204`, and left the
125
+ refresh session usable, so the client believed it had signed out. The request is now refused
126
+ before either happens.
127
+ - **"Sign out my other devices" no longer signs out every device when the token is stale.** A
128
+ refresh token that was well formed but no longer a live session was treated as having no session
129
+ to keep, so the whole account was revoked and the call answered success. It is refused instead,
130
+ and nothing is revoked.
131
+
132
+ ### Changed
133
+
134
+ - **The package is built with tsup 9.** The JavaScript bundles are byte-for-byte what tsup 8
135
+ produced. The declaration files spell each entry point's export list as `export { … }` followed
136
+ by `export type { … }` where they wrote inline `type` modifiers; the exported names and which of
137
+ them are types are unchanged.
138
+
139
+ ### Documentation
140
+
141
+ - **The Quick Start module block compiles under `strict`.** It reads the secret with
142
+ `config.getOrThrow('JWT_SECRET')`, since `config.get` answers `string | undefined`, and it now
143
+ imports the repository and email provider classes it uses, which the previous steps define. A
144
+ test type-checks the Quick Start blocks with every name they use declared.
145
+
21
146
  ## [1.4.15] - 2026-11-01
22
147
 
23
148
  ### Apply to a derived backend
@@ -4293,7 +4418,9 @@ ever installable.
4293
4418
  - Phase 4 password-reset tests cover: both `token` and `otp` flows, mutual exclusivity validation, `verifiedToken` exchange, resend cooldown, anti-enumeration (no error on unknown email), and session invalidation on reset
4294
4419
  - Phase 5 tests cover: platform login with MFA path and brute-force lockout, `JwtPlatformGuard` cross-context rejection, `PlatformRolesGuard` hierarchy enforcement, OAuth CSRF state lifecycle, `onOAuthLogin` hook resolution strategies, and invitation role-authorization + acceptance single-use enforcement
4295
4420
 
4296
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.15...HEAD
4421
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.17...HEAD
4422
+ [1.4.17]: https://github.com/bymaxone/nest-auth/compare/v1.4.16...v1.4.17
4423
+ [1.4.16]: https://github.com/bymaxone/nest-auth/compare/v1.4.15...v1.4.16
4297
4424
  [1.4.15]: https://github.com/bymaxone/nest-auth/compare/v1.4.14...v1.4.15
4298
4425
  [1.4.14]: https://github.com/bymaxone/nest-auth/compare/v1.4.13...v1.4.14
4299
4426
  [1.4.13]: https://github.com/bymaxone/nest-auth/compare/v1.4.12...v1.4.13
package/README.md CHANGED
@@ -530,6 +530,8 @@ import {
530
530
  BYMAX_AUTH_REDIS_CLIENT,
531
531
  BYMAX_AUTH_EMAIL_PROVIDER
532
532
  } from '@bymax-one/nest-auth'
533
+ import { PrismaUserRepository } from './user.repository'
534
+ import { ResendEmailProvider } from './email.provider'
533
535
 
534
536
  // Yours, not this library's: `ConfigModule` and `ConfigService` come from `@nestjs/config`,
535
537
  // `DatabaseModule` is your module exporting the database client the repository uses, and
@@ -541,7 +543,7 @@ import {
541
543
  imports: [ConfigModule, DatabaseModule, RedisModule],
542
544
  useFactory: (config: ConfigService) => ({
543
545
  jwt: {
544
- secret: config.get('JWT_SECRET'), // min 32 chars, high entropy
546
+ secret: config.getOrThrow('JWT_SECRET'), // min 32 chars, high entropy
545
547
  accessExpiresIn: '15m',
546
548
  refreshExpiresInDays: 7
547
549
  },
@@ -373,4 +373,5 @@ interface AuthClient {
373
373
  */
374
374
  declare function createAuthClient(config: AuthClientConfig): AuthClient;
375
375
 
376
- export { type AuthClient, type AuthClientConfig, type AuthFetch, type AuthFetchConfig, type LoginInput, type RefreshFailure, type RefreshFailureReason, type RefreshOutcome, type RegisterInput, type ResetPasswordInput, createAuthClient, createAuthFetch };
376
+ export { createAuthClient, createAuthFetch };
377
+ export type { AuthClient, AuthClientConfig, AuthFetch, AuthFetchConfig, LoginInput, RefreshFailure, RefreshFailureReason, RefreshOutcome, RegisterInput, ResetPasswordInput };
@@ -373,4 +373,5 @@ interface AuthClient {
373
373
  */
374
374
  declare function createAuthClient(config: AuthClientConfig): AuthClient;
375
375
 
376
- export { type AuthClient, type AuthClientConfig, type AuthFetch, type AuthFetchConfig, type LoginInput, type RefreshFailure, type RefreshFailureReason, type RefreshOutcome, type RegisterInput, type ResetPasswordInput, createAuthClient, createAuthFetch };
376
+ export { createAuthClient, createAuthFetch };
377
+ export type { AuthClient, AuthClientConfig, AuthFetch, AuthFetchConfig, LoginInput, RefreshFailure, RefreshFailureReason, RefreshOutcome, RegisterInput, ResetPasswordInput };
@@ -1138,4 +1138,5 @@ declare function createLogoutHandler(config: LogoutHandlerConfig): LogoutHandler
1138
1138
  */
1139
1139
  declare const LOGOUT_ROUTE: "/api/auth/logout";
1140
1140
 
1141
- export { type AuthProxyConfig, type AuthProxyInstance, CLIENT_REFRESH_ROUTE, type ClientRefreshHandler, type ClientRefreshHandlerConfig, type DecodedToken, type HeadersLike, type JwtHeader, LOGOUT_ROUTE, type LogoutHandler, type LogoutHandlerConfig, type LogoutHandlerRedirectConfig, type LogoutHandlerStatusConfig, type ParsedSetCookie, type ProtectedRoutePattern, type RequestWithHeaders, type RequestWithUrl, type ResolvedAuthProxyConfig, SILENT_REFRESH_ROUTE, type SilentRefreshHandler, type SilentRefreshHandlerConfig, buildSilentRefreshUrl, createAuthProxy, createClientRefreshHandler, createLogoutHandler, createSilentRefreshHandler, decodeJwtToken, dedupeSetCookieHeaders, getSetCookieHeaders, getTenantId, getUserId, getUserRole, isBackgroundRequest, isTokenExpired, parseSetCookieHeader, resolveSafeDestination, verifyJwtToken };
1141
+ export { CLIENT_REFRESH_ROUTE, LOGOUT_ROUTE, SILENT_REFRESH_ROUTE, buildSilentRefreshUrl, createAuthProxy, createClientRefreshHandler, createLogoutHandler, createSilentRefreshHandler, decodeJwtToken, dedupeSetCookieHeaders, getSetCookieHeaders, getTenantId, getUserId, getUserRole, isBackgroundRequest, isTokenExpired, parseSetCookieHeader, resolveSafeDestination, verifyJwtToken };
1142
+ export type { AuthProxyConfig, AuthProxyInstance, ClientRefreshHandler, ClientRefreshHandlerConfig, DecodedToken, HeadersLike, JwtHeader, LogoutHandler, LogoutHandlerConfig, LogoutHandlerRedirectConfig, LogoutHandlerStatusConfig, ParsedSetCookie, ProtectedRoutePattern, RequestWithHeaders, RequestWithUrl, ResolvedAuthProxyConfig, SilentRefreshHandler, SilentRefreshHandlerConfig };
@@ -1138,4 +1138,5 @@ declare function createLogoutHandler(config: LogoutHandlerConfig): LogoutHandler
1138
1138
  */
1139
1139
  declare const LOGOUT_ROUTE: "/api/auth/logout";
1140
1140
 
1141
- export { type AuthProxyConfig, type AuthProxyInstance, CLIENT_REFRESH_ROUTE, type ClientRefreshHandler, type ClientRefreshHandlerConfig, type DecodedToken, type HeadersLike, type JwtHeader, LOGOUT_ROUTE, type LogoutHandler, type LogoutHandlerConfig, type LogoutHandlerRedirectConfig, type LogoutHandlerStatusConfig, type ParsedSetCookie, type ProtectedRoutePattern, type RequestWithHeaders, type RequestWithUrl, type ResolvedAuthProxyConfig, SILENT_REFRESH_ROUTE, type SilentRefreshHandler, type SilentRefreshHandlerConfig, buildSilentRefreshUrl, createAuthProxy, createClientRefreshHandler, createLogoutHandler, createSilentRefreshHandler, decodeJwtToken, dedupeSetCookieHeaders, getSetCookieHeaders, getTenantId, getUserId, getUserRole, isBackgroundRequest, isTokenExpired, parseSetCookieHeader, resolveSafeDestination, verifyJwtToken };
1141
+ export { CLIENT_REFRESH_ROUTE, LOGOUT_ROUTE, SILENT_REFRESH_ROUTE, buildSilentRefreshUrl, createAuthProxy, createClientRefreshHandler, createLogoutHandler, createSilentRefreshHandler, decodeJwtToken, dedupeSetCookieHeaders, getSetCookieHeaders, getTenantId, getUserId, getUserRole, isBackgroundRequest, isTokenExpired, parseSetCookieHeader, resolveSafeDestination, verifyJwtToken };
1142
+ export type { AuthProxyConfig, AuthProxyInstance, ClientRefreshHandler, ClientRefreshHandlerConfig, DecodedToken, HeadersLike, JwtHeader, LogoutHandler, LogoutHandlerConfig, LogoutHandlerRedirectConfig, LogoutHandlerStatusConfig, ParsedSetCookie, ProtectedRoutePattern, RequestWithHeaders, RequestWithUrl, ResolvedAuthProxyConfig, SilentRefreshHandler, SilentRefreshHandlerConfig };
@@ -352,4 +352,5 @@ interface UseAuthStatusResult {
352
352
  */
353
353
  declare function useAuthStatus(): UseAuthStatusResult;
354
354
 
355
- export { type AuthContextValue, AuthProvider, type AuthProviderProps, type AuthStatus, type UseAuthResult, type UseAuthStatusResult, type UseSessionResult, useAuth, useAuthStatus, useSession };
355
+ export { AuthProvider, useAuth, useAuthStatus, useSession };
356
+ export type { AuthContextValue, AuthProviderProps, AuthStatus, UseAuthResult, UseAuthStatusResult, UseSessionResult };
@@ -352,4 +352,5 @@ interface UseAuthStatusResult {
352
352
  */
353
353
  declare function useAuthStatus(): UseAuthStatusResult;
354
354
 
355
- export { type AuthContextValue, AuthProvider, type AuthProviderProps, type AuthStatus, type UseAuthResult, type UseAuthStatusResult, type UseSessionResult, useAuth, useAuthStatus, useSession };
355
+ export { AuthProvider, useAuth, useAuthStatus, useSession };
356
+ export type { AuthContextValue, AuthProviderProps, AuthStatus, UseAuthResult, UseAuthStatusResult, UseSessionResult };