@passkeyme/auth 2.1.0 → 2.2.1

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 CHANGED
@@ -419,6 +419,29 @@ class PasskeymeApiClient {
419
419
  lastLoginAt: new Date().toISOString(),
420
420
  };
421
421
  }
422
+ /**
423
+ * Get detailed user information from /userinfo endpoint
424
+ * Returns rich user data including name, picture, etc.
425
+ * Requires a valid access token.
426
+ */
427
+ async getUserInfo(accessToken) {
428
+ const response = (await this.request("/api/userinfo", {
429
+ method: "GET",
430
+ headers: {
431
+ Authorization: `Bearer ${accessToken}`,
432
+ },
433
+ }));
434
+ // Convert userinfo response to User object
435
+ return {
436
+ id: response.sub,
437
+ email: response.email,
438
+ name: response.name || response.email,
439
+ givenName: response.given_name,
440
+ familyName: response.family_name,
441
+ picture: response.picture,
442
+ emailVerified: response.email_verified,
443
+ };
444
+ }
422
445
  /**
423
446
  * Refresh access token
424
447
  */
@@ -1685,6 +1708,32 @@ class PasskeymeAuth {
1685
1708
  });
1686
1709
  return this._appConfigPromise;
1687
1710
  }
1711
+ /**
1712
+ * Get detailed user information including name, picture, etc.
1713
+ * Requires the user to be authenticated.
1714
+ * This calls the /userinfo endpoint which returns richer user data
1715
+ * than what's available from the JWT token alone.
1716
+ */
1717
+ async getUserInfo() {
1718
+ const accessToken = await this.getAccessToken();
1719
+ if (!accessToken) {
1720
+ throw new PasskeymeError({
1721
+ code: PasskeymeErrorCode.SESSION_EXPIRED,
1722
+ message: "No access token available",
1723
+ userMessage: "Please sign in to view user information.",
1724
+ recoverable: true,
1725
+ retryable: false,
1726
+ suggestedAction: "Sign in again",
1727
+ });
1728
+ }
1729
+ const userInfo = await this.apiClient.getUserInfo(accessToken);
1730
+ // Update state with enriched user data
1731
+ this.setState({
1732
+ user: { ...this._state.user, ...userInfo },
1733
+ });
1734
+ logger.debug("User info retrieved:", userInfo);
1735
+ return userInfo;
1736
+ }
1688
1737
  }
1689
1738
  // Test comment
1690
1739