@passkeyme/auth 2.0.11 → 2.0.12

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.js CHANGED
@@ -1433,6 +1433,19 @@ class PasskeymeAuth {
1433
1433
  }
1434
1434
  // Extract token and user info from response
1435
1435
  const { token, user_uuid, success, message } = completeResponse.data;
1436
+ // Decode JWT to extract email and other user info
1437
+ let tokenEmail;
1438
+ try {
1439
+ const tokenParts = token.split(".");
1440
+ if (tokenParts.length === 3) {
1441
+ const payload = JSON.parse(atob(tokenParts[1]));
1442
+ tokenEmail = payload.email;
1443
+ logger.debug("Extracted email from JWT:", tokenEmail);
1444
+ }
1445
+ }
1446
+ catch (decodeError) {
1447
+ logger.debug("Failed to decode JWT token:", decodeError);
1448
+ }
1436
1449
  // Store tokens - use the JWT token as access token
1437
1450
  const tokens = {
1438
1451
  accessToken: token,
@@ -1441,11 +1454,13 @@ class PasskeymeAuth {
1441
1454
  };
1442
1455
  await this.tokenStorage.setTokens(tokens);
1443
1456
  // Create user object with available information
1457
+ // Prefer email from JWT token, fallback to username
1458
+ const userEmail = tokenEmail || username;
1444
1459
  const user = {
1445
1460
  id: user_uuid,
1446
1461
  uuid: user_uuid,
1447
1462
  username: username,
1448
- email: username, // Assume username is email for now
1463
+ email: userEmail,
1449
1464
  authenticated: true,
1450
1465
  };
1451
1466
  // Update state