@nauth-toolkit/client 0.1.95 → 0.1.98
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 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +26 -3
- package/dist/index.d.ts +26 -3
- package/dist/index.mjs +25 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1619,6 +1619,18 @@ var NAuthClient = class {
|
|
|
1619
1619
|
}
|
|
1620
1620
|
/**
|
|
1621
1621
|
* Refresh tokens manually.
|
|
1622
|
+
*
|
|
1623
|
+
* @throws {NAuthClientError} When refresh fails (e.g., session expired)
|
|
1624
|
+
*
|
|
1625
|
+
* @example
|
|
1626
|
+
* ```typescript
|
|
1627
|
+
* try {
|
|
1628
|
+
* await client.refreshTokens();
|
|
1629
|
+
* } catch (error) {
|
|
1630
|
+
* // Session expired - user is already logged out automatically
|
|
1631
|
+
* router.navigate(['/login']);
|
|
1632
|
+
* }
|
|
1633
|
+
* ```
|
|
1622
1634
|
*/
|
|
1623
1635
|
async refreshTokens() {
|
|
1624
1636
|
const tokenDelivery = this.getTokenDeliveryMode();
|
|
@@ -1629,10 +1641,19 @@ var NAuthClient = class {
|
|
|
1629
1641
|
const refreshFn = async () => {
|
|
1630
1642
|
return this.post(this.config.endpoints.refresh, body, false);
|
|
1631
1643
|
};
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
|
|
1644
|
+
try {
|
|
1645
|
+
const tokens = await this.tokenManager.refreshOnce(refreshFn, { persist: tokenDelivery === "json" });
|
|
1646
|
+
this.config.onTokenRefresh?.();
|
|
1647
|
+
this.eventEmitter.emit({ type: "auth:refresh", data: { success: true }, timestamp: Date.now() });
|
|
1648
|
+
return tokens;
|
|
1649
|
+
} catch (error) {
|
|
1650
|
+
if (error instanceof NAuthClientError && error.statusCode === 401) {
|
|
1651
|
+
await this.clearLocalAuthState();
|
|
1652
|
+
this.config.onSessionExpired?.();
|
|
1653
|
+
this.eventEmitter.emit({ type: "auth:session_expired", data: {}, timestamp: Date.now() });
|
|
1654
|
+
}
|
|
1655
|
+
throw error;
|
|
1656
|
+
}
|
|
1636
1657
|
}
|
|
1637
1658
|
// ============================================================================
|
|
1638
1659
|
// Local state management (no network)
|