@bymax-one/nest-auth 1.4.5 → 1.4.8

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.
@@ -296,18 +296,16 @@ declare function getSetCookieHeaders(headers: HeadersLike): string[];
296
296
  * API (`globalThis.crypto.subtle`) for signature verification and
297
297
  * never import from `node:crypto` or `@nestjs/jwt`.
298
298
  *
299
- * Two modes are supported:
300
- *
301
- * - **Verify mode**: when a `JWT_SECRET` is provided we call
302
- * {@link verifyJwtToken} which performs HS256 signature
303
- * verification and expiry validation. This is the production path.
304
- *
305
- * - **Decode-only mode**: when no secret is available (e.g., during
306
- * local development or in a proxy that delegates signature
307
- * verification to the upstream API) we fall back to
308
- * {@link decodeJwtToken} which parses the payload without
309
- * verifying the signature. Decode-only mode is explicit — the
310
- * caller must pass `undefined`/`null` as the secret.
299
+ * Two functions, and a missing secret never selects between them:
300
+ *
301
+ * - {@link verifyJwtToken} performs HS256 signature verification and
302
+ * expiry validation. It fails closed: a missing or empty secret
303
+ * returns an empty, invalid result rather than a decoded payload.
304
+ * This is the production path.
305
+ *
306
+ * - {@link decodeJwtToken} parses the payload without verifying the
307
+ * signature. It is called explicitly, for non-authoritative claims
308
+ * such as UI hints, and never as a fallback for a missing secret.
311
309
  *
312
310
  * SECURITY — algorithm pinning:
313
311
  *
@@ -296,18 +296,16 @@ declare function getSetCookieHeaders(headers: HeadersLike): string[];
296
296
  * API (`globalThis.crypto.subtle`) for signature verification and
297
297
  * never import from `node:crypto` or `@nestjs/jwt`.
298
298
  *
299
- * Two modes are supported:
300
- *
301
- * - **Verify mode**: when a `JWT_SECRET` is provided we call
302
- * {@link verifyJwtToken} which performs HS256 signature
303
- * verification and expiry validation. This is the production path.
304
- *
305
- * - **Decode-only mode**: when no secret is available (e.g., during
306
- * local development or in a proxy that delegates signature
307
- * verification to the upstream API) we fall back to
308
- * {@link decodeJwtToken} which parses the payload without
309
- * verifying the signature. Decode-only mode is explicit — the
310
- * caller must pass `undefined`/`null` as the secret.
299
+ * Two functions, and a missing secret never selects between them:
300
+ *
301
+ * - {@link verifyJwtToken} performs HS256 signature verification and
302
+ * expiry validation. It fails closed: a missing or empty secret
303
+ * returns an empty, invalid result rather than a decoded payload.
304
+ * This is the production path.
305
+ *
306
+ * - {@link decodeJwtToken} parses the payload without verifying the
307
+ * signature. It is called explicitly, for non-authoritative claims
308
+ * such as UI hints, and never as a fallback for a missing secret.
311
309
  *
312
310
  * SECURITY — algorithm pinning:
313
311
  *
@@ -13,7 +13,6 @@ var AuthContext = React.createContext(null);
13
13
 
14
14
  // src/react/AuthProvider.tsx
15
15
  var DEFAULT_REVALIDATE_INTERVAL_MS = 3e5;
16
- var DEFAULT_TENANT_ID = "default";
17
16
  var INITIAL_STATE = {
18
17
  user: null,
19
18
  status: "loading",
@@ -138,7 +137,6 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
138
137
  revalidateInterval
139
138
  ]);
