@bymax-one/nest-auth 1.4.14 → 1.4.16
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 +104 -1
- package/README.md +32 -2
- package/dist/client/index.d.cts +2 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/nextjs/index.d.cts +2 -1
- package/dist/nextjs/index.d.ts +2 -1
- package/dist/react/index.d.cts +2 -1
- package/dist/react/index.d.ts +2 -1
- package/dist/server/index.cjs +203 -85
- package/dist/server/index.d.cts +85 -10
- package/dist/server/index.d.ts +85 -10
- package/dist/server/index.mjs +203 -85
- package/dist/shared/index.d.cts +2 -1
- package/dist/shared/index.d.ts +2 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,107 @@ what moves, and that note is the compatibility contract until strict SemVer begi
|
|
|
18
18
|
|
|
19
19
|
## [Unreleased]
|
|
20
20
|
|
|
21
|
+
## [1.4.16] - 2026-11-06
|
|
22
|
+
|
|
23
|
+
### Apply to a derived backend
|
|
24
|
+
|
|
25
|
+
- **`GET /sessions` now fails when the store cannot read one of the caller's session records.** A
|
|
26
|
+
listing that used to answer `200` with the unreadable session left out during a Redis fault
|
|
27
|
+
now answers `500` (`auth.internal` when `AuthExceptionFilter` is registered), as a failed
|
|
28
|
+
logout write does. A client that treated every `200` from this route as the complete list must
|
|
29
|
+
now handle the error. A session record that is absent or malformed is still left out of the
|
|
30
|
+
list, as before. A private method, `readSession`, appears in the `SessionService` declarations;
|
|
31
|
+
this change adds no public member.
|
|
32
|
+
- **`registerAsync` now accepts a factory with typed parameters, without a cast.** The options
|
|
33
|
+
factory is declared `(...args: never[])` instead of `(...args: unknown[])`, so
|
|
34
|
+
`useFactory: (config: ConfigService) => ...` type-checks under `strict`. A factory written with
|
|
35
|
+
`...args: unknown[]` keeps compiling, and the options it returns are checked as before: a secret
|
|
36
|
+
typed `string | undefined` is still refused.
|
|
37
|
+
- **A request whose `refreshToken` is present but malformed now answers `400 auth.validation`.** On
|
|
38
|
+
`POST /refresh`, `/logout`, `/sessions/revoke-all`, `GET /sessions` and the platform `refresh` and
|
|
39
|
+
`logout`, a body `refreshToken` that is not a string of 1 to 2048 characters used to be read as a
|
|
40
|
+
missing token: refresh answered `401`, logout answered `204`, revoke-all answered `404`, and the
|
|
41
|
+
listing ignored it. It is now refused with `400`, naming the field, before anything is done. An
|
|
42
|
+
omitted field and JSON `null` still mean no token. A client that sends `refreshToken: ''` when it
|
|
43
|
+
holds no token, the `?? ''` pattern, now gets the `400`; it should omit the field or send
|
|
44
|
+
`null`. The field is read only where the delivery mode reads the body, so in `cookie` mode a
|
|
45
|
+
value there is ignored.
|
|
46
|
+
- **`POST /sessions/revoke-all` and `POST /password/change` refuse a refresh token that names no
|
|
47
|
+
live session of the caller, with `404 auth.session_not_found`, before anything changes.** Both
|
|
48
|
+
keep the caller's own session and end the rest when given a token, so they need to know which
|
|
49
|
+
one it is. A well-formed token that named none kept nothing: revoke-all answered `204` and ended
|
|
50
|
+
every session the account had, the caller's own included, and a password change wrote the new
|
|
51
|
+
password and then did the same. A password change checks the current password first, so a wrong
|
|
52
|
+
one still answers `401`, then the session, then writes. `SessionService` gains a public method,
|
|
53
|
+
`assertLiveSession`, which the password change uses, and a private one, `requireLiveMember`;
|
|
54
|
+
`LiveSessionParams`, the type of its parameter, is exported from the package entry point.
|
|
55
|
+
`PasswordResetService` gains three private methods, `requireLiveCurrentSession`,
|
|
56
|
+
`endOtherSessions` and `endAllSessions`.
|
|
57
|
+
|
|
58
|
+
### Fixed
|
|
59
|
+
|
|
60
|
+
- **A session listing no longer hides a session it could not read.** The list is the caller's
|
|
61
|
+
only view of their sessions, and a session left out of it is one they cannot revoke, so a read
|
|
62
|
+
fault on one record answered a list that looked complete. The index cleanup that ran after
|
|
63
|
+
every listing still runs, with the same candidates and the same guard that removes only members
|
|
64
|
+
whose refresh key is gone, so the fault costs the caller the list and the index nothing.
|
|
65
|
+
- **Logout no longer answers success while leaving the refresh session alive.** With a refresh
|
|
66
|
+
token that was present but malformed it blacklisted the access token, answered `204`, and left the
|
|
67
|
+
refresh session usable, so the client believed it had signed out. The request is now refused
|
|
68
|
+
before either happens.
|
|
69
|
+
- **"Sign out my other devices" no longer signs out every device when the token is stale.** A
|
|
70
|
+
refresh token that was well formed but no longer a live session was treated as having no session
|
|
71
|
+
to keep, so the whole account was revoked and the call answered success. It is refused instead,
|
|
72
|
+
and nothing is revoked.
|
|
73
|
+
|
|
74
|
+
### Changed
|
|
75
|
+
|
|
76
|
+
- **The package is built with tsup 9.** The JavaScript bundles are byte-for-byte what tsup 8
|
|
77
|
+
produced. The declaration files spell each entry point's export list as `export { … }` followed
|
|
78
|
+
by `export type { … }` where they wrote inline `type` modifiers; the exported names and which of
|
|
79
|
+
them are types are unchanged.
|
|
80
|
+
|
|
81
|
+
### Documentation
|
|
82
|
+
|
|
83
|
+
- **The Quick Start module block compiles under `strict`.** It reads the secret with
|
|
84
|
+
`config.getOrThrow('JWT_SECRET')`, since `config.get` answers `string | undefined`, and it now
|
|
85
|
+
imports the repository and email provider classes it uses, which the previous steps define. A
|
|
86
|
+
test type-checks the Quick Start blocks with every name they use declared.
|
|
87
|
+
|
|
88
|
+
## [1.4.15] - 2026-11-01
|
|
89
|
+
|
|
90
|
+
### Apply to a derived backend
|
|
91
|
+
|
|
92
|
+
- **`POST /password/forgot-password` and `POST /password/resend-otp` now answer `200` with an
|
|
93
|
+
empty JSON object, `{}`, where they answered `200` with no body.** The status and the
|
|
94
|
+
anti-enumeration behaviour are unchanged, and the body is the same for a known and an unknown
|
|
95
|
+
account. The wire contract now pins it. A client that asserted an empty body must accept JSON;
|
|
96
|
+
the bundled client discards the body and is unaffected.
|
|
97
|
+
|
|
98
|
+
### Fixed
|
|
99
|
+
|
|
100
|
+
- **`POST /password/change` refuses an empty `refreshToken` and accepts a long one.** The field is
|
|
101
|
+
the caller's own refresh token, sent in the body under bearer delivery. It was capped at 512
|
|
102
|
+
characters and an empty string passed validation, so a present-but-empty value was read as "no
|
|
103
|
+
token" and the request silently degraded. It is now held to the wire contract's opaque-token
|
|
104
|
+
bound: 1 to 2048 characters, answered `400 auth.validation` outside it. An absent field is
|
|
105
|
+
unchanged.
|
|
106
|
+
- **`registerAsync` with `imports` and `inject` from a non-global module failed at boot.** The
|
|
107
|
+
options factory was run a second time to configure the internal JWT registration, and that
|
|
108
|
+
registration was given `inject` but not `imports`, so Nest could not resolve the injected
|
|
109
|
+
provider. It worked only
|
|
110
|
+
when the module providing the injected token, typically `ConfigModule`, was global. The internal
|
|
111
|
+
registration now receives the same `imports`.
|
|
112
|
+
|
|
113
|
+
### Documentation
|
|
114
|
+
|
|
115
|
+
- **The Quick Start now runs as written.** A test executes its repository, email provider,
|
|
116
|
+
module, `main.ts` and controller blocks in a real application. Three gaps it found are closed:
|
|
117
|
+
the module block did not bind the email provider the previous step told the reader to bind, so a
|
|
118
|
+
verification code never reached the reader's mailer; it did not say which of the modules it
|
|
119
|
+
uses are the reader's own; and `tokenDelivery: 'cookie'` needs `cookie-parser` mounted, without
|
|
120
|
+
which a signed-in user is answered `401 auth.token_invalid` on every protected route.
|
|
121
|
+
|
|
21
122
|
## [1.4.14] - 2026-11-01
|
|
22
123
|
|
|
23
124
|
### Apply to a derived backend
|
|
@@ -4259,7 +4360,9 @@ ever installable.
|
|
|
4259
4360
|
- 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
|
|
4260
4361
|
- 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
|
|
4261
4362
|
|
|
4262
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.
|
|
4363
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.16...HEAD
|
|
4364
|
+
[1.4.16]: https://github.com/bymaxone/nest-auth/compare/v1.4.15...v1.4.16
|
|
4365
|
+
[1.4.15]: https://github.com/bymaxone/nest-auth/compare/v1.4.14...v1.4.15
|
|
4263
4366
|
[1.4.14]: https://github.com/bymaxone/nest-auth/compare/v1.4.13...v1.4.14
|
|
4264
4367
|
[1.4.13]: https://github.com/bymaxone/nest-auth/compare/v1.4.12...v1.4.13
|
|
4265
4368
|
[1.4.12]: https://github.com/bymaxone/nest-auth/compare/v1.4.11...v1.4.12
|
package/README.md
CHANGED
|
@@ -143,6 +143,9 @@ yarn add @bymax-one/nest-auth
|
|
|
143
143
|
# Server subpath (required)
|
|
144
144
|
pnpm add @nestjs/common @nestjs/core @nestjs/jwt @nestjs/throttler @nestjs/websockets ioredis class-validator class-transformer reflect-metadata
|
|
145
145
|
|
|
146
|
+
# Also needed with `tokenDelivery: 'cookie'` or `'both'` (see step 4): the library reads `req.cookies`
|
|
147
|
+
pnpm add cookie-parser
|
|
148
|
+
|
|
146
149
|
# React subpath (optional)
|
|
147
150
|
pnpm add react
|
|
148
151
|
|
|
@@ -524,8 +527,15 @@ import { Module } from '@nestjs/common'
|
|
|
524
527
|
import {
|
|
525
528
|
BymaxAuthModule,
|
|
526
529
|
BYMAX_AUTH_USER_REPOSITORY,
|
|
527
|
-
BYMAX_AUTH_REDIS_CLIENT
|
|
530
|
+
BYMAX_AUTH_REDIS_CLIENT,
|
|
531
|
+
BYMAX_AUTH_EMAIL_PROVIDER
|
|
528
532
|
} from '@bymax-one/nest-auth'
|
|
533
|
+
import { PrismaUserRepository } from './user.repository'
|
|
534
|
+
import { ResendEmailProvider } from './email.provider'
|
|
535
|
+
|
|
536
|
+
// Yours, not this library's: `ConfigModule` and `ConfigService` come from `@nestjs/config`,
|
|
537
|
+
// `DatabaseModule` is your module exporting the database client the repository uses, and
|
|
538
|
+
// `RedisModule` is your module exporting `RedisService`, whose `client` is an `ioredis` instance.
|
|
529
539
|
|
|
530
540
|
@Module({
|
|
531
541
|
imports: [
|
|
@@ -533,7 +543,7 @@ import {
|
|
|
533
543
|
imports: [ConfigModule, DatabaseModule, RedisModule],
|
|
534
544
|
useFactory: (config: ConfigService) => ({
|
|
535
545
|
jwt: {
|
|
536
|
-
secret: config.
|
|
546
|
+
secret: config.getOrThrow('JWT_SECRET'), // min 32 chars, high entropy
|
|
537
547
|
accessExpiresIn: '15m',
|
|
538
548
|
refreshExpiresInDays: 7
|
|
539
549
|
},
|
|
@@ -556,6 +566,10 @@ import {
|
|
|
556
566
|
provide: BYMAX_AUTH_USER_REPOSITORY,
|
|
557
567
|
useClass: PrismaUserRepository
|
|
558
568
|
},
|
|
569
|
+
{
|
|
570
|
+
provide: BYMAX_AUTH_EMAIL_PROVIDER,
|
|
571
|
+
useClass: ResendEmailProvider
|
|
572
|
+
},
|
|
559
573
|
{
|
|
560
574
|
provide: BYMAX_AUTH_REDIS_CLIENT,
|
|
561
575
|
useFactory: (redis: RedisService) => redis.client,
|
|
@@ -568,6 +582,22 @@ import {
|
|
|
568
582
|
export class AppModule {}
|
|
569
583
|
```
|
|
570
584
|
|
|
585
|
+
With `tokenDelivery: 'cookie'` (or `'both'`) the library reads the credential from `req.cookies`, and it takes no dependency on a parser, so mount one yourself. Without it a correctly signed-in user is answered `401 auth.token_invalid` on every protected route.
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
// main.ts
|
|
589
|
+
import { NestFactory } from '@nestjs/core'
|
|
590
|
+
import cookieParser from 'cookie-parser'
|
|
591
|
+
import { AppModule } from './app.module'
|
|
592
|
+
|
|
593
|
+
async function bootstrap() {
|
|
594
|
+
const app = await NestFactory.create(AppModule)
|
|
595
|
+
app.use(cookieParser())
|
|
596
|
+
await app.listen(3000)
|
|
597
|
+
}
|
|
598
|
+
bootstrap()
|
|
599
|
+
```
|
|
600
|
+
|
|
571
601
|
### 5. Protect Routes
|
|
572
602
|
|
|
573
603
|
```typescript
|
package/dist/client/index.d.cts
CHANGED
|
@@ -373,4 +373,5 @@ interface AuthClient {
|
|
|
373
373
|
*/
|
|
374
374
|
declare function createAuthClient(config: AuthClientConfig): AuthClient;
|
|
375
375
|
|
|
376
|
-
export {
|
|
376
|
+
export { createAuthClient, createAuthFetch };
|
|
377
|
+
export type { AuthClient, AuthClientConfig, AuthFetch, AuthFetchConfig, LoginInput, RefreshFailure, RefreshFailureReason, RefreshOutcome, RegisterInput, ResetPasswordInput };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -373,4 +373,5 @@ interface AuthClient {
|
|
|
373
373
|
*/
|
|
374
374
|
declare function createAuthClient(config: AuthClientConfig): AuthClient;
|
|
375
375
|
|
|
376
|
-
export {
|
|
376
|
+
export { createAuthClient, createAuthFetch };
|
|
377
|
+
export type { AuthClient, AuthClientConfig, AuthFetch, AuthFetchConfig, LoginInput, RefreshFailure, RefreshFailureReason, RefreshOutcome, RegisterInput, ResetPasswordInput };
|
package/dist/nextjs/index.d.cts
CHANGED
|
@@ -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 {
|
|
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 };
|
package/dist/nextjs/index.d.ts
CHANGED
|
@@ -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 {
|
|
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 };
|
package/dist/react/index.d.cts
CHANGED
|
@@ -352,4 +352,5 @@ interface UseAuthStatusResult {
|
|
|
352
352
|
*/
|
|
353
353
|
declare function useAuthStatus(): UseAuthStatusResult;
|
|
354
354
|
|
|
355
|
-
export {
|
|
355
|
+
export { AuthProvider, useAuth, useAuthStatus, useSession };
|
|
356
|
+
export type { AuthContextValue, AuthProviderProps, AuthStatus, UseAuthResult, UseAuthStatusResult, UseSessionResult };
|
package/dist/react/index.d.ts
CHANGED
|
@@ -352,4 +352,5 @@ interface UseAuthStatusResult {
|
|
|
352
352
|
*/
|
|
353
353
|
declare function useAuthStatus(): UseAuthStatusResult;
|
|
354
354
|
|
|
355
|
-
export {
|
|
355
|
+
export { AuthProvider, useAuth, useAuthStatus, useSession };
|
|
356
|
+
export type { AuthContextValue, AuthProviderProps, AuthStatus, UseAuthResult, UseAuthStatusResult, UseSessionResult };
|