@passkeyme/auth 2.0.12 → 2.0.13
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.esm.js +34 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +34 -11
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +34 -11
- package/dist/index.umd.js.map +1 -1
- package/dist/src/passkeyme-auth.d.ts +5 -1
- package/dist/src/passkeyme-auth.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1052,6 +1052,25 @@ class PasskeymeAuth {
|
|
|
1052
1052
|
});
|
|
1053
1053
|
}
|
|
1054
1054
|
}
|
|
1055
|
+
/**
|
|
1056
|
+
* Internal helper: Redirect to login in hosted mode, or throw error in direct mode
|
|
1057
|
+
*/
|
|
1058
|
+
redirectOrThrow(userMessage, technicalMessage) {
|
|
1059
|
+
if (this.config.mode === "hosted") {
|
|
1060
|
+
this.redirectToLogin();
|
|
1061
|
+
return { method: "redirect" };
|
|
1062
|
+
}
|
|
1063
|
+
else {
|
|
1064
|
+
throw new PasskeymeError({
|
|
1065
|
+
code: exports.PasskeymeErrorCode.PASSKEY_NOT_SUPPORTED,
|
|
1066
|
+
message: technicalMessage,
|
|
1067
|
+
userMessage: userMessage,
|
|
1068
|
+
recoverable: true,
|
|
1069
|
+
retryable: false,
|
|
1070
|
+
suggestedAction: "Use OAuth sign-in instead",
|
|
1071
|
+
});
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1055
1074
|
/**
|
|
1056
1075
|
* Handle authentication callback from hosted auth page
|
|
1057
1076
|
*/
|
|
@@ -1518,7 +1537,7 @@ class PasskeymeAuth {
|
|
|
1518
1537
|
* 1. Check app config for discoverable credentials support
|
|
1519
1538
|
* 2. If supported: attempt discoverable credentials first (no username)
|
|
1520
1539
|
* 3. If not supported or fails: use stored username or prompt for username
|
|
1521
|
-
* 4. Fallback to hosted auth if all passkey attempts fail
|
|
1540
|
+
* 4. Fallback to hosted auth if all passkey attempts fail (unless mode is 'direct')
|
|
1522
1541
|
*/
|
|
1523
1542
|
async smartLogin(username, apiKey) {
|
|
1524
1543
|
logger.debug("[DEBUG] smartLogin called with:", {
|
|
@@ -1533,8 +1552,9 @@ class PasskeymeAuth {
|
|
|
1533
1552
|
logger.debug("[DEBUG] Passkey support check:", isSupported);
|
|
1534
1553
|
if (!isSupported || !effectiveApiKey) {
|
|
1535
1554
|
logger.debug("Conditions not met, redirecting to hosted auth. isSupported:", isSupported, "hasApiKey:", !!effectiveApiKey);
|
|
1536
|
-
this.
|
|
1537
|
-
|
|
1555
|
+
return this.redirectOrThrow(isSupported
|
|
1556
|
+
? "API key is required for passkey authentication."
|
|
1557
|
+
: "Your device doesn't support passkeys.", "Passkey authentication not available");
|
|
1538
1558
|
}
|
|
1539
1559
|
try {
|
|
1540
1560
|
// Get app configuration to check discoverable credentials support
|
|
@@ -1557,8 +1577,7 @@ class PasskeymeAuth {
|
|
|
1557
1577
|
// If passkeys are disabled at the app level, fallback to hosted auth
|
|
1558
1578
|
if (!appConfig.passkeyEnabled) {
|
|
1559
1579
|
logger.debug("Passkeys disabled for this app, falling back to hosted auth");
|
|
1560
|
-
this.
|
|
1561
|
-
return { method: "redirect" };
|
|
1580
|
+
return this.redirectOrThrow("Passkey authentication is not available for this app.", "Passkeys are disabled for this application");
|
|
1562
1581
|
}
|
|
1563
1582
|
let authUsername = username;
|
|
1564
1583
|
// Smart username resolution following industry best practices
|
|
@@ -1580,15 +1599,13 @@ class PasskeymeAuth {
|
|
|
1580
1599
|
const storageKey = `last_username_${this.config.appId}`;
|
|
1581
1600
|
logger.debug("Looking for stored username with key:", storageKey);
|
|
1582
1601
|
const storedUsername = await this.storage.getItem(storageKey);
|
|
1583
|
-
logger.debug("Found stored username:", storedUsername);
|
|
1584
1602
|
if (storedUsername) {
|
|
1585
1603
|
logger.debug("Using stored username for targeted authentication:", storedUsername);
|
|
1586
1604
|
authUsername = storedUsername;
|
|
1587
1605
|
}
|
|
1588
1606
|
else {
|
|
1589
1607
|
logger.debug("No username available and discoverable auth failed/unsupported, falling back to hosted auth");
|
|
1590
|
-
this.
|
|
1591
|
-
return { method: "redirect" };
|
|
1608
|
+
return this.redirectOrThrow("Unable to authenticate with passkey. Please sign in with another method.", "No username available for passkey authentication");
|
|
1592
1609
|
}
|
|
1593
1610
|
}
|
|
1594
1611
|
// Attempt passkey authentication with username
|
|
@@ -1607,9 +1624,15 @@ class PasskeymeAuth {
|
|
|
1607
1624
|
if (this.config.debug) {
|
|
1608
1625
|
logger.error("[PasskeymeAuth] Passkey authentication error details:", error);
|
|
1609
1626
|
}
|
|
1610
|
-
// Fallback to hosted auth for any passkey failures
|
|
1611
|
-
|
|
1612
|
-
|
|
1627
|
+
// Fallback to hosted auth for any passkey failures (unless mode is 'direct')
|
|
1628
|
+
// In direct mode, re-throw the original error for the caller to handle
|
|
1629
|
+
if (this.config.mode === "hosted") {
|
|
1630
|
+
this.redirectToLogin();
|
|
1631
|
+
return { method: "redirect" };
|
|
1632
|
+
}
|
|
1633
|
+
else {
|
|
1634
|
+
throw error;
|
|
1635
|
+
}
|
|
1613
1636
|
}
|
|
1614
1637
|
}
|
|
1615
1638
|
/**
|