@nauth-toolkit/client 0.1.21 → 0.1.23

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.
@@ -845,7 +845,9 @@ var _NAuthClient = class _NAuthClient {
845
845
  */
846
846
  async confirmForgotPassword(identifier, code, newPassword) {
847
847
  const payload = { identifier, code, newPassword };
848
- return this.post(this.config.endpoints.confirmForgotPassword, payload);
848
+ const result = await this.post(this.config.endpoints.confirmForgotPassword, payload);
849
+ await this.clearAuthState(false);
850
+ return result;
849
851
  }
850
852
  /**
851
853
  * Request password change (must change on next login).
@@ -981,11 +983,9 @@ var _NAuthClient = class _NAuthClient {
981
983
  const base = this.config.baseUrl.replace(/\/$/, "");
982
984
  const startUrl = new URL(`${base}${startPath}`);
983
985
  const returnTo = options?.returnTo ?? this.config.redirects?.success ?? "/";
984
- const action = options?.action ?? "login";
985
986
  startUrl.searchParams.set("returnTo", returnTo);
986
- startUrl.searchParams.set("action", action);
987
- if (options?.delivery === "cookies" || options?.delivery === "json") {
988
- startUrl.searchParams.set("delivery", options.delivery);
987
+ if (options?.action === "link") {
988
+ startUrl.searchParams.set("action", "link");
989
989
  }
990
990
  if (typeof options?.appState === "string" && options.appState.trim() !== "") {
991
991
  startUrl.searchParams.set("appState", options.appState);
@@ -1196,7 +1196,9 @@ var _NAuthClient = class _NAuthClient {
1196
1196
  await this.setDeviceToken(response.deviceToken);
1197
1197
  }
1198
1198
  if (response.user) {
1199
- await this.setUser(response.user);
1199
+ const user = response.user;
1200
+ user.sessionAuthMethod = response.authMethod ?? null;
1201
+ await this.setUser(user);
1200
1202
  }
1201
1203
  await this.clearChallenge();
1202
1204
  }
@@ -1268,6 +1270,15 @@ var _NAuthClient = class _NAuthClient {
1268
1270
  headers["Authorization"] = `Bearer ${accessToken}`;
1269
1271
  }
1270
1272
  }
1273
+ if (this.config.tokenDelivery === "json") {
1274
+ try {
1275
+ const deviceToken = await this.config.storage.getItem(this.config.deviceTrust.storageKey);
1276
+ if (deviceToken) {
1277
+ headers[this.config.deviceTrust.headerName] = deviceToken;
1278
+ }
1279
+ } catch {
1280
+ }
1281
+ }
1271
1282
  if (this.config.tokenDelivery === "cookies" && hasWindow()) {
1272
1283
  const csrfToken = this.getCsrfToken();
1273
1284
  if (csrfToken) {
@@ -1516,6 +1527,22 @@ var AuthService = class {
1516
1527
  refresh() {
1517
1528
  return (0, import_rxjs2.from)(this.client.refreshTokens());
1518
1529
  }
1530
+ /**
1531
+ * Refresh tokens (promise-based).
1532
+ *
1533
+ * Returns a promise instead of an Observable, matching the core NAuthClient API.
1534
+ * Useful for async/await patterns in guards and interceptors.
1535
+ *
1536
+ * @returns Promise of TokenResponse
1537
+ *
1538
+ * @example
1539
+ * ```typescript
1540
+ * const tokens = await auth.refreshTokensPromise();
1541
+ * ```
1542
+ */
1543
+ refreshTokensPromise() {
1544
+ return this.client.refreshTokens();
1545
+ }
1519
1546
  // ============================================================================
1520
1547
  // Account Recovery (Forgot Password)
1521
1548
  // ============================================================================
@@ -1580,6 +1607,25 @@ var AuthService = class {
1580
1607
  })
1581
1608
  );
1582
1609
  }
