@finatic/client 0.0.138 → 0.0.139

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.mjs CHANGED
@@ -1670,13 +1670,17 @@ class PortalUI {
1670
1670
  console.warn('[PortalUI] Received message from unauthorized origin:', event.origin, 'Expected:', this.portalOrigin);
1671
1671
  return;
1672
1672
  }
1673
- const { type, userId, error, height, data } = event.data;
1673
+ const { type, userId, access_token, refresh_token, error, height, data } = event.data;
1674
1674
  console.log('[PortalUI] Received message:', event.data);
1675
1675
  switch (type) {
1676
1676
  case 'portal-success': {
1677
1677
  // Handle both direct userId and data.userId formats
1678
1678
  const successUserId = userId || (data && data.userId);
1679
- this.handlePortalSuccess(successUserId);
1679
+ const tokens = {
1680
+ access_token: access_token || (data && data.access_token),
1681
+ refresh_token: refresh_token || (data && data.refresh_token)
1682
+ };
1683
+ this.handlePortalSuccess(successUserId, tokens);
1680
1684
  break;
1681
1685
  }
1682
1686
  case 'portal-error': {
@@ -1708,14 +1712,17 @@ class PortalUI {
1708
1712
  console.warn('[PortalUI] Received unhandled message type:', type);
1709
1713
  }
1710
1714
  }
1711
- handlePortalSuccess(userId) {
1715
+ handlePortalSuccess(userId, tokens) {
1712
1716
  if (!userId) {
1713
1717
  console.error('[PortalUI] Missing userId in portal-success message');
1714
1718
  return;
1715
1719
  }
1716
1720
  console.log('[PortalUI] Portal success - User connected:', userId);
1721
+ if (tokens?.access_token && tokens?.refresh_token) {
1722
+ console.log('[PortalUI] Tokens received for user:', userId);
1723
+ }
1717
1724
  // Pass userId to parent (SDK will handle tokens internally)
1718
- this.options?.onSuccess?.(userId);
1725
+ this.options?.onSuccess?.(userId, tokens);
1719
1726
  }
1720
1727
  handlePortalError(error) {
1721
1728
  console.error('[PortalUI] Portal error:', error);
@@ -5171,11 +5178,15 @@ class FinaticConnect extends EventEmitter {
5171
5178
  }
5172
5179
  // Show portal
5173
5180
  this.portalUI.show(themedPortalUrl, this.sessionId || '', {
5174
- onSuccess: async (userId) => {
5181
+ onSuccess: async (userId, tokens) => {
5175
5182
  try {
5176
5183
  if (!this.sessionId) {
5177
5184
  throw new SessionError('Session not initialized');
5178
5185
  }
5186
+ // Handle tokens if provided
5187
+ if (tokens?.access_token && tokens?.refresh_token) {
5188
+ this.handleTokens(tokens);
5189
+ }
5179
5190
  // Emit portal success event
5180
5191
  this.emit('portal:success', userId);
5181
5192
  // Emit legacy success event