@passkeyme/auth 2.0.13 → 2.2.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
@@ -425,6 +425,29 @@
425
425
  lastLoginAt: new Date().toISOString(),
426
426
  };
427
427
  }
428
+ /**
429
+ * Get detailed user information from /userinfo endpoint
430
+ * Returns rich user data including name, picture, etc.
431
+ * Requires a valid access token.
432
+ */
433
+ async getUserInfo(accessToken) {
434
+ const response = (await this.request("/userinfo", {
435
+ method: "GET",
436
+ headers: {
437
+ Authorization: `Bearer ${accessToken}`,
438
+ },
439
+ }));
440
+ // Convert userinfo response to User object
441
+ return {
442
+ id: response.sub,
443
+ email: response.email,
444
+ name: response.name || response.email,
445
+ givenName: response.given_name,
446
+ familyName: response.family_name,
447
+ picture: response.picture,
448
+ emailVerified: response.email_verified,
449
+ };
450
+ }
428
451
  /**
429
452
  * Refresh access token
430
453
  */
@@ -1020,10 +1043,7 @@
1020
1043
  redirectToOAuth(provider, redirectUri) {
1021
1044
  const finalRedirectUri = redirectUri || this.config.redirectUri;
1022
1045
  // 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");
1046
+ const apiBaseUrl = this.config.apiUrl || "https://api.passkeyme.com";
1027
1047
  const params = new URLSearchParams({
1028
1048
  redirect_uri: finalRedirectUri,
1029
1049
  });
@@ -1694,6 +1714,32 @@
1694
1714
  });
1695
1715
  return this._appConfigPromise;
1696
1716
  }
1717
+ /**
1718
+ * Get detailed user information including name, picture, etc.
1719
+ * Requires the user to be authenticated.
1720
+ * This calls the /userinfo endpoint which returns richer user data
1721
+ * than what's available from the JWT token alone.
1722
+ */
1723
+ async getUserInfo() {
1724
+ const accessToken = await this.getAccessToken();
1725
+ if (!accessToken) {
1726
+ throw new PasskeymeError({
1727
+ code: exports.PasskeymeErrorCode.SESSION_EXPIRED,
1728
+ message: "No access token available",
1729
+ userMessage: "Please sign in to view user information.",
1730
+ recoverable: true,
1731
+ retryable: false,
1732
+ suggestedAction: "Sign in again",
1733
+ });
1734
+ }
1735
+ const userInfo = await this.apiClient.getUserInfo(accessToken);
1736
+ // Update state with enriched user data
1737
+ this.setState({
1738
+ user: { ...this._state.user, ...userInfo },
1739
+ });
1740
+ logger.debug("User info retrieved:", userInfo);
1741
+ return userInfo;
1742
+ }
1697
1743
  }
1698
1744
  // Test comment
1699
1745