@proveanything/smartlinks-auth-ui 0.1.14 → 0.1.16

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
@@ -11267,18 +11267,18 @@ const AuthProvider = ({ children, proxyMode = false, accountCacheTTL = 5 * 60 *
11267
11267
  const initializeAuth = async () => {
11268
11268
  try {
11269
11269
  if (proxyMode) {
11270
- // PROXY MODE: Initialize from URL params and parent via SDK
11271
- const params = new URLSearchParams(window.location.search);
11272
- const userId = params.get('userId');
11273
- if (userId) {
11274
- console.log('[AuthContext] Proxy mode: userId detected, fetching account from parent');
11275
- try {
11276
- // Fetch account details from parent via proxied API call
11277
- const accountResponse = await smartlinks__namespace.auth.getAccount();
11278
- // Build user object from account response
11279
- const accountAny = accountResponse;
11270
+ // PROXY MODE: Check for existing session via parent's auth.getAccount()
11271
+ console.log('[AuthContext] Proxy mode: checking for existing session via auth.getAccount()');
11272
+ try {
11273
+ const accountResponse = await smartlinks__namespace.auth.getAccount();
11274
+ // auth.getAccount() always returns a response object, but uid will be
11275
+ // empty/undefined if no user is logged in
11276
+ const accountAny = accountResponse;
11277
+ const hasValidSession = accountAny?.uid && accountAny.uid.length > 0;
11278
+ if (hasValidSession) {
11279
+ // User is logged in with valid account
11280
11280
  const userFromAccount = {
11281
- uid: userId,
11281
+ uid: accountAny.uid,
11282
11282
  email: accountAny?.email,
11283
11283
  displayName: accountAny?.displayName || accountAny?.name,
11284
11284
  phoneNumber: accountAny?.phoneNumber,
@@ -11286,16 +11286,15 @@ const AuthProvider = ({ children, proxyMode = false, accountCacheTTL = 5 * 60 *
11286
11286
  setUser(userFromAccount);
11287
11287
  setAccountData(accountResponse);
11288
11288
  setAccountInfo(accountResponse);
11289
- console.log('[AuthContext] Proxy mode: initialized from parent account');
11289
+ console.log('[AuthContext] Proxy mode: initialized from parent account, uid:', accountAny.uid);
11290
11290
  notifyAuthStateChange('LOGIN', userFromAccount, null, accountResponse, accountResponse);
11291
11291
  }
11292
- catch (error) {
11293
- console.warn('[AuthContext] Proxy mode: failed to fetch account from parent:', error);
11294
- // No session - that's ok, user may need to login
11292
+ else {
11293
+ console.log('[AuthContext] Proxy mode: no valid session (no uid), awaiting login');
11295
11294
  }
11296
11295
  }
11297
- else {
11298
- console.log('[AuthContext] Proxy mode: no userId in URL, awaiting login');
11296
+ catch (error) {
11297
+ console.log('[AuthContext] Proxy mode: auth.getAccount() failed, awaiting login:', error);
11299
11298
  }
11300
11299
  setIsLoading(false);
11301
11300
  return;