@nauth-toolkit/client 0.1.99 → 0.1.101

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.d.mts CHANGED
@@ -361,6 +361,26 @@ interface SocialLoginOptions {
361
361
  * Default: 'login'
362
362
  */
363
363
  action?: 'login' | 'link';
364
+ /**
365
+ * Optional OAuth parameters to pass to the provider
366
+ *
367
+ * These parameters override config defaults and allow per-request customization.
368
+ * Use cases:
369
+ * - Google: Force account chooser, restrict to domain
370
+ * - Facebook: Rerequest declined permissions
371
+ * - Apple: Add nonce for ID token validation
372
+ *
373
+ * @example Google - Force account chooser
374
+ * ```typescript
375
+ * { prompt: 'select_account' }
376
+ * ```
377
+ *
378
+ * @example Facebook - Rerequest permissions
379
+ * ```typescript
380
+ * { auth_type: 'rerequest' }
381
+ * ```
382
+ */
383
+ oauthParams?: Record<string, string>;
364
384
  }
365
385
  /**
366
386
  * Linked social accounts response.
@@ -2735,6 +2755,9 @@ declare class NAuthClient {
2735
2755
  * - In cookie delivery modes, httpOnly cookies can only be cleared by the backend; this method
2736
2756
  * only clears client-side state (e.g., cached user + persisted tokens in JSON mode).
2737
2757
  *
2758
+ * IMPORTANT: Also clears any pending challenge sessions to prevent ghost states where the UI
2759
+ * shows a challenge screen but the backend session is invalid.
2760
+ *
2738
2761
  * @param options - Optional behavior flags
2739
2762
  * @returns Promise that resolves when local state is cleared
2740
2763
  *
package/dist/index.d.ts CHANGED
@@ -361,6 +361,26 @@ interface SocialLoginOptions {
361
361
  * Default: 'login'
362
362
  */
363
363
  action?: 'login' | 'link';
364
+ /**
365
+ * Optional OAuth parameters to pass to the provider
366
+ *
367
+ * These parameters override config defaults and allow per-request customization.
368
+ * Use cases:
369
+ * - Google: Force account chooser, restrict to domain
370
+ * - Facebook: Rerequest declined permissions
371
+ * - Apple: Add nonce for ID token validation
372
+ *
373
+ * @example Google - Force account chooser
374
+ * ```typescript
375
+ * { prompt: 'select_account' }
376
+ * ```
377
+ *
378
+ * @example Facebook - Rerequest permissions
379
+ * ```typescript
380
+ * { auth_type: 'rerequest' }
381
+ * ```
382
+ */
383
+ oauthParams?: Record<string, string>;
364
384
  }
365
385
  /**
366
386
  * Linked social accounts response.
@@ -2735,6 +2755,9 @@ declare class NAuthClient {
2735
2755
  * - In cookie delivery modes, httpOnly cookies can only be cleared by the backend; this method
2736
2756
  * only clears client-side state (e.g., cached user + persisted tokens in JSON mode).
2737
2757
  *
2758
+ * IMPORTANT: Also clears any pending challenge sessions to prevent ghost states where the UI
2759
+ * shows a challenge screen but the backend session is invalid.
2760
+ *
2738
2761
  * @param options - Optional behavior flags
2739
2762
  * @returns Promise that resolves when local state is cleared
2740
2763
  *
package/dist/index.mjs CHANGED
@@ -1625,6 +1625,9 @@ var NAuthClient = class {
1625
1625
  * - In cookie delivery modes, httpOnly cookies can only be cleared by the backend; this method
1626
1626
  * only clears client-side state (e.g., cached user + persisted tokens in JSON mode).
1627
1627
  *
1628
+ * IMPORTANT: Also clears any pending challenge sessions to prevent ghost states where the UI
1629
+ * shows a challenge screen but the backend session is invalid.
1630
+ *
1628
1631
  * @param options - Optional behavior flags
1629
1632
  * @returns Promise that resolves when local state is cleared
1630
1633
  *
@@ -1636,6 +1639,7 @@ var NAuthClient = class {
1636
1639
  */
1637
1640
  async clearLocalAuthState(options) {
1638
1641
  await this.clearAuthState(options?.forgetDevice ?? false);
1642
+ await this.clearChallenge();
1639
1643
  }
1640
1644
  /**
1641
1645
  * Logout current session.
@@ -1652,6 +1656,7 @@ var NAuthClient = class {
1652
1656
  console.warn("[nauth] Logout request failed (session may already be invalid):", error);
1653
1657
  } finally {
1654
1658
  await this.clearAuthState(forgetDevice);
1659
+ await this.clearChallenge();
1655
1660
  this.eventEmitter.emit({
1656
1661
  type: "auth:logout",
1657
1662
  data: { forgetDevice: !!forgetDevice, global: false },
@@ -1679,6 +1684,7 @@ var NAuthClient = class {
1679
1684
  true
1680
1685
  );
1681
1686
  await this.clearAuthState(forgetDevices);
1687
+ await this.clearChallenge();
1682
1688
  this.eventEmitter.emit({
1683
1689
  type: "auth:logout",
1684
1690
  data: { forgetDevice: !!forgetDevices, global: true },
@@ -1687,6 +1693,7 @@ var NAuthClient = class {
1687
1693
  return { revokedCount: result.revokedCount };
1688
1694
  } catch (error) {
1689
1695
  await this.clearAuthState(forgetDevices);
1696
+ await this.clearChallenge();
1690
1697
  this.eventEmitter.emit({
1691
1698
  type: "auth:logout",
1692
1699
  data: { forgetDevice: !!forgetDevices, global: true },
@@ -2006,6 +2013,9 @@ var NAuthClient = class {
2006
2013
  if (typeof options?.appState === "string" && options.appState.trim() !== "") {
2007
2014
  startUrl.searchParams.set("appState", options.appState);
2008
2015
  }
2016
+ if (options?.oauthParams && Object.keys(options.oauthParams).length > 0) {
2017
+ startUrl.searchParams.set("oauthParams", JSON.stringify(options.oauthParams));
2018
+ }
2009
2019
  window.location.href = startUrl.toString();
2010
2020
  }
2011
2021
  }
@@ -2260,6 +2270,10 @@ var NAuthClient = class {
2260
2270
  if (forgetDevice && this.config.tokenDelivery === "json") {
2261
2271
  await this.config.storage.removeItem(this.config.deviceTrust.storageKey);
2262
2272
  }
2273
+ try {
2274
+ await this.oauthStorage.removeItem(OAUTH_STATE_KEY2);
2275
+ } catch {
2276
+ }
2263
2277
  this.config.onAuthStateChange?.(null);
2264
2278
  }
2265
2279
  /**