1610
+ /**
1611
+ * Get current user profile (promise-based).
1612
+ *
1613
+ * Returns a promise instead of an Observable, matching the core NAuthClient API.
1614
+ * Useful for async/await patterns in guards and interceptors.
1615
+ *
1616
+ * @returns Promise of current user profile
1617
+ *
1618
+ * @example
1619
+ * ```typescript
1620
+ * const user = await auth.getProfilePromise();
1621
+ * ```
1622
+ */
1623
+ getProfilePromise() {
1624
+ return this.client.getProfile().then((user) => {
1625
+ this.currentUserSubject.next(user);
1626
+ return user;
1627
+ });
1628
+ }
1583
1629
  /**
1584
1630
  * Update user profile.
1585
1631
  *
@@ -1674,6 +1720,23 @@ var AuthService = class {
1674
1720
  exchangeSocialRedirect(exchangeToken) {
1675
1721
  return (0, import_rxjs2.from)(this.client.exchangeSocialRedirect(exchangeToken).then((res) => this.updateChallengeState(res)));
1676
1722
  }
1723
+ /**
1724
+ * Exchange an exchangeToken (from redirect callback URL) into an AuthResponse (promise-based).
1725
+ *
1726
+ * Returns a promise instead of an Observable, matching the core NAuthClient API.
1727
+ * Useful for async/await patterns in guards and interceptors.
1728
+ *
1729
+ * @param exchangeToken - One-time exchange token from the callback URL
1730
+ * @returns Promise of AuthResponse
1731
+ *
1732
+ * @example
1733
+ * ```typescript
1734
+ * const response = await auth.exchangeSocialRedirectPromise(exchangeToken);
1735
+ * ```
1736
+ */
1737
+ exchangeSocialRedirectPromise(exchangeToken) {
1738
+ return this.client.exchangeSocialRedirect(exchangeToken).then((res) => this.updateChallengeState(res));
1739
+ }
1677
1740
  /**
1678
1741
  * Verify native social token (mobile).
1679
1742
  *
@@ -1953,7 +2016,7 @@ var authInterceptor = /* @__PURE__ */ __name((req, next) => {
1953
2016
  if (config.debug) {
1954
2017
  console.warn("[nauth-interceptor] Starting refresh...");
1955
2018
  }
1956
- const refresh$ = tokenDelivery === "cookies" ? http.post(refreshUrl, {}, { withCredentials: true }) : (0, import_rxjs3.from)(authService.getClient().refreshTokens());
2019
+ const refresh$ = tokenDelivery === "cookies" ? http.post(refreshUrl, {}, { withCredentials: true }) : (0, import_rxjs3.from)(authService.refreshTokensPromise());
1957
2020
  return refresh$.pipe(
1958
2021
  (0, import_rxjs3.switchMap)((response) => {
1959
2022
  if (config.debug) {
@@ -2080,9 +2143,18 @@ var socialRedirectCallbackGuard = /* @__PURE__ */ __name(async () => {
2080
2143
  return false;
2081
2144
  }
2082
2145
  if (!exchangeToken) {
2083
- return true;
2146
+ try {
2147
+ await auth.getProfilePromise();
2148
+ } catch {
2149
+ const errorUrl = config.redirects?.oauthError || "/login";
2150
+ window.location.replace(errorUrl);
2151
+ return false;
2152
+ }
2153
+ const successUrl2 = config.redirects?.success || "/";
2154
+ window.location.replace(successUrl2);
2155
+ return false;
2084
2156
  }
2085
- const response = await auth.getClient().exchangeSocialRedirect(exchangeToken);
2157
+ const response = await auth.exchangeSocialRedirectPromise(exchangeToken);
2086
2158
  if (response.challengeName) {
2087
2159
  const challengeBase = config.redirects?.challengeBase || "/auth/challenge";
2088
2160
  const challengeRoute = response.challengeName.toLowerCase().replace(/_/g, "-");