@pooflabs/web 0.0.31 → 0.0.33

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.
@@ -24,9 +24,14 @@ export declare class PhantomWalletProvider implements AuthProvider {
24
24
  private resolvedProviders;
25
25
  private pendingLogin;
26
26
  private loginInProgress;
27
+ private autoLoginInProgress;
27
28
  private initPromise;
28
29
  constructor(networkUrl?: string | null, config?: PhantomWalletConfig);
29
30
  private initializeAsync;
31
+ /**
32
+ * Check if social login providers are configured (non-injected providers).
33
+ */
34
+ private hasSocialProviders;
30
35
  static getInstance(networkUrl: string | null, config: PhantomWalletConfig): PhantomWalletProvider;
31
36
  private resolveProviders;
32
37
  private initialize;
package/dist/global.d.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  import { User, ClientConfig } from '@pooflabs/core';
2
2
  export declare function init(newConfig: Partial<ClientConfig>): Promise<void>;
3
3
  export declare function onAuthStateChanged(callback: (user: User | null) => void): void;
4
+ export declare function onAuthLoadingChanged(callback: (loading: boolean) => void): void;
5
+ export declare function setAuthLoading(loading: boolean): void;
6
+ export declare function getAuthLoading(): boolean;
4
7
  export declare function login(): Promise<User | null>;
5
8
  export declare function logout(): Promise<void>;
6
9
  export declare function setCurrentUser(user: User | null): void;
@@ -12652,7 +12652,7 @@ async function loadDependencies() {
12652
12652
  const [reactModule, reactDomModule, phantomModule] = await Promise.all([
12653
12653
  import('react'),
12654
12654
  import('react-dom/client'),
12655
- Promise.resolve().then(function () { return require('./index-DXYtcpKo.js'); })
12655
+ Promise.resolve().then(function () { return require('./index-DVFbwTxe.js'); })
12656
12656
  ]);
12657
12657
  React$1 = reactModule;
12658
12658
  ReactDOM$1 = reactDomModule;
@@ -12669,6 +12669,7 @@ class PhantomWalletProvider {
12669
12669
  this.resolvedProviders = ['injected'];
12670
12670
  this.pendingLogin = null;
12671
12671
  this.loginInProgress = false;
12672
+ this.autoLoginInProgress = false;
12672
12673
  this.initPromise = null;
12673
12674
  this.networkUrl = networkUrl;
12674
12675
  this.config = config;
@@ -12691,6 +12692,12 @@ class PhantomWalletProvider {
12691
12692
  // Initialize React component
12692
12693
  this.initialize();
12693
12694
  }
12695
+ /**
12696
+ * Check if social login providers are configured (non-injected providers).
12697
+ */
12698
+ hasSocialProviders() {
12699
+ return this.resolvedProviders.some(p => p !== 'injected');
12700
+ }
12694
12701
  static getInstance(networkUrl, config) {
12695
12702
  if (!PhantomWalletProvider.instance) {
12696
12703
  new PhantomWalletProvider(networkUrl, config);
@@ -12766,16 +12773,49 @@ class PhantomWalletProvider {
12766
12773
  };
12767
12774
  }
12768
12775
  }, [phantom, phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, connect, disconnect, isDisconnecting, modal, modal.isOpened, solana, solanaHook.isAvailable, connectError]);
12769
- // Auto-disconnect Phantom if connected but no valid Tarobase session exists
12770
- // This handles the case where user connected to Phantom but didn't complete login
12776
+ // Auto-login: If connected but no Tarobase session, try to create one.
12777
+ // This handles social login callbacks where user returns from OAuth already connected.
12771
12778
  React$1.useEffect(() => {
12772
- const checkSessionAndDisconnect = async () => {
12773
- // Only check when SDK is ready, connected, and not in the middle of a login
12774
- if (!(phantom === null || phantom === void 0 ? void 0 : phantom.isConnected) || (phantom === null || phantom === void 0 ? void 0 : phantom.isLoading) || that.loginInProgress) {
12779
+ const autoCreateSession = async () => {
12780
+ var _a;
12781
+ // Only proceed when SDK is ready, connected, has addresses, and not already in a login flow
12782
+ if (!(phantom === null || phantom === void 0 ? void 0 : phantom.isConnected) || (phantom === null || phantom === void 0 ? void 0 : phantom.isLoading) || that.loginInProgress || that.autoLoginInProgress || that.pendingLogin) {
12775
12783
  return;
12776
12784
  }
12777
- const session = await WebSessionManager.getSession();
12778
- if (!session) {
12785
+ // Need solana to be available for signing
12786
+ if (!solana || !solanaHook.isAvailable) {
12787
+ return;
12788
+ }
12789
+ // Find Solana address
12790
+ const solAddress = (_a = phantom.addresses) === null || _a === void 0 ? void 0 : _a.find((addr) => addr.addressType === AddressType.solana);
12791
+ if (!solAddress) {
12792
+ return;
12793
+ }
12794
+ const publicKey = solAddress.address;
12795
+ // Check if we already have a valid session for this address
12796
+ const existingSession = await WebSessionManager.getSession();
12797
+ if (existingSession && existingSession.address === publicKey) {
12798
+ // Already have a valid session, nothing to do
12799
+ setCurrentUser({ provider: that, address: publicKey });
12800
+ return;
12801
+ }
12802
+ // No valid session - try to create one automatically
12803
+ that.autoLoginInProgress = true;
12804
+ setAuthLoading(true);
12805
+ try {
12806
+ const nonce = await genAuthNonce();
12807
+ const messageText = await genSolanaMessage(publicKey, nonce);
12808
+ // signMessage returns { signature: Uint8Array, publicKey: string }
12809
+ const signResult = await solana.signMessage(messageText);
12810
+ // Convert Uint8Array signature to base64 string
12811
+ const signatureBytes = signResult.signature;
12812
+ const signature = bufferExports$1.Buffer.from(signatureBytes).toString('base64');
12813
+ const createSessionResult = await createSessionWithSignature(publicKey, messageText, signature);
12814
+ await WebSessionManager.storeSession(publicKey, createSessionResult.accessToken, createSessionResult.idToken, createSessionResult.refreshToken);
12815
+ setCurrentUser({ provider: that, address: publicKey });
12816
+ }
12817
+ catch (error) {
12818
+ // User rejected signing or other error - disconnect fully
12779
12819
  try {
12780
12820
  await disconnect();
12781
12821
  }
@@ -12783,9 +12823,13 @@ class PhantomWalletProvider {
12783
12823
  // Ignore disconnect errors
12784
12824
  }
12785
12825
  }
12826
+ finally {
12827
+ that.autoLoginInProgress = false;
12828
+ setAuthLoading(false);
12829
+ }
12786
12830
  };
12787
- checkSessionAndDisconnect();
12788
- }, [phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, disconnect]);
12831
+ autoCreateSession();
12832
+ }, [phantom === null || phantom === void 0 ? void 0 : phantom.isConnected, phantom === null || phantom === void 0 ? void 0 : phantom.isLoading, phantom === null || phantom === void 0 ? void 0 : phantom.addresses, solana, solanaHook.isAvailable, disconnect]);
12789
12833
  // Handle modal close without connection
12790
12834
  React$1.useEffect(() => {
12791
12835
  // Detect when modal was open and is now closed
@@ -12889,9 +12933,11 @@ class PhantomWalletProvider {
12889
12933
  if (that.config.appId) {
12890
12934
  config.appId = that.config.appId;
12891
12935
  }
12892
- if (that.config.redirectUrl) {
12936
+ // Set authOptions with redirectUrl for social login callback handling
12937
+ // Default to current page URL if not explicitly configured
12938
+ if (that.hasSocialProviders()) {
12893
12939
  config.authOptions = {
12894
- redirectUrl: that.config.redirectUrl,
12940
+ redirectUrl: that.config.redirectUrl || window.location.href,
12895
12941
  };
12896
12942
  }
12897
12943
  return config;
@@ -31326,7 +31372,9 @@ async function logout$1() {
31326
31372
  let authProviderInstance = null;
31327
31373
  let currentUser = null;
31328
31374
  let authStateListeners = [];
31375
+ let authLoadingListeners = [];
31329
31376
  let initCompleted = false;
31377
+ let isAuthLoading = false;
31330
31378
  // This file acts as a middleware for the global state of the SDK
31331
31379
  // This mostly involves setting up the AuthProvider and managing the current user
31332
31380
  async function init(newConfig) {
@@ -31350,6 +31398,20 @@ function onAuthStateChanged(callback) {
31350
31398
  callback(currentUser);
31351
31399
  }
31352
31400
  }
31401
+ function onAuthLoadingChanged(callback) {
31402
+ authLoadingListeners.push(callback);
31403
+ // Call immediately with current loading state
31404
+ callback(isAuthLoading);
31405
+ }
31406
+ function setAuthLoading(loading) {
31407
+ if (isAuthLoading !== loading) {
31408
+ isAuthLoading = loading;
31409
+ authLoadingListeners.forEach((callback) => callback(loading));
31410
+ }
31411
+ }
31412
+ function getAuthLoading() {
31413
+ return isAuthLoading;
31414
+ }
31353
31415
  async function login() {
31354
31416
  if (!authProviderInstance) {
31355
31417
  throw new Error('SDK not initialized. Please call init() first.');
@@ -31392,11 +31454,15 @@ function useAuth() {
31392
31454
  }
31393
31455
  const [user, setUser] = React__namespace.useState(null);
31394
31456
  const [loading, setLoading] = React__namespace.useState(true);
31457
+ const [sdkLoading, setSdkLoading] = React__namespace.useState(false);
31395
31458
  React__namespace.useEffect(() => {
31396
31459
  onAuthStateChanged((user) => {
31397
31460
  setUser(user);
31398
31461
  setLoading(false);
31399
31462
  });
31463
+ onAuthLoadingChanged((loading) => {
31464
+ setSdkLoading(loading);
31465
+ });
31400
31466
  return () => {
31401
31467
  };
31402
31468
  }, []);
@@ -31433,7 +31499,7 @@ function useAuth() {
31433
31499
  return {
31434
31500
  login: login$1,
31435
31501
  logout: logout$1,
31436
- loading,
31502
+ loading: loading || sdkLoading,
31437
31503
  user,
31438
31504
  };
31439
31505
  }
@@ -31458,6 +31524,7 @@ exports.createSessionWithSignature = createSessionWithSignature;
31458
31524
  exports.genAuthNonce = genAuthNonce;
31459
31525
  exports.genSolanaMessage = genSolanaMessage;
31460
31526
  exports.get = get$2;
31527
+ exports.getAuthLoading = getAuthLoading;
31461
31528
  exports.getAuthProvider = getAuthProvider;
31462
31529
  exports.getConfig = getConfig;
31463
31530
  exports.getCurrentUser = getCurrentUser;
@@ -31467,6 +31534,7 @@ exports.getIdToken = getIdToken;
31467
31534
  exports.init = init;
31468
31535
  exports.login = login;
31469
31536
  exports.logout = logout;
31537
+ exports.onAuthLoadingChanged = onAuthLoadingChanged;
31470
31538
  exports.onAuthStateChanged = onAuthStateChanged;
31471
31539
  exports.refreshSession = refreshSession;
31472
31540
  exports.runExpression = runExpression;
@@ -31479,4 +31547,4 @@ exports.setMany = setMany;
31479
31547
  exports.signSessionCreateMessage = signSessionCreateMessage;
31480
31548
  exports.subscribe = subscribe;
31481
31549
  exports.useAuth = useAuth;
31482
- //# sourceMappingURL=index-BzYf0Bnq.js.map
31550
+ //# sourceMappingURL=index-CyYOGixN.js.map