@nauth-toolkit/client 0.1.17 → 0.1.21

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.
@@ -40,7 +40,7 @@ __export(index_exports, {
40
40
  NAuthModule: () => NAuthModule,
41
41
  authGuard: () => authGuard,
42
42
  authInterceptor: () => authInterceptor,
43
- oauthCallbackGuard: () => oauthCallbackGuard
43
+ socialRedirectCallbackGuard: () => socialRedirectCallbackGuard
44
44
  });
45
45
  module.exports = __toCommonJS(index_exports);
46
46
 
@@ -224,12 +224,12 @@ var defaultEndpoints = {
224
224
  mfaPreferred: "/mfa/preferred-method",
225
225
  mfaBackupCodes: "/mfa/backup-codes/generate",
226
226
  mfaExemption: "/mfa/exemption",
227
- socialAuthUrl: "/social/auth-url",
228
- socialCallback: "/social/callback",
229
227
  socialLinked: "/social/linked",
230
228
  socialLink: "/social/link",
231
229
  socialUnlink: "/social/unlink",
232
230
  socialVerify: "/social/:provider/verify",
231
+ socialRedirectStart: "/social/:provider/redirect",
232
+ socialExchange: "/social/exchange",
233
233
  trustDevice: "/trust-device",
234
234
  isTrustedDevice: "/is-trusted-device",
235
235
  auditHistory: "/audit/history",
@@ -381,6 +381,9 @@ var _BrowserStorage = class _BrowserStorage {
381
381
  async removeItem(key) {
382
382
  this.storage.removeItem(key);
383
383
  }
384
+ async clear() {
385
+ this.storage.clear();
386
+ }
384
387
  };
385
388
  __name(_BrowserStorage, "BrowserStorage");
386
389
  var BrowserStorage = _BrowserStorage;
@@ -399,6 +402,9 @@ var _InMemoryStorage = class _InMemoryStorage {
399
402
  async removeItem(key) {
400
403
  this.store.delete(key);
401
404
  }
405
+ async clear() {
406
+ this.store.clear();
407
+ }
402
408
  };
403
409
  __name(_InMemoryStorage, "InMemoryStorage");
404
410
  var InMemoryStorage = _InMemoryStorage;
@@ -523,9 +529,9 @@ var _FetchAdapter = class _FetchAdapter {
523
529
  });
