@passkeyme/auth 2.0.12 → 2.1.0

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.umd.js CHANGED
@@ -1020,10 +1020,7 @@
1020
1020
  redirectToOAuth(provider, redirectUri) {
1021
1021
  const finalRedirectUri = redirectUri || this.config.redirectUri;
1022
1022
  // Build direct OAuth initiation URL - use apiUrl for backend API endpoints
1023
- const apiBaseUrl = this.config.apiUrl ||
1024
- (typeof window !== "undefined" && window.location.hostname !== "localhost"
1025
- ? "https://api.passkeyme.com"
1026
- : "http://localhost:8000");
1023
+ const apiBaseUrl = this.config.apiUrl || "https://api.passkeyme.com";
1027
1024
  const params = new URLSearchParams({
1028
1025
  redirect_uri: finalRedirectUri,
1029
1026
  });
@@ -1054,6 +1051,25 @@
1054
1051
  });
1055
1052
  }
1056
1053
  }
1054
+ /**
1055
+ * Internal helper: Redirect to login in hosted mode, or throw error in direct mode
1056
+ */
1057
+ redirectOrThrow(userMessage, technicalMessage) {
1058
+ if (this.config.mode === "hosted") {
1059
+ this.redirectToLogin();
1060
+ return { method: "redirect" };
1061
+ }
1062
+ else {
1063
+ throw new PasskeymeError({
1064
+ code: exports.PasskeymeErrorCode.PASSKEY_NOT_SUPPORTED,
1065
+ message: technicalMessage,
1066
+ userMessage: userMessage,
1067
+ recoverable: true,
1068
+ retryable: false,
1069
+ suggestedAction: "Use OAuth sign-in instead",
1070
+ });
1071
+ }
1072
+ }
1057
1073
  /**
1058
1074
  * Handle authentication callback from hosted auth page
1059
1075
  */
@@ -1520,7 +1536,7 @@
1520
1536
  * 1. Check app config for discoverable credentials support
1521
1537
  * 2. If supported: attempt discoverable credentials first (no username)
1522
1538
  * 3. If not supported or fails: use stored username or prompt for username
1523
- * 4. Fallback to hosted auth if all passkey attempts fail
1539
+ * 4. Fallback to hosted auth if all passkey attempts fail (unless mode is 'direct')
1524
1540
  */
1525
1541
  async smartLogin(username, apiKey) {
1526
1542
  logger.debug("[DEBUG] smartLogin called with:", {
@@ -1535,8 +1551,9 @@
1535
1551
  logger.debug("[DEBUG] Passkey support check:", isSupported);
1536
1552
  if (!isSupported || !effectiveApiKey) {
1537
1553
  logger.debug("Conditions not met, redirecting to hosted auth. isSupported:", isSupported, "hasApiKey:", !!effectiveApiKey);
1538
- this.redirectToLogin();
1539
- return { method: "redirect" };
1554
+ return this.redirectOrThrow(isSupported
1555
+ ? "API key is required for passkey authentication."
1556
+ : "Your device doesn't support passkeys.", "Passkey authentication not available");
1540
1557
  }
1541
1558
  try {
1542
1559
  // Get app configuration to check discoverable credentials support
@@ -1559,8 +1576,7 @@
1559
1576
  // If passkeys are disabled at the app level, fallback to hosted auth
1560
1577
  if (!appConfig.passkeyEnabled) {
1561
1578
  logger.debug("Passkeys disabled for this app, falling back to hosted auth");
1562
- this.redirectToLogin();
1563
- return { method: "redirect" };
1579
+ return this.redirectOrThrow("Passkey authentication is not available for this app.", "Passkeys are disabled for this application");
1564
1580
  }
1565
1581
  let authUsername = username;
1566
1582
  // Smart username resolution following industry best practices
@@ -1582,15 +1598,13 @@
1582
1598
  const storageKey = `last_username_${this.config.appId}`;
1583
1599
  logger.debug("Looking for stored username with key:", storageKey);
1584
1600
  const storedUsername = await this.storage.getItem(storageKey);
1585
- logger.debug("Found stored username:", storedUsername);
1586
1601
  if (storedUsername) {
1587
1602
  logger.debug("Using stored username for targeted authentication:", storedUsername);
1588
1603
  authUsername = storedUsername;
1589
1604
  }
1590
1605
  else {
1591
1606
  logger.debug("No username available and discoverable auth failed/unsupported, falling back to hosted auth");
1592
- this.redirectToLogin();
1593
- return { method: "redirect" };
1607
+ return this.redirectOrThrow("Unable to authenticate with passkey. Please sign in with another method.", "No username available for passkey authentication");
1594
1608
  }
1595
1609
  }
1596
1610
  // Attempt passkey authentication with username
@@ -1609,9 +1623,15 @@
1609
1623
  if (this.config.debug) {
1610
1624
  logger.error("[PasskeymeAuth] Passkey authentication error details:", error);
1611
1625
  }
1612
- // Fallback to hosted auth for any passkey failures
1613
- this.redirectToLogin();
1614
- return { method: "redirect" };
1626
+ // Fallback to hosted auth for any passkey failures (unless mode is 'direct')
1627
+ // In direct mode, re-throw the original error for the caller to handle
1628
+ if (this.config.mode === "hosted") {
1629
+ this.redirectToLogin();
1630
+ return { method: "redirect" };
1631
+ }
1632
+ else {
1633
+ throw error;
1634
+ }
1615
1635
  }
1616
1636
  }
1617
1637
  /**