najm-auth 3.3.1 → 3.3.2

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.
@@ -110,6 +110,7 @@ declare class NajmAuthClient {
110
110
  private _refreshWithCircuit;
111
111
  private _doRefresh;
112
112
  private handleUnauthorized;
113
+ private requestServerLogout;
113
114
  private applyTokens;
114
115
  private scheduleRefresh;
115
116
  private clearRefreshTimer;
@@ -1,4 +1,4 @@
1
- export { F as FetchClient, H as HydrateSession, N as NajmAuthClient, c as createAuthClient } from '../NajmAuthClient-ZtXTIUSF.js';
1
+ export { F as FetchClient, H as HydrateSession, N as NajmAuthClient, c as createAuthClient } from '../NajmAuthClient-BBl-GRis.js';
2
2
  import { D as DecodedToken, T as TabSyncMessage, S as SyncPayload } from '../types-BaSfgxqE.js';
3
3
  export { b as AuthClientConfig, h as AuthError, f as AuthEvent, g as AuthEventHandler, i as AuthEventMap, e as AuthState, A as AuthUser, j as AuthenticatedLogin, C as CredentialSetupPending, L as LoginCredentials, c as LoginResult, d as OAuthLoginOptions, O as OAuthProvider, a as RequestOptions, R as RetryConfig, k as ServerResponse, l as TokenPair } from '../types-BaSfgxqE.js';
4
4
 
@@ -364,7 +364,7 @@ var NajmAuthClient = class _NajmAuthClient {
364
364
  this.emit("logout", null);
365
365
  try {
366
366
  await pendingRefresh?.catch(() => void 0);
367
- await this.api.post(`${this.prefix}/logout`, { skipAuth: true });
367
+ await this.requestServerLogout();
368
368
  } catch (err) {
369
369
  this.emit("logoutError", err);
370
370
  }
@@ -549,6 +549,7 @@ var NajmAuthClient = class _NajmAuthClient {
549
549
  if (generation !== this.authGeneration) return;
550
550
  const shouldOpenCircuit = this.registerRefreshFailure(err);
551
551
  if (shouldOpenCircuit) {
552
+ await this.requestServerLogout().catch(() => void 0);
552
553
  this.resetState();
553
554
  this.emit("sessionExpired", null);
554
555
  if (err instanceof AuthError && err.status === 401) {
@@ -578,6 +579,9 @@ var NajmAuthClient = class _NajmAuthClient {
578
579
  return null;
579
580
  }
580
581
  }
582
+ async requestServerLogout() {
583
+ await this.api.post(`${this.prefix}/logout`, { skipAuth: true });
584
+ }
581
585
  applyTokens(tokens) {
582
586
  this.resetRefreshFailures();
583
587
  const decoded = decodeToken(tokens.accessToken);
@@ -618,7 +622,7 @@ var NajmAuthClient = class _NajmAuthClient {
618
622
  this.clearRefreshCircuitTimer();
619
623
  }
620
624
  registerRefreshFailure(err) {
621
- if (err instanceof AuthError && err.status === 401) {
625
+ if (err instanceof AuthError && [401, 403, 429].includes(err.status)) {
622
626
  this.refreshFailures = _NajmAuthClient.MAX_REFRESH_FAILURES;
623
627
  } else {
624
628
  this.refreshFailures += 1;
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode, CSSProperties, ReactElement } from 'react';
3
- import { N as NajmAuthClient, H as HydrateSession } from '../../NajmAuthClient-ZtXTIUSF.js';
3
+ import { N as NajmAuthClient, H as HydrateSession } from '../../NajmAuthClient-BBl-GRis.js';
4
4
  import { e as AuthState, A as AuthUser, c as LoginResult, h as AuthError, L as LoginCredentials, d as OAuthLoginOptions, f as AuthEvent, i as AuthEventMap } from '../../types-BaSfgxqE.js';
5
5
 
6
6
  interface AuthProviderProps {
@@ -1,5 +1,5 @@
1
1
  import { A as AuthUser, R as RetryConfig } from '../../types-BaSfgxqE.js';
2
- import { F as FetchClient, N as NajmAuthClient } from '../../NajmAuthClient-ZtXTIUSF.js';
2
+ import { F as FetchClient, N as NajmAuthClient } from '../../NajmAuthClient-BBl-GRis.js';
3
3
  import { ProxySessionMode } from '../edge.js';
4
4
  export { withAuthMiddleware } from '../edge.js';
5
5
  import { G as GetSessionConfig, S as ServerSession$1 } from '../../getSession-BthP85UA.js';
@@ -1075,7 +1075,7 @@ var NajmAuthClient = class _NajmAuthClient {
1075
1075
  this.emit("logout", null);
1076
1076
  try {
1077
1077
  await pendingRefresh?.catch(() => void 0);
1078
- await this.api.post(`${this.prefix}/logout`, { skipAuth: true });
1078
+ await this.requestServerLogout();
1079
1079
  } catch (err) {
1080
1080
  this.emit("logoutError", err);
1081
1081
  }
@@ -1260,6 +1260,7 @@ var NajmAuthClient = class _NajmAuthClient {
1260
1260
  if (generation !== this.authGeneration) return;
1261
1261
  const shouldOpenCircuit = this.registerRefreshFailure(err);
1262
1262
  if (shouldOpenCircuit) {
1263
+ await this.requestServerLogout().catch(() => void 0);
1263
1264
  this.resetState();
1264
1265
  this.emit("sessionExpired", null);
1265
1266
  if (err instanceof AuthError && err.status === 401) {
@@ -1289,6 +1290,9 @@ var NajmAuthClient = class _NajmAuthClient {
1289
1290
  return null;
1290
1291
  }
1291
1292
  }
1293
+ async requestServerLogout() {
1294
+ await this.api.post(`${this.prefix}/logout`, { skipAuth: true });
1295
+ }
1292
1296
  applyTokens(tokens) {
1293
1297
  this.resetRefreshFailures();
1294
1298
  const decoded = decodeToken(tokens.accessToken);
@@ -1329,7 +1333,7 @@ var NajmAuthClient = class _NajmAuthClient {
1329
1333
  this.clearRefreshCircuitTimer();
1330
1334
  }
1331
1335
  registerRefreshFailure(err) {
1332
- if (err instanceof AuthError && err.status === 401) {
1336
+ if (err instanceof AuthError && [401, 403, 429].includes(err.status)) {
1333
1337
  this.refreshFailures = _NajmAuthClient.MAX_REFRESH_FAILURES;
1334
1338
  } else {
1335
1339
  this.refreshFailures += 1;
package/dist/index.d.ts CHANGED
@@ -1626,7 +1626,7 @@ declare class AuthService {
1626
1626
  recoverSession(): Promise<{
1627
1627
  recovered: true;
1628
1628
  }>;
1629
- logoutUser(userId: string, authorization?: string): Promise<{
1629
+ logoutUser(userId: string | undefined, authorization?: string): Promise<{
1630
1630
  data: any;
1631
1631
  message: string;
1632
1632
  }>;
@@ -1703,7 +1703,7 @@ declare class AuthController {
1703
1703
  recoverSession(recoveryRequest: string | undefined, ctx: Context): Promise<{
1704
1704
  recovered: true;
1705
1705
  }>;
1706
- logoutUser(userId: string, authorization?: string): Promise<{
1706
+ logoutUser(userId: string | undefined, authorization?: string): Promise<{
1707
1707
  data: any;
1708
1708
  message: string;
1709
1709
  }>;
package/dist/index.js CHANGED
@@ -3361,9 +3361,14 @@ var AuthService = class AuthService2 {
3361
3361
  return { recovered: true };
3362
3362
  }
3363
3363
  async logoutUser(userId, authorization) {
3364
- await this.tokenService.logout(userId, authorization);
3365
- this.cookieManager.clearRefreshToken();
3366
- this.cookieManager.clearSessionCookie();
3364
+ try {
3365
+ if (userId) {
3366
+ await this.tokenService.logout(userId, authorization);
3367
+ }
3368
+ } finally {
3369
+ this.cookieManager.clearRefreshToken();
3370
+ this.cookieManager.clearSessionCookie();
3371
+ }
3367
3372
  return { data: null, message: this.t("auth.success.logout") };
3368
3373
  }
3369
3374
  /**
@@ -3857,8 +3862,6 @@ __decorate20([
3857
3862
  ], AuthController.prototype, "recoverSession", null);
3858
3863
  __decorate20([
3859
3864
  Post("/logout"),
3860
- isAuth(),
3861
- RateLimit({ limit: 10, window: "15m", key: "user" }),
3862
3865
  __param5(0, User2("id")),
3863
3866
  __param5(1, Headers("authorization")),
3864
3867
  __metadata20("design:type", Function),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "najm-auth",
3
- "version": "3.3.1",
3
+ "version": "3.3.2",
4
4
  "description": "Authentication and authorization library for najm framework",
5
5
  "type": "module",
6
6
  "files": [