140
139
  const login = React.useCallback(async (email, password, options) => {
141
- const tenantId = options?.tenantId ?? DEFAULT_TENANT_ID;
142
140
  syncedDispatch({
143
141
  type: "SET_LOADING"
144
142
  });
@@ -146,7 +144,9 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
146
144
  const result = await clientRef.current.login({
147
145
  email,
148
146
  password,
149
- tenantId
147
+ ...options?.tenantId !== void 0 ? {
148
+ tenantId: options.tenantId
149
+ } : {}
150
150
  });
151
151
  if ("mfaRequired" in result) {
152
152
  sessionGenerationRef.current = {};
@@ -216,7 +216,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
216
216
  ]);
217
217
  const forgotPassword = React.useCallback(
218
218
  async (email, tenantId) => {
219
- await clientRef.current.forgotPassword(email, tenantId ?? DEFAULT_TENANT_ID);
219
+ await clientRef.current.forgotPassword(email, tenantId);
220
220
  },
221
221
  // Stryker disable next-line ArrayDeclaration: empty deps array with only stable references in scope; a constant-string array re-runs identically
222
222
  []
@@ -101,8 +101,12 @@ interface AuthContextValue {
101
101
  *
102
102
  * @param email User's primary email address.
103
103
  * @param password Plaintext password — the server hashes on receipt.
104
- * @param options Optional metadata. `tenantId` defaults to `'default'`
105
- * when omitted so single-tenant apps can skip it.
104
+ * @param options Optional metadata. `tenantId` is forwarded exactly as
105
+ * given: omit it and the request body carries no tenant
106
+ * at all. Which of the two a deployment wants is the
107
+ * server's answer, not this signature's — one configuring
108
+ * `tenantIdResolver` refuses a body that names a tenant,
109
+ * and one without a resolver requires it.
106
110
  *
107
111
  * @returns The discriminated {@link LoginResult} — branch on
108
112
  * `'mfaRequired' in result` to handle the MFA challenge case.
@@ -154,6 +158,10 @@ interface AuthContextValue {
154
158
  * Initiate a password reset. The server returns 200 regardless of
155
159
  * whether the email is registered (anti-enumeration) — treat a
156
160
  * resolved Promise as "request accepted", not "email known".
161
+ *
162
+ * `tenantId` is forwarded exactly as given, under the same rule
163
+ * {@link AuthContextValue.login} documents: an omitted tenant reaches
164
+ * the server as an absent field rather than a default one.
157
165
  */
158
166
  forgotPassword: (email: string, tenantId?: string) => Promise<void>;
159
167
  /**
@@ -267,6 +275,11 @@ type UseAuthResult = Pick<AuthContextValue, 'login' | 'register' | 'logout' | 'f
267
275
  * surfacing as an undefined-method runtime failure inside a
268
276
  * component handler.
269
277
  *
278
+ * The example omits `tenantId`, which is correct for a deployment configuring
279
+ * `tenantIdResolver` — there the server decides the tenant and REFUSES a body that
280
+ * names one. Without a resolver the server requires it, so pass
281
+ * `{ tenantId }` as the third argument. See {@link AuthContextValue.login}.
282
+ *
270
283
  * @example
271
284
  * ```tsx
272
285
  * function LoginForm(): ReactNode {
@@ -101,8 +101,12 @@ interface AuthContextValue {
101
101
  *
102
102
  * @param email User's primary email address.
103
103
  * @param password Plaintext password — the server hashes on receipt.
104
- * @param options Optional metadata. `tenantId` defaults to `'default'`
105
- * when omitted so single-tenant apps can skip it.
104
+ * @param options Optional metadata. `tenantId` is forwarded exactly as
105
+ * given: omit it and the request body carries no tenant
106
+ * at all. Which of the two a deployment wants is the
107
+ * server's answer, not this signature's — one configuring
108
+ * `tenantIdResolver` refuses a body that names a tenant,
109
+ * and one without a resolver requires it.
106
110
  *
107
111
  * @returns The discriminated {@link LoginResult} — branch on
108
112
  * `'mfaRequired' in result` to handle the MFA challenge case.
@@ -154,6 +158,10 @@ interface AuthContextValue {
154
158
  * Initiate a password reset. The server returns 200 regardless of
155
159
  * whether the email is registered (anti-enumeration) — treat a
156
160
  * resolved Promise as "request accepted", not "email known".
161
+ *
162
+ * `tenantId` is forwarded exactly as given, under the same rule
163
+ * {@link AuthContextValue.login} documents: an omitted tenant reaches
164
+ * the server as an absent field rather than a default one.
157
165
  */
158
166
  forgotPassword: (email: string, tenantId?: string) => Promise<void>;
159
167
  /**
@@ -267,6 +275,11 @@ type UseAuthResult = Pick<AuthContextValue, 'login' | 'register' | 'logout' | 'f
267
275
  * surfacing as an undefined-method runtime failure inside a
268
276
  * component handler.
269
277
  *
278
+ * The example omits `tenantId`, which is correct for a deployment configuring
279
+ * `tenantIdResolver` — there the server decides the tenant and REFUSES a body that
280
+ * names one. Without a resolver the server requires it, so pass
281
+ * `{ tenantId }` as the third argument. See {@link AuthContextValue.login}.
282
+ *
270
283
  * @example
271
284
  * ```tsx
272
285
  * function LoginForm(): ReactNode {
@@ -7,7 +7,6 @@ var AuthContext = createContext(null);
7
7
 
8
8
  // src/react/AuthProvider.tsx
9
9
  var DEFAULT_REVALIDATE_INTERVAL_MS = 3e5;
10
- var DEFAULT_TENANT_ID = "default";
11
10
  var INITIAL_STATE = {
12
11
  user: null,
13
12
  status: "loading",
@@ -132,7 +131,6 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
132
131
  revalidateInterval
133
132
  ]);
134
133
  const login = useCallback(async (email, password, options) => {
135
- const tenantId = options?.tenantId ?? DEFAULT_TENANT_ID;
136
134
  syncedDispatch({
137
135
  type: "SET_LOADING"
138
136
  });
@@ -140,7 +138,9 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
140
138
  const result = await clientRef.current.login({
141
139
  email,
142
140
  password,
143
- tenantId
141
+ ...options?.tenantId !== void 0 ? {
142
+ tenantId: options.tenantId
143
+ } : {}
144
144
  });
145
145
  if ("mfaRequired" in result) {
146
146
  sessionGenerationRef.current = {};
@@ -210,7 +210,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
210
210
  ]);
211
211
  const forgotPassword = useCallback(
212
212
  async (email, tenantId) => {
213
- await clientRef.current.forgotPassword(email, tenantId ?? DEFAULT_TENANT_ID);
213
+ await clientRef.current.forgotPassword(email, tenantId);
214
214
  },
215
215
  // Stryker disable next-line ArrayDeclaration: empty deps array with only stable references in scope; a constant-string array re-runs identically
216
216
  []