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