524
530
  if (!response.ok) {
525
531
  const errorData = typeof data === "object" && data !== null ? data : {};
526
- const code = typeof errorData["code"] === "string" ? errorData.code : "INTERNAL_ERROR" /* INTERNAL_ERROR */;
527
- const message = typeof errorData["message"] === "string" ? errorData.message : `Request failed with status ${status}`;
528
- const timestamp = typeof errorData["timestamp"] === "string" ? errorData.timestamp : void 0;
532
+ const code = typeof errorData["code"] === "string" ? errorData["code"] : "INTERNAL_ERROR" /* INTERNAL_ERROR */;
533
+ const message = typeof errorData["message"] === "string" ? errorData["message"] : `Request failed with status ${status}`;
534
+ const timestamp = typeof errorData["timestamp"] === "string" ? errorData["timestamp"] : void 0;
529
535
  const details = errorData["details"];
530
536
  throw new NAuthClientError(code, message, {
531
537
  statusCode: status,
@@ -949,126 +955,59 @@ var _NAuthClient = class _NAuthClient {
949
955
  // Social Authentication
950
956
  // ============================================================================
951
957
  /**
952
- * Start social OAuth flow with automatic state management.
958
+ * Start redirect-first social OAuth flow (web).
959
+ *
960
+ * This performs a browser navigation to:
961
+ * `GET {baseUrl}/social/:provider/redirect?returnTo=...&appState=...`
953
962
  *
954
- * Generates a secure state token, stores OAuth context, and redirects to the OAuth provider.
955
- * After OAuth callback, use `handleOAuthCallback()` to complete authentication.
963
+ * The backend:
964
+ * - generates and stores CSRF state (cluster-safe)
965
+ * - redirects the user to the provider
966
+ * - completes OAuth on callback and sets cookies (or issues an exchange token)
967
+ * - redirects back to `returnTo` with `appState` (and `exchangeToken` for json/hybrid)
956
968
  *
957
969
  * @param provider - OAuth provider ('google', 'apple', 'facebook')
958
- * @param options - Optional configuration
970
+ * @param options - Optional redirect options
959
971
  *
960
972
  * @example
961
973
  * ```typescript
962
- * // Simple usage
963
- * await client.loginWithSocial('google');
964
- *
965
- * // With custom redirect URI
966
- * await client.loginWithSocial('apple', {
967
- * redirectUri: 'https://example.com/auth/callback'
968
- * });
974
+ * await client.loginWithSocial('google', { returnTo: '/auth/callback', appState: '12345' });
969
975
  * ```
970
976
  */
971
- async loginWithSocial(provider, _options) {
977
+ async loginWithSocial(provider, options) {
972
978
  this.eventEmitter.emit({ type: "oauth:started", data: { provider }, timestamp: Date.now() });
973
- const { url } = await this.getSocialAuthUrl({ provider });
974
979
  if (hasWindow()) {
975
- window.location.href = url;
976
- }
977
- }
978
- /**
979
- * Auto-detect and handle OAuth callback.
980
- *
981
- * Call this on app initialization or in callback route.
982
- * Returns null if not an OAuth callback (no provider/code params).
983
- *
984
- * The SDK validates the state token, completes authentication via backend,
985
- * and emits appropriate events.
986
- *
987
- * @param urlOrParams - Optional URL string or URLSearchParams (auto-detects from window.location if not provided)
988
- * @returns AuthResponse if OAuth callback detected, null otherwise
989
- *
990
- * @example
991
- * ```typescript
992
- * // Auto-detect on app init
993
- * const response = await client.handleOAuthCallback();
994
- * if (response) {
995
- * if (response.challengeName) {
996
- * router.navigate(['/challenge', response.challengeName]);
997
- * } else {
998
- * router.navigate(['/']); // Navigate to your app's home route
999
- * }
1000
- * }
1001
- *
1002
- * // In callback route
1003
- * const response = await client.handleOAuthCallback(window.location.search);
1004
- * ```
1005
- */
1006
- async handleOAuthCallback(urlOrParams) {
1007
- let params;
1008
- if (urlOrParams instanceof URLSearchParams) {
1009
- params = urlOrParams;
1010
- } else if (typeof urlOrParams === "string") {
1011
- params = new URLSearchParams(urlOrParams);
1012
- } else if (hasWindow()) {
1013
- params = new URLSearchParams(window.location.search);
1014
- } else {
1015
- return null;
1016
- }
1017
- const provider = params.get("provider");
1018
- const code = params.get("code");
1019
- const state = params.get("state");
1020
- const error = params.get("error");
1021
- if (!provider || !code && !error) {
1022
- return null;
1023
- }
1024
- this.eventEmitter.emit({ type: "oauth:callback", data: { provider }, timestamp: Date.now() });
1025
- try {
1026
- if (error) {
1027
- const authError = new NAuthClientError(
1028
- "SOCIAL_TOKEN_INVALID" /* SOCIAL_TOKEN_INVALID */,
1029
- params.get("error_description") || error,
1030
- { details: { error, provider } }
1031
- );
1032
- this.eventEmitter.emit({ type: "oauth:error", data: authError, timestamp: Date.now() });
1033
- throw authError;
1034
- }
1035
- if (!state) {
1036
- throw new NAuthClientError("CHALLENGE_INVALID" /* CHALLENGE_INVALID */, "Missing OAuth state parameter");
980
+ const startPath = this.config.endpoints.socialRedirectStart.replace(":provider", provider);
981
+ const base = this.config.baseUrl.replace(/\/$/, "");
982
+ const startUrl = new URL(`${base}${startPath}`);
983
+ const returnTo = options?.returnTo ?? this.config.redirects?.success ?? "/";
984
+ const action = options?.action ?? "login";
985
+ 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);
1037
989
  }
1038
- const response = await this.handleSocialCallback({
1039
- provider,
1040
- code,
1041
- state
1042
- });
1043
- if (response.challengeName) {
1044
- this.eventEmitter.emit({ type: "auth:challenge", data: response, timestamp: Date.now() });
1045
- } else {
1046
- this.eventEmitter.emit({ type: "auth:success", data: response, timestamp: Date.now() });
990
+ if (typeof options?.appState === "string" && options.appState.trim() !== "") {
991
+ startUrl.searchParams.set("appState", options.appState);
1047
992
  }
1048
- this.eventEmitter.emit({ type: "oauth:completed", data: response, timestamp: Date.now() });
1049
- return response;
1050
- } catch (error2) {
1051
- const authError = error2 instanceof NAuthClientError ? error2 : new NAuthClientError(
1052
- "SOCIAL_TOKEN_INVALID" /* SOCIAL_TOKEN_INVALID */,
1053
- error2.message || "OAuth callback failed"
1054
- );
1055
- this.eventEmitter.emit({ type: "oauth:error", data: authError, timestamp: Date.now() });
1056
- throw authError;
993
+ window.location.href = startUrl.toString();
1057
994
  }
1058
995
  }
1059
996
  /**
1060
- * Get social auth URL (low-level API).
997
+ * Exchange an `exchangeToken` (from redirect callback URL) into an AuthResponse.
1061
998
  *
1062
- * For most cases, use `loginWithSocial()` which handles state management automatically.
1063
- */
1064
- async getSocialAuthUrl(request) {
1065
- return this.post(this.config.endpoints.socialAuthUrl, request);
1066
- }
1067
- /**
1068
- * Handle social callback.
999
+ * Used for `tokenDelivery: 'json'` or hybrid flows where the backend redirects back
1000
+ * with `exchangeToken` instead of setting cookies.
1001
+ *
1002
+ * @param exchangeToken - One-time exchange token from the callback URL
1003
+ * @returns AuthResponse
1069
1004
  */
1070
- async handleSocialCallback(request) {
1071
- const result = await this.post(this.config.endpoints.socialCallback, request);
1005
+ async exchangeSocialRedirect(exchangeToken) {
1006
+ const token = exchangeToken?.trim();
1007
+ if (!token) {
1008
+ throw new NAuthClientError("CHALLENGE_INVALID" /* CHALLENGE_INVALID */, "Missing exchangeToken");
1009
+ }
1010
+ const result = await this.post(this.config.endpoints.socialExchange, { exchangeToken: token });
1072
1011
  await this.handleAuthResponse(result);
1073
1012
  return result;
1074
1013
  }
@@ -1592,6 +1531,76 @@ var AuthService = class {
1592
1531
  confirmForgotPassword(identifier, code, newPassword) {
1593
1532
  return (0, import_rxjs2.from)(this.client.confirmForgotPassword(identifier, code, newPassword));
1594
1533
  }
1534
+ /**
1535
+ * Change user password (requires current password).
1536
+ *
1537
+ * @param oldPassword - Current password
1538
+ * @param newPassword - New password (must meet requirements)
1539
+ * @returns Observable that completes when password is changed
1540
+ *
1541
+ * @example
1542
+ * ```typescript
1543
+ * this.auth.changePassword('oldPassword123', 'newSecurePassword456!').subscribe({
1544
+ * next: () => console.log('Password changed successfully'),
1545
+ * error: (err) => console.error('Failed to change password:', err)
1546
+ * });
1547
+ * ```
1548
+ */
1549
+ changePassword(oldPassword, newPassword) {
1550
+ return (0, import_rxjs2.from)(this.client.changePassword(oldPassword, newPassword));
1551
+ }
1552
+ /**
1553
+ * Request password change (must change on next login).
1554
+ *
1555
+ * @returns Observable that completes when request is sent
1556
+ */
1557
+ requestPasswordChange() {
1558
+ return (0, import_rxjs2.from)(this.client.requestPasswordChange());
1559
+ }
1560
+ // ============================================================================
1561
+ // Profile Management
1562
+ // ============================================================================
1563
+ /**
1564
+ * Get current user profile.
1565
+ *
1566
+ * @returns Observable of current user profile
1567
+ *
1568
+ * @example
1569
+ * ```typescript
1570
+ * this.auth.getProfile().subscribe(user => {
1571
+ * console.log('User profile:', user);
1572
+ * });
1573
+ * ```
1574
+ */
1575
+ getProfile() {
1576
+ return (0, import_rxjs2.from)(
1577
+ this.client.getProfile().then((user) => {
1578
+ this.currentUserSubject.next(user);
1579
+ return user;
1580
+ })
1581
+ );
1582
+ }
1583
+ /**
1584
+ * Update user profile.
1585
+ *
1586
+ * @param updates - Profile fields to update
1587
+ * @returns Observable of updated user profile
1588
+ *
1589
+ * @example
1590
+ * ```typescript
1591
+ * this.auth.updateProfile({ firstName: 'John', lastName: 'Doe' }).subscribe(user => {
1592
+ * console.log('Profile updated:', user);
1593
+ * });
1594
+ * ```
1595
+ */
1596
+ updateProfile(updates) {
1597
+ return (0, import_rxjs2.from)(
1598
+ this.client.updateProfile(updates).then((user) => {
1599
+ this.currentUserSubject.next(user);
1600
+ return user;
1601
+ })
1602
+ );
1603
+ }
1595
1604
  // ============================================================================
1596
1605
  // Challenge Flow Methods (Essential for any auth flow)
1597
1606
  // ============================================================================
@@ -1648,26 +1657,172 @@ var AuthService = class {
1648
1657
  // ============================================================================
1649
1658
  /**
1650
1659
  * Initiate social OAuth login flow.
1651
- * Redirects to OAuth provider with automatic state management.
1660
+ * Redirects the browser to backend `/auth/social/:provider/redirect`.
1652
1661
  */
1653
1662
  loginWithSocial(provider, options) {
1654
1663
  return this.client.loginWithSocial(provider, options);
1655
1664
  }
1656
1665
  /**
1657
- * Get social auth URL to redirect user for OAuth (low-level API).
1666
+ * Exchange an exchangeToken (from redirect callback URL) into an AuthResponse.
1667
+ *
1668
+ * Used for `tokenDelivery: 'json'` or hybrid flows where the backend redirects back
1669
+ * with `exchangeToken` instead of setting cookies.
1670
+ *
1671
+ * @param exchangeToken - One-time exchange token from the callback URL
1672
+ * @returns Observable of AuthResponse
1658
1673
  */
1659
- getSocialAuthUrl(provider, redirectUri) {
1660
- return (0, import_rxjs2.from)(
1661
- this.client.getSocialAuthUrl({ provider, redirectUri })
1662
- );
1674
+ exchangeSocialRedirect(exchangeToken) {
1675
+ return (0, import_rxjs2.from)(this.client.exchangeSocialRedirect(exchangeToken).then((res) => this.updateChallengeState(res)));
1663
1676
  }
1664
1677
  /**
1665
- * Handle social auth callback (low-level API).
1678
+ * Verify native social token (mobile).
1679
+ *
1680
+ * @param request - Social verification request with provider and token
1681
+ * @returns Observable of AuthResponse
1666
1682
  */
1667
- handleSocialCallback(provider, code, state) {
1668
- return (0, import_rxjs2.from)(
1669
- this.client.handleSocialCallback({ provider, code, state }).then((res) => this.updateChallengeState(res))
1670
- );
1683
+ verifyNativeSocial(request) {
1684
+ return (0, import_rxjs2.from)(this.client.verifyNativeSocial(request).then((res) => this.updateChallengeState(res)));
1685
+ }
1686
+ /**
1687
+ * Get linked social accounts.
1688
+ *
1689
+ * @returns Observable of linked accounts response
1690
+ */
1691
+ getLinkedAccounts() {
1692
+ return (0, import_rxjs2.from)(this.client.getLinkedAccounts());
1693
+ }
1694
+ /**
1695
+ * Link social account.
1696
+ *
1697
+ * @param provider - Social provider to link
1698
+ * @param code - OAuth authorization code
1699
+ * @param state - OAuth state parameter
1700
+ * @returns Observable with success message
1701
+ */
1702
+ linkSocialAccount(provider, code, state) {
1703
+ return (0, import_rxjs2.from)(this.client.linkSocialAccount(provider, code, state));
1704
+ }
1705
+ /**
1706
+ * Unlink social account.
1707
+ *
1708
+ * @param provider - Social provider to unlink
1709
+ * @returns Observable with success message
1710
+ */
1711
+ unlinkSocialAccount(provider) {
1712
+ return (0, import_rxjs2.from)(this.client.unlinkSocialAccount(provider));
1713
+ }
1714
+ // ============================================================================
1715
+ // MFA Management
1716
+ // ============================================================================
1717
+ /**
1718
+ * Get MFA status for the current user.
1719
+ *
1720
+ * @returns Observable of MFA status
1721
+ */
1722
+ getMfaStatus() {
1723
+ return (0, import_rxjs2.from)(this.client.getMfaStatus());
1724
+ }
1725
+ /**
1726
+ * Get MFA devices for the current user.
1727
+ *
1728
+ * @returns Observable of MFA devices array
1729
+ */
1730
+ getMfaDevices() {
1731
+ return (0, import_rxjs2.from)(this.client.getMfaDevices());
1732
+ }
1733
+ /**
1734
+ * Setup MFA device (authenticated user).
1735
+ *
1736
+ * @param method - MFA method to set up
1737
+ * @returns Observable of setup data
1738
+ */
1739
+ setupMfaDevice(method) {
1740
+ return (0, import_rxjs2.from)(this.client.setupMfaDevice(method));
1741
+ }
1742
+ /**
1743
+ * Verify MFA setup (authenticated user).
1744
+ *
1745
+ * @param method - MFA method
1746
+ * @param setupData - Setup data from setupMfaDevice
1747
+ * @param deviceName - Optional device name
1748
+ * @returns Observable with device ID
1749
+ */
1750
+ verifyMfaSetup(method, setupData, deviceName) {
1751
+ return (0, import_rxjs2.from)(this.client.verifyMfaSetup(method, setupData, deviceName));
1752
+ }
1753
+ /**
1754
+ * Remove MFA device.
1755
+ *
1756
+ * @param method - MFA method to remove
1757
+ * @returns Observable with success message
1758
+ */
1759
+ removeMfaDevice(method) {
1760
+ return (0, import_rxjs2.from)(this.client.removeMfaDevice(method));
1761
+ }
1762
+ /**
1763
+ * Set preferred MFA method.
1764
+ *
1765
+ * @param method - Device method to set as preferred ('totp', 'sms', 'email', or 'passkey')
1766
+ * @returns Observable with success message
1767
+ */
1768
+ setPreferredMfaMethod(method) {
1769
+ return (0, import_rxjs2.from)(this.client.setPreferredMfaMethod(method));
1770
+ }
1771
+ /**
1772
+ * Generate backup codes.
1773
+ *
1774
+ * @returns Observable of backup codes array
1775
+ */
1776
+ generateBackupCodes() {
1777
+ return (0, import_rxjs2.from)(this.client.generateBackupCodes());
1778
+ }
1779
+ /**
1780
+ * Set MFA exemption (admin/test scenarios).
1781
+ *
1782
+ * @param exempt - Whether to exempt user from MFA
1783
+ * @param reason - Optional reason for exemption
1784
+ * @returns Observable that completes when exemption is set
1785
+ */
1786
+ setMfaExemption(exempt, reason) {
1787
+ return (0, import_rxjs2.from)(this.client.setMfaExemption(exempt, reason));
1788
+ }
1789
+ // ============================================================================
1790
+ // Device Trust
1791
+ // ============================================================================
1792
+ /**
1793
+ * Trust current device.
1794
+ *
1795
+ * @returns Observable with device token
1796
+ */
1797
+ trustDevice() {
1798
+ return (0, import_rxjs2.from)(this.client.trustDevice());
1799
+ }
1800
+ /**
1801
+ * Check if the current device is trusted.
1802
+ *
1803
+ * @returns Observable with trusted status
1804
+ */
1805
+ isTrustedDevice() {
1806
+ return (0, import_rxjs2.from)(this.client.isTrustedDevice());
1807
+ }
1808
+ // ============================================================================
1809
+ // Audit History
1810
+ // ============================================================================
1811
+ /**
1812
+ * Get paginated audit history for the current user.
1813
+ *
1814
+ * @param params - Query parameters for filtering and pagination
1815
+ * @returns Observable of audit history response
1816
+ *
1817
+ * @example
1818
+ * ```typescript
1819
+ * this.auth.getAuditHistory({ page: 1, limit: 20, eventType: 'LOGIN_SUCCESS' }).subscribe(history => {
1820
+ * console.log('Audit history:', history);
1821
+ * });
1822
+ * ```
1823
+ */
1824
+ getAuditHistory(params) {
1825
+ return (0, import_rxjs2.from)(this.client.getAuditHistory(params));
1671
1826
  }
1672
1827
  // ============================================================================
1673
1828
  // Escape Hatch
@@ -1675,20 +1830,19 @@ var AuthService = class {
1675
1830
  /**
1676
1831
  * Expose underlying NAuthClient for advanced scenarios.
1677
1832
  *
1678
- * Use this for operations not directly exposed by this service:
1679
- * - Profile management (getProfile, updateProfile)
1680
- * - MFA management (getMfaStatus, setupMfaDevice, etc.)
1681
- * - Social account linking (linkSocialAccount, unlinkSocialAccount)
1682
- * - Audit history (getAuditHistory)
1683
- * - Device trust (trustDevice)
1833
+ * @deprecated All core functionality is now exposed directly on AuthService as Observables.
1834
+ * Use the direct methods on AuthService instead (e.g., `auth.changePassword()` instead of `auth.getClient().changePassword()`).
1835
+ * This method is kept for backward compatibility only and may be removed in a future version.
1836
+ *
1837
+ * @returns The underlying NAuthClient instance
1684
1838
  *
1685
1839
  * @example
1686
1840
  * ```typescript
1687
- * // Get MFA status
1841
+ * // Deprecated - use direct methods instead
1688
1842
  * const status = await this.auth.getClient().getMfaStatus();
1689
1843
  *
1690
- * // Update profile
1691
- * const user = await this.auth.getClient().updateProfile({ firstName: 'John' });
1844
+ * // Preferred - use Observable-based methods
1845
+ * this.auth.getMfaStatus().subscribe(status => ...);
1692
1846
  * ```
1693
1847
  */
1694
1848
  getClient() {
@@ -1767,12 +1921,11 @@ var authInterceptor = /* @__PURE__ */ __name((req, next) => {
1767
1921
  const refreshPath = endpoints.refresh ?? "/refresh";
1768
1922
  const loginPath = endpoints.login ?? "/login";
1769
1923
  const signupPath = endpoints.signup ?? "/signup";
1770
- const socialAuthUrlPath = endpoints.socialAuthUrl ?? "/social/auth-url";
1771
- const socialCallbackPath = endpoints.socialCallback ?? "/social/callback";
1924
+ const socialExchangePath = endpoints.socialExchange ?? "/social/exchange";
1772
1925
  const refreshUrl = `${baseUrl}${refreshPath}`;
1773
1926
  const isAuthApiRequest = req.url.includes(baseUrl);
1774
1927
  const isRefreshEndpoint = req.url.includes(refreshPath);
1775
- const isPublicEndpoint = req.url.includes(loginPath) || req.url.includes(signupPath) || req.url.includes(socialAuthUrlPath) || req.url.includes(socialCallbackPath);
1928
+ const isPublicEndpoint = req.url.includes(loginPath) || req.url.includes(signupPath) || req.url.includes(socialExchangePath);
1776
1929
  let authReq = req;
1777
1930
  if (tokenDelivery === "cookies") {
1778
1931
  authReq = authReq.clone({ withCredentials: true });
@@ -1907,10 +2060,10 @@ var _AuthGuard = class _AuthGuard {
1907
2060
  __name(_AuthGuard, "AuthGuard");
1908
2061
  var AuthGuard = _AuthGuard;
1909
2062
 
1910
- // src/angular/oauth-callback.guard.ts
2063
+ // src/angular/social-redirect-callback.guard.ts
1911
2064
  var import_core6 = require("@angular/core");
1912
2065
  var import_common2 = require("@angular/common");
1913
- var oauthCallbackGuard = /* @__PURE__ */ __name(async () => {
2066
+ var socialRedirectCallbackGuard = /* @__PURE__ */ __name(async () => {
1914
2067
  const auth = (0, import_core6.inject)(AuthService);
1915
2068
  const config = (0, import_core6.inject)(NAUTH_CLIENT_CONFIG);
1916
2069
  const platformId = (0, import_core6.inject)(import_core6.PLATFORM_ID);
@@ -1918,38 +2071,28 @@ var oauthCallbackGuard = /* @__PURE__ */ __name(async () => {
1918
2071
  if (!isBrowser) {
1919
2072
  return false;
1920
2073
  }
1921
- try {
1922
- const response = await auth.getClient().handleOAuthCallback();
1923
- if (!response) {
1924
- const homeUrl = config.redirects?.success || "/";
1925
- window.location.replace(homeUrl);
1926
- return false;
1927
- }
1928
- if (response.challengeName) {
1929
- const challengeBase = config.redirects?.challengeBase || "/auth/challenge";
1930
- const challengeRoute = response.challengeName.toLowerCase().replace(/_/g, "-");
1931
- const challengePath = `${challengeBase}/${challengeRoute}`;
1932
- if (config.debug) {
1933
- console.warn("[oauth-callback-guard] Redirecting to challenge:", challengePath);
1934
- }
1935
- window.location.replace(challengePath);
1936
- } else {
1937
- const successUrl = config.redirects?.success || "/";
1938
- if (config.debug) {
1939
- console.warn("[oauth-callback-guard] Redirecting to success URL:", successUrl);
1940
- }
1941
- window.location.replace(successUrl);
1942
- }
1943
- } catch (error) {
1944
- console.error("[oauth-callback-guard] OAuth callback failed:", error);
2074
+ const params = new URLSearchParams(window.location.search);
2075
+ const error = params.get("error");
2076
+ const exchangeToken = params.get("exchangeToken");
2077
+ if (error) {
1945
2078
  const errorUrl = config.redirects?.oauthError || "/login";
1946
- if (config.debug) {
1947
- console.warn("[oauth-callback-guard] Redirecting to error URL:", errorUrl);
1948
- }
1949
2079
  window.location.replace(errorUrl);
2080
+ return false;
2081
+ }
2082
+ if (!exchangeToken) {
2083
+ return true;
2084
+ }
2085
+ const response = await auth.getClient().exchangeSocialRedirect(exchangeToken);
2086
+ if (response.challengeName) {
2087
+ const challengeBase = config.redirects?.challengeBase || "/auth/challenge";
2088
+ const challengeRoute = response.challengeName.toLowerCase().replace(/_/g, "-");
2089
+ window.location.replace(`${challengeBase}/${challengeRoute}`);
2090
+ return false;
1950
2091
  }
2092
+ const successUrl = config.redirects?.success || "/";
2093
+ window.location.replace(successUrl);
1951
2094
  return false;
1952
- }, "oauthCallbackGuard");
2095
+ }, "socialRedirectCallbackGuard");
1953
2096
 
1954
2097
  // src/angular/auth.module.ts
1955
2098
  var import_core7 = require("@angular/core");
@@ -1984,6 +2127,6 @@ NAuthModule = __decorateClass([
1984
2127
  NAuthModule,
1985
2128
  authGuard,
1986
2129
  authInterceptor,
1987
- oauthCallbackGuard
2130
+ socialRedirectCallbackGuard
1988
2131
  });
1989
2132
  //# sourceMappingURL=index.cjs.map