@proveanything/smartlinks-auth-ui 0.1.11 → 0.1.14
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/components/SmartlinksAuthUI.d.ts.map +1 -1
- package/dist/context/AuthContext.d.ts +2 -0
- package/dist/context/AuthContext.d.ts.map +1 -1
- package/dist/index.esm.js +176 -51
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +175 -51
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +10 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAW5D,OAAO,KAAK,EAAE,qBAAqB,EAAyC,MAAM,UAAU,CAAC;AA8E7F,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,
|
|
1
|
+
{"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAuC,MAAM,OAAO,CAAC;AAW5D,OAAO,KAAK,EAAE,qBAAqB,EAAyC,MAAM,UAAU,CAAC;AA8E7F,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAyhC5D,CAAC"}
|
|
@@ -7,6 +7,7 @@ interface AuthContextValue {
|
|
|
7
7
|
accountInfo: Record<string, any> | null;
|
|
8
8
|
isAuthenticated: boolean;
|
|
9
9
|
isLoading: boolean;
|
|
10
|
+
proxyMode: boolean;
|
|
10
11
|
login: (token: string, user: AuthUser, accountData?: Record<string, any>) => Promise<void>;
|
|
11
12
|
logout: () => Promise<void>;
|
|
12
13
|
getToken: () => Promise<string | null>;
|
|
@@ -18,6 +19,7 @@ interface AuthContextValue {
|
|
|
18
19
|
}
|
|
19
20
|
interface AuthProviderProps {
|
|
20
21
|
children: React.ReactNode;
|
|
22
|
+
proxyMode?: boolean;
|
|
21
23
|
accountCacheTTL?: number;
|
|
22
24
|
preloadAccountInfo?: boolean;
|
|
23
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../../src/context/AuthContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8E,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"AuthContext.d.ts","sourceRoot":"","sources":["../../src/context/AuthContext.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8E,MAAM,OAAO,CAAC;AAKnG,OAAO,KAAK,EAAE,QAAQ,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAC;AAElE,UAAU,gBAAgB;IACxB,IAAI,EAAE,QAAQ,GAAG,IAAI,CAAC;IACtB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IACxC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC;IACxC,eAAe,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,OAAO,CAAC;IACnB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3F,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACvC,YAAY,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAC;IACpC,UAAU,EAAE,CAAC,YAAY,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACrE,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IACnD,iBAAiB,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,iBAAiB,EAAE,CAAC,QAAQ,EAAE,uBAAuB,KAAK,MAAM,IAAI,CAAC;CACtE;AAID,UAAU,iBAAiB;IACzB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA+YpD,CAAC;AAEF,eAAO,MAAM,OAAO,QAAO,gBAM1B,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import React, { useEffect, useState, useRef, useCallback, useMemo, createContext, useContext } from 'react';
|
|
3
3
|
import * as smartlinks from '@proveanything/smartlinks';
|
|
4
|
+
import { iframe } from '@proveanything/smartlinks';
|
|
4
5
|
|
|
5
6
|
const AuthContainer = ({ children, theme = 'light', className = '', config, minimal = false, }) => {
|
|
6
7
|
// Apply CSS variables for customization
|
|
@@ -11217,7 +11218,7 @@ const tokenStorage = {
|
|
|
11217
11218
|
};
|
|
11218
11219
|
|
|
11219
11220
|
const AuthContext = createContext(undefined);
|
|
11220
|
-
const AuthProvider = ({ children, accountCacheTTL = 5 * 60 * 1000, preloadAccountInfo = false }) => {
|
|
11221
|
+
const AuthProvider = ({ children, proxyMode = false, accountCacheTTL = 5 * 60 * 1000, preloadAccountInfo = false }) => {
|
|
11221
11222
|
const [user, setUser] = useState(null);
|
|
11222
11223
|
const [token, setToken] = useState(null);
|
|
11223
11224
|
const [accountData, setAccountData] = useState(null);
|
|
@@ -11241,10 +11242,45 @@ const AuthProvider = ({ children, accountCacheTTL = 5 * 60 * 1000, preloadAccoun
|
|
|
11241
11242
|
}
|
|
11242
11243
|
});
|
|
11243
11244
|
}, []);
|
|
11244
|
-
// Initialize auth state
|
|
11245
|
+
// Initialize auth state - different behavior for proxy mode vs standalone mode
|
|
11245
11246
|
useEffect(() => {
|
|
11246
11247
|
const initializeAuth = async () => {
|
|
11247
11248
|
try {
|
|
11249
|
+
if (proxyMode) {
|
|
11250
|
+
// PROXY MODE: Initialize from URL params and parent via SDK
|
|
11251
|
+
const params = new URLSearchParams(window.location.search);
|
|
11252
|
+
const userId = params.get('userId');
|
|
11253
|
+
if (userId) {
|
|
11254
|
+
console.log('[AuthContext] Proxy mode: userId detected, fetching account from parent');
|
|
11255
|
+
try {
|
|
11256
|
+
// Fetch account details from parent via proxied API call
|
|
11257
|
+
const accountResponse = await smartlinks.auth.getAccount();
|
|
11258
|
+
// Build user object from account response
|
|
11259
|
+
const accountAny = accountResponse;
|
|
11260
|
+
const userFromAccount = {
|
|
11261
|
+
uid: userId,
|
|
11262
|
+
email: accountAny?.email,
|
|
11263
|
+
displayName: accountAny?.displayName || accountAny?.name,
|
|
11264
|
+
phoneNumber: accountAny?.phoneNumber,
|
|
11265
|
+
};
|
|
11266
|
+
setUser(userFromAccount);
|
|
11267
|
+
setAccountData(accountResponse);
|
|
11268
|
+
setAccountInfo(accountResponse);
|
|
11269
|
+
console.log('[AuthContext] Proxy mode: initialized from parent account');
|
|
11270
|
+
notifyAuthStateChange('LOGIN', userFromAccount, null, accountResponse, accountResponse);
|
|
11271
|
+
}
|
|
11272
|
+
catch (error) {
|
|
11273
|
+
console.warn('[AuthContext] Proxy mode: failed to fetch account from parent:', error);
|
|
11274
|
+
// No session - that's ok, user may need to login
|
|
11275
|
+
}
|
|
11276
|
+
}
|
|
11277
|
+
else {
|
|
11278
|
+
console.log('[AuthContext] Proxy mode: no userId in URL, awaiting login');
|
|
11279
|
+
}
|
|
11280
|
+
setIsLoading(false);
|
|
11281
|
+
return;
|
|
11282
|
+
}
|
|
11283
|
+
// STANDALONE MODE: Load from persistent storage
|
|
11248
11284
|
const storedToken = await tokenStorage.getToken();
|
|
11249
11285
|
const storedUser = await tokenStorage.getUser();
|
|
11250
11286
|
const storedAccountData = await tokenStorage.getAccountData();
|
|
@@ -11271,9 +11307,49 @@ const AuthProvider = ({ children, accountCacheTTL = 5 * 60 * 1000, preloadAccoun
|
|
|
11271
11307
|
}
|
|
11272
11308
|
};
|
|
11273
11309
|
initializeAuth();
|
|
11274
|
-
}, []);
|
|
11275
|
-
//
|
|
11310
|
+
}, [proxyMode, notifyAuthStateChange]);
|
|
11311
|
+
// Listen for parent auth state changes (proxy mode only)
|
|
11312
|
+
useEffect(() => {
|
|
11313
|
+
if (!proxyMode)
|
|
11314
|
+
return;
|
|
11315
|
+
console.log('[AuthContext] Proxy mode: setting up parent message listener');
|
|
11316
|
+
const handleParentMessage = (event) => {
|
|
11317
|
+
// Handle auth state pushed from parent
|
|
11318
|
+
if (event.data?.type === 'smartlinks:authkit:state') {
|
|
11319
|
+
const { user: parentUser, accountData: parentAccountData, authenticated } = event.data.payload || {};
|
|
11320
|
+
console.log('[AuthContext] Proxy mode: received state from parent:', { authenticated });
|
|
11321
|
+
if (authenticated && parentUser) {
|
|
11322
|
+
const userObj = {
|
|
11323
|
+
uid: parentUser.uid || parentUser.id,
|
|
11324
|
+
email: parentUser.email,
|
|
11325
|
+
displayName: parentUser.displayName || parentUser.name,
|
|
11326
|
+
phoneNumber: parentUser.phoneNumber,
|
|
11327
|
+
};
|
|
11328
|
+
setUser(userObj);
|
|
11329
|
+
setAccountData(parentAccountData || null);
|
|
11330
|
+
setAccountInfo(parentAccountData || null);
|
|
11331
|
+
notifyAuthStateChange('CROSS_TAB_SYNC', userObj, null, parentAccountData || null, parentAccountData || null);
|
|
11332
|
+
}
|
|
11333
|
+
else {
|
|
11334
|
+
// Parent indicates no session / logged out
|
|
11335
|
+
setUser(null);
|
|
11336
|
+
setToken(null);
|
|
11337
|
+
setAccountData(null);
|
|
11338
|
+
setAccountInfo(null);
|
|
11339
|
+
notifyAuthStateChange('LOGOUT', null, null, null, null);
|
|
11340
|
+
}
|
|
11341
|
+
}
|
|
11342
|
+
};
|
|
11343
|
+
window.addEventListener('message', handleParentMessage);
|
|
11344
|
+
return () => {
|
|
11345
|
+
console.log('[AuthContext] Proxy mode: cleaning up parent message listener');
|
|
11346
|
+
window.removeEventListener('message', handleParentMessage);
|
|
11347
|
+
};
|
|
11348
|
+
}, [proxyMode, notifyAuthStateChange]);
|
|
11349
|
+
// Cross-tab synchronization - standalone mode only
|
|
11276
11350
|
useEffect(() => {
|
|
11351
|
+
if (proxyMode)
|
|
11352
|
+
return; // Skip cross-tab sync in proxy mode
|
|
11277
11353
|
console.log('[AuthContext] Setting up cross-tab synchronization');
|
|
11278
11354
|
const unsubscribe = onStorageChange(async (event) => {
|
|
11279
11355
|
console.log('[AuthContext] Cross-tab storage event:', event.type, event.key);
|
|
@@ -11332,27 +11408,38 @@ const AuthProvider = ({ children, accountCacheTTL = 5 * 60 * 1000, preloadAccoun
|
|
|
11332
11408
|
console.log('[AuthContext] Cleaning up cross-tab synchronization');
|
|
11333
11409
|
unsubscribe();
|
|
11334
11410
|
};
|
|
11335
|
-
}, [notifyAuthStateChange]);
|
|
11411
|
+
}, [proxyMode, notifyAuthStateChange]);
|
|
11336
11412
|
const login = useCallback(async (authToken, authUser, authAccountData) => {
|
|
11337
11413
|
try {
|
|
11338
|
-
//
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11414
|
+
// Only persist to storage in standalone mode
|
|
11415
|
+
if (!proxyMode) {
|
|
11416
|
+
await tokenStorage.saveToken(authToken);
|
|
11417
|
+
await tokenStorage.saveUser(authUser);
|
|
11418
|
+
if (authAccountData) {
|
|
11419
|
+
await tokenStorage.saveAccountData(authAccountData);
|
|
11420
|
+
}
|
|
11421
|
+
// Set bearer token in global Smartlinks SDK via auth.verifyToken
|
|
11422
|
+
smartlinks.auth.verifyToken(authToken).catch(err => {
|
|
11423
|
+
console.warn('Failed to set bearer token on login:', err);
|
|
11424
|
+
});
|
|
11343
11425
|
}
|
|
11426
|
+
// Always update memory state
|
|
11344
11427
|
setToken(authToken);
|
|
11345
11428
|
setUser(authUser);
|
|
11346
11429
|
setAccountData(authAccountData || null);
|
|
11347
|
-
//
|
|
11348
|
-
//
|
|
11349
|
-
|
|
11350
|
-
console.
|
|
11351
|
-
|
|
11430
|
+
// Cross-iframe auth state synchronization
|
|
11431
|
+
// Always notify parent frame of login (both modes, but especially important in proxy mode)
|
|
11432
|
+
if (iframe.isIframe()) {
|
|
11433
|
+
console.log('[AuthContext] Notifying parent of login via postMessage');
|
|
11434
|
+
iframe.sendParentCustom('smartlinks:authkit:login', {
|
|
11435
|
+
token: authToken,
|
|
11436
|
+
user: authUser,
|
|
11437
|
+
accountData: authAccountData || null
|
|
11438
|
+
});
|
|
11439
|
+
}
|
|
11352
11440
|
notifyAuthStateChange('LOGIN', authUser, authToken, authAccountData || null);
|
|
11353
|
-
// Optionally preload account info on login
|
|
11354
|
-
if (preloadAccountInfo) {
|
|
11355
|
-
// Preload after login completes (non-blocking)
|
|
11441
|
+
// Optionally preload account info on login (standalone mode only)
|
|
11442
|
+
if (!proxyMode && preloadAccountInfo) {
|
|
11356
11443
|
getAccount(true).catch(error => {
|
|
11357
11444
|
console.warn('[AuthContext] Failed to preload account info:', error);
|
|
11358
11445
|
});
|
|
@@ -11362,34 +11449,55 @@ const AuthProvider = ({ children, accountCacheTTL = 5 * 60 * 1000, preloadAccoun
|
|
|
11362
11449
|
console.error('Failed to save auth data to storage:', error);
|
|
11363
11450
|
throw error;
|
|
11364
11451
|
}
|
|
11365
|
-
}, [notifyAuthStateChange, preloadAccountInfo]);
|
|
11452
|
+
}, [proxyMode, notifyAuthStateChange, preloadAccountInfo]);
|
|
11366
11453
|
const logout = useCallback(async () => {
|
|
11367
11454
|
try {
|
|
11368
|
-
//
|
|
11369
|
-
|
|
11455
|
+
// Only clear persistent storage in standalone mode
|
|
11456
|
+
if (!proxyMode) {
|
|
11457
|
+
await tokenStorage.clearAll();
|
|
11458
|
+
smartlinks.auth.logout();
|
|
11459
|
+
}
|
|
11460
|
+
// Always clear memory state
|
|
11370
11461
|
setToken(null);
|
|
11371
11462
|
setUser(null);
|
|
11372
11463
|
setAccountData(null);
|
|
11373
11464
|
setAccountInfo(null);
|
|
11374
|
-
//
|
|
11375
|
-
|
|
11465
|
+
// Cross-iframe auth state synchronization
|
|
11466
|
+
// Always notify parent frame of logout
|
|
11467
|
+
if (iframe.isIframe()) {
|
|
11468
|
+
console.log('[AuthContext] Notifying parent of logout via postMessage');
|
|
11469
|
+
iframe.sendParentCustom('smartlinks:authkit:logout', {});
|
|
11470
|
+
}
|
|
11376
11471
|
notifyAuthStateChange('LOGOUT', null, null, null);
|
|
11377
11472
|
}
|
|
11378
11473
|
catch (error) {
|
|
11379
11474
|
console.error('Failed to clear auth data from storage:', error);
|
|
11380
11475
|
}
|
|
11381
|
-
}, [notifyAuthStateChange]);
|
|
11476
|
+
}, [proxyMode, notifyAuthStateChange]);
|
|
11382
11477
|
const getToken = useCallback(async () => {
|
|
11478
|
+
if (proxyMode) {
|
|
11479
|
+
// In proxy mode, token is managed by parent - return memory state
|
|
11480
|
+
return token;
|
|
11481
|
+
}
|
|
11383
11482
|
const storedToken = await tokenStorage.getToken();
|
|
11384
11483
|
return storedToken ? storedToken.token : null;
|
|
11385
|
-
}, []);
|
|
11484
|
+
}, [proxyMode, token]);
|
|
11386
11485
|
const refreshToken = useCallback(async () => {
|
|
11387
11486
|
throw new Error('Token refresh must be implemented via your backend API');
|
|
11388
11487
|
}, []);
|
|
11389
|
-
// Get account with intelligent caching
|
|
11488
|
+
// Get account with intelligent caching (or direct parent fetch in proxy mode)
|
|
11390
11489
|
const getAccount = useCallback(async (forceRefresh = false) => {
|
|
11391
11490
|
try {
|
|
11392
|
-
|
|
11491
|
+
if (proxyMode) {
|
|
11492
|
+
// PROXY MODE: Always fetch from parent via proxied API, no local cache
|
|
11493
|
+
console.log('[AuthContext] Proxy mode: fetching account from parent');
|
|
11494
|
+
const freshAccountInfo = await smartlinks.auth.getAccount();
|
|
11495
|
+
setAccountInfo(freshAccountInfo);
|
|
11496
|
+
setAccountData(freshAccountInfo);
|
|
11497
|
+
notifyAuthStateChange('ACCOUNT_REFRESH', user, token, freshAccountInfo, freshAccountInfo);
|
|
11498
|
+
return freshAccountInfo;
|
|
11499
|
+
}
|
|
11500
|
+
// STANDALONE MODE: Use caching
|
|
11393
11501
|
if (!token) {
|
|
11394
11502
|
throw new Error('Not authenticated. Please login first.');
|
|
11395
11503
|
}
|
|
@@ -11412,24 +11520,28 @@ const AuthProvider = ({ children, accountCacheTTL = 5 * 60 * 1000, preloadAccoun
|
|
|
11412
11520
|
}
|
|
11413
11521
|
catch (error) {
|
|
11414
11522
|
console.error('[AuthContext] Failed to get account info:', error);
|
|
11415
|
-
// Fallback to stale cache if API fails
|
|
11416
|
-
|
|
11417
|
-
|
|
11418
|
-
|
|
11419
|
-
|
|
11523
|
+
// Fallback to stale cache if API fails (standalone mode only)
|
|
11524
|
+
if (!proxyMode) {
|
|
11525
|
+
const cached = await tokenStorage.getAccountInfo();
|
|
11526
|
+
if (cached) {
|
|
11527
|
+
console.warn('[AuthContext] Returning stale cached data due to API error');
|
|
11528
|
+
return cached.data;
|
|
11529
|
+
}
|
|
11420
11530
|
}
|
|
11421
11531
|
throw error;
|
|
11422
11532
|
}
|
|
11423
|
-
}, [token, accountCacheTTL, user, accountData, notifyAuthStateChange]);
|
|
11533
|
+
}, [proxyMode, token, accountCacheTTL, user, accountData, notifyAuthStateChange]);
|
|
11424
11534
|
// Convenience method for explicit refresh
|
|
11425
11535
|
const refreshAccount = useCallback(async () => {
|
|
11426
11536
|
return await getAccount(true);
|
|
11427
11537
|
}, [getAccount]);
|
|
11428
|
-
// Clear account cache
|
|
11538
|
+
// Clear account cache (no-op in proxy mode)
|
|
11429
11539
|
const clearAccountCache = useCallback(async () => {
|
|
11430
|
-
|
|
11540
|
+
if (!proxyMode) {
|
|
11541
|
+
await tokenStorage.clearAccountInfo();
|
|
11542
|
+
}
|
|
11431
11543
|
setAccountInfo(null);
|
|
11432
|
-
}, []);
|
|
11544
|
+
}, [proxyMode]);
|
|
11433
11545
|
const onAuthStateChange = useCallback((callback) => {
|
|
11434
11546
|
callbacksRef.current.add(callback);
|
|
11435
11547
|
// Return unsubscribe function
|
|
@@ -11442,8 +11554,9 @@ const AuthProvider = ({ children, accountCacheTTL = 5 * 60 * 1000, preloadAccoun
|
|
|
11442
11554
|
token,
|
|
11443
11555
|
accountData,
|
|
11444
11556
|
accountInfo,
|
|
11445
|
-
isAuthenticated: !!
|
|
11557
|
+
isAuthenticated: !!user,
|
|
11446
11558
|
isLoading,
|
|
11559
|
+
proxyMode,
|
|
11447
11560
|
login,
|
|
11448
11561
|
logout,
|
|
11449
11562
|
getToken,
|
|
@@ -11533,7 +11646,7 @@ const getFriendlyErrorMessage = (errorMessage) => {
|
|
|
11533
11646
|
// Return original message if no pattern matches
|
|
11534
11647
|
return errorMessage;
|
|
11535
11648
|
};
|
|
11536
|
-
const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAuthSuccess, onAuthError, enabledProviders = ['email', 'google', 'phone'], initialMode = 'login', redirectUrl, theme = 'auto', className, customization, skipConfigFetch = false, minimal = false, logger, }) => {
|
|
11649
|
+
const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAuthSuccess, onAuthError, enabledProviders = ['email', 'google', 'phone'], initialMode = 'login', redirectUrl, theme = 'auto', className, customization, skipConfigFetch = false, minimal = false, logger, proxyMode = false, }) => {
|
|
11537
11650
|
const [mode, setMode] = useState(initialMode);
|
|
11538
11651
|
const [loading, setLoading] = useState(false);
|
|
11539
11652
|
const [error, setError] = useState();
|
|
@@ -11566,25 +11679,25 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
11566
11679
|
mediaQuery.addEventListener('change', updateTheme);
|
|
11567
11680
|
return () => mediaQuery.removeEventListener('change', updateTheme);
|
|
11568
11681
|
}, [theme]);
|
|
11569
|
-
// Reinitialize Smartlinks SDK when apiEndpoint
|
|
11682
|
+
// Reinitialize Smartlinks SDK when apiEndpoint or proxyMode changes
|
|
11570
11683
|
// IMPORTANT: Preserve bearer token during reinitialization
|
|
11571
11684
|
useEffect(() => {
|
|
11572
|
-
log.log('SDK reinitialize useEffect triggered', { apiEndpoint });
|
|
11685
|
+
log.log('SDK reinitialize useEffect triggered', { apiEndpoint, proxyMode });
|
|
11573
11686
|
setSdkReady(false); // Mark SDK as not ready during reinitialization
|
|
11574
11687
|
const reinitializeWithToken = async () => {
|
|
11575
11688
|
if (apiEndpoint) {
|
|
11576
|
-
log.log('Reinitializing SDK with baseURL:', apiEndpoint);
|
|
11577
|
-
// Get current token before reinitializing
|
|
11578
|
-
const currentToken = await auth.getToken();
|
|
11689
|
+
log.log('Reinitializing SDK with baseURL:', apiEndpoint, 'proxyMode:', proxyMode);
|
|
11690
|
+
// Get current token before reinitializing (only in standalone mode)
|
|
11691
|
+
const currentToken = !proxyMode ? await auth.getToken() : null;
|
|
11579
11692
|
smartlinks.initializeApi({
|
|
11580
11693
|
baseURL: apiEndpoint,
|
|
11581
|
-
proxyMode:
|
|
11694
|
+
proxyMode: proxyMode, // Use prop value
|
|
11582
11695
|
ngrokSkipBrowserWarning: true,
|
|
11583
11696
|
logger: logger, // Pass logger to SDK for verbose SDK logging
|
|
11584
11697
|
});
|
|
11585
11698
|
log.log('SDK reinitialized successfully');
|
|
11586
|
-
// Restore bearer token after reinitialization using auth.verifyToken
|
|
11587
|
-
if (currentToken) {
|
|
11699
|
+
// Restore bearer token after reinitialization using auth.verifyToken (standalone mode only)
|
|
11700
|
+
if (currentToken && !proxyMode) {
|
|
11588
11701
|
smartlinks.auth.verifyToken(currentToken).catch(err => {
|
|
11589
11702
|
log.warn('Failed to restore bearer token after reinit:', err);
|
|
11590
11703
|
});
|
|
@@ -11592,6 +11705,11 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
11592
11705
|
// Mark SDK as ready
|
|
11593
11706
|
setSdkReady(true);
|
|
11594
11707
|
}
|
|
11708
|
+
else if (proxyMode) {
|
|
11709
|
+
// In proxy mode without custom endpoint, SDK should already be initialized by parent
|
|
11710
|
+
log.log('Proxy mode without apiEndpoint, SDK already initialized by parent');
|
|
11711
|
+
setSdkReady(true);
|
|
11712
|
+
}
|
|
11595
11713
|
else {
|
|
11596
11714
|
log.log('No apiEndpoint, SDK already initialized by App');
|
|
11597
11715
|
// SDK was initialized by App component, mark as ready
|
|
@@ -11599,7 +11717,7 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
11599
11717
|
}
|
|
11600
11718
|
};
|
|
11601
11719
|
reinitializeWithToken();
|
|
11602
|
-
}, [apiEndpoint, auth, logger, log]);
|
|
11720
|
+
}, [apiEndpoint, proxyMode, auth, logger, log]);
|
|
11603
11721
|
// Get the effective redirect URL (use prop or default to current page)
|
|
11604
11722
|
const getRedirectUrl = () => {
|
|
11605
11723
|
if (redirectUrl)
|
|
@@ -12113,11 +12231,18 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
12113
12231
|
},
|
|
12114
12232
|
auto_select: false,
|
|
12115
12233
|
cancel_on_tap_outside: true,
|
|
12234
|
+
// Note: use_fedcm_for_prompt omitted - requires Permissions-Policy header on hosting server
|
|
12235
|
+
// Will be needed when FedCM becomes mandatory in the future
|
|
12116
12236
|
});
|
|
12117
|
-
|
|
12118
|
-
|
|
12119
|
-
|
|
12120
|
-
|
|
12237
|
+
// Use timeout fallback instead of deprecated notification methods
|
|
12238
|
+
// (isNotDisplayed/isSkippedMoment will stop working when FedCM becomes mandatory)
|
|
12239
|
+
const promptTimeout = setTimeout(() => {
|
|
12240
|
+
setLoading(false);
|
|
12241
|
+
}, 5000);
|
|
12242
|
+
google.accounts.id.prompt(() => {
|
|
12243
|
+
// Clear timeout if prompt interaction occurs
|
|
12244
|
+
clearTimeout(promptTimeout);
|
|
12245
|
+
setLoading(false);
|
|
12121
12246
|
});
|
|
12122
12247
|
}
|
|
12123
12248
|
}
|