@nauth-toolkit/client 0.1.73 → 0.1.75
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/dist/index.cjs +25 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.mjs +25 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1336,6 +1336,27 @@ declare class NAuthClient {
|
|
|
1336
1336
|
* Refresh tokens manually.
|
|
1337
1337
|
*/
|
|
1338
1338
|
refreshTokens(): Promise<TokenResponse>;
|
|
1339
|
+
/**
|
|
1340
|
+
* Clear all local auth state without making any network requests.
|
|
1341
|
+
*
|
|
1342
|
+
* WHY:
|
|
1343
|
+
* - When refresh fails with 401 (session expired), clients should immediately drop any cached
|
|
1344
|
+
* auth state (user + tokens) to prevent "sticky auth" across hard reloads.
|
|
1345
|
+
* - In cookie delivery modes, httpOnly cookies can only be cleared by the backend; this method
|
|
1346
|
+
* only clears client-side state (e.g., cached user + persisted tokens in JSON mode).
|
|
1347
|
+
*
|
|
1348
|
+
* @param options - Optional behavior flags
|
|
1349
|
+
* @returns Promise that resolves when local state is cleared
|
|
1350
|
+
*
|
|
1351
|
+
* @example
|
|
1352
|
+
* ```typescript
|
|
1353
|
+
* // Called by framework adapters/interceptors when refresh fails with 401
|
|
1354
|
+
* await client.clearLocalAuthState();
|
|
1355
|
+
* ```
|
|
1356
|
+
*/
|
|
1357
|
+
clearLocalAuthState(options?: {
|
|
1358
|
+
forgetDevice?: boolean;
|
|
1359
|
+
}): Promise<void>;
|
|
1339
1360
|
/**
|
|
1340
1361
|
* Logout current session.
|
|
1341
1362
|
*
|
package/dist/index.d.ts
CHANGED
|
@@ -1336,6 +1336,27 @@ declare class NAuthClient {
|
|
|
1336
1336
|
* Refresh tokens manually.
|
|
1337
1337
|
*/
|
|
1338
1338
|
refreshTokens(): Promise<TokenResponse>;
|
|
1339
|
+
/**
|
|
1340
|
+
* Clear all local auth state without making any network requests.
|
|
1341
|
+
*
|
|
1342
|
+
* WHY:
|
|
1343
|
+
* - When refresh fails with 401 (session expired), clients should immediately drop any cached
|
|
1344
|
+
* auth state (user + tokens) to prevent "sticky auth" across hard reloads.
|
|
1345
|
+
* - In cookie delivery modes, httpOnly cookies can only be cleared by the backend; this method
|
|
1346
|
+
* only clears client-side state (e.g., cached user + persisted tokens in JSON mode).
|
|
1347
|
+
*
|
|
1348
|
+
* @param options - Optional behavior flags
|
|
1349
|
+
* @returns Promise that resolves when local state is cleared
|
|
1350
|
+
*
|
|
1351
|
+
* @example
|
|
1352
|
+
* ```typescript
|
|
1353
|
+
* // Called by framework adapters/interceptors when refresh fails with 401
|
|
1354
|
+
* await client.clearLocalAuthState();
|
|
1355
|
+
* ```
|
|
1356
|
+
*/
|
|
1357
|
+
clearLocalAuthState(options?: {
|
|
1358
|
+
forgetDevice?: boolean;
|
|
1359
|
+
}): Promise<void>;
|
|
1339
1360
|
/**
|
|
1340
1361
|
* Logout current session.
|
|
1341
1362
|
*
|
package/dist/index.mjs
CHANGED
|
@@ -787,11 +787,35 @@ var NAuthClient = class {
|
|
|
787
787
|
const refreshFn = async () => {
|
|
788
788
|
return this.post(this.config.endpoints.refresh, body, false);
|
|
789
789
|
};
|
|
790
|
-
const tokens = await this.tokenManager.refreshOnce(refreshFn);
|
|
790
|
+
const tokens = await this.tokenManager.refreshOnce(refreshFn, { persist: tokenDelivery === "json" });
|
|
791
791
|
this.config.onTokenRefresh?.();
|
|
792
792
|
this.eventEmitter.emit({ type: "auth:refresh", data: { success: true }, timestamp: Date.now() });
|
|
793
793
|
return tokens;
|
|
794
794
|
}
|
|
795
|
+
// ============================================================================
|
|
796
|
+
// Local state management (no network)
|
|
797
|
+
// ============================================================================
|
|
798
|
+
/**
|
|
799
|
+
* Clear all local auth state without making any network requests.
|
|
800
|
+
*
|
|
801
|
+
* WHY:
|
|
802
|
+
* - When refresh fails with 401 (session expired), clients should immediately drop any cached
|
|
803
|
+
* auth state (user + tokens) to prevent "sticky auth" across hard reloads.
|
|
804
|
+
* - In cookie delivery modes, httpOnly cookies can only be cleared by the backend; this method
|
|
805
|
+
* only clears client-side state (e.g., cached user + persisted tokens in JSON mode).
|
|
806
|
+
*
|
|
807
|
+
* @param options - Optional behavior flags
|
|
808
|
+
* @returns Promise that resolves when local state is cleared
|
|
809
|
+
*
|
|
810
|
+
* @example
|
|
811
|
+
* ```typescript
|
|
812
|
+
* // Called by framework adapters/interceptors when refresh fails with 401
|
|
813
|
+
* await client.clearLocalAuthState();
|
|
814
|
+
* ```
|
|
815
|
+
*/
|
|
816
|
+
async clearLocalAuthState(options) {
|
|
817
|
+
await this.clearAuthState(options?.forgetDevice ?? false);
|
|
818
|
+
}
|
|
795
819
|
/**
|
|
796
820
|
* Logout current session.
|
|
797
821
|
*
|