@proveanything/smartlinks-auth-ui 0.5.13 → 0.5.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.map +1 -1
- package/dist/index.esm.js +79 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +79 -4
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -12775,6 +12775,9 @@ collectionId, enableContactSync, enableInteractionTracking, interactionAppId, in
|
|
|
12775
12775
|
await tokenStorage.saveAccountData(authAccountData);
|
|
12776
12776
|
await tokenStorage.saveAccountInfo(authAccountData, accountCacheTTL);
|
|
12777
12777
|
}
|
|
12778
|
+
else {
|
|
12779
|
+
await tokenStorage.clearAccountData();
|
|
12780
|
+
}
|
|
12778
12781
|
smartlinks__namespace.auth.verifyToken(authToken).catch(() => { });
|
|
12779
12782
|
}
|
|
12780
12783
|
// Always update memory state (but NOT isVerified yet - wait for parent ack in iframe mode)
|
|
@@ -13119,6 +13122,22 @@ const normalizeQueryString = (query) => {
|
|
|
13119
13122
|
const buildSearchParams = (rawQuery) => {
|
|
13120
13123
|
return new URLSearchParams(normalizeQueryString(rawQuery));
|
|
13121
13124
|
};
|
|
13125
|
+
const appendWhatsAppResumeParams = (url, token) => {
|
|
13126
|
+
try {
|
|
13127
|
+
const nextUrl = new URL(url, window.location.origin);
|
|
13128
|
+
nextUrl.searchParams.set('mode', 'whatsapp');
|
|
13129
|
+
if (token) {
|
|
13130
|
+
nextUrl.searchParams.set('token', token);
|
|
13131
|
+
}
|
|
13132
|
+
else {
|
|
13133
|
+
nextUrl.searchParams.delete('token');
|
|
13134
|
+
}
|
|
13135
|
+
return nextUrl.toString();
|
|
13136
|
+
}
|
|
13137
|
+
catch {
|
|
13138
|
+
return url;
|
|
13139
|
+
}
|
|
13140
|
+
};
|
|
13122
13141
|
// Helper to check for URL auth params synchronously (runs during initialization)
|
|
13123
13142
|
// This prevents the form from flashing before detecting deep-link flows
|
|
13124
13143
|
const getInitialUrlAuthParams = () => {
|
|
@@ -13141,6 +13160,19 @@ const getExpirationFromResponse = (response) => {
|
|
|
13141
13160
|
return Date.now() + response.expiresIn;
|
|
13142
13161
|
return undefined; // Will use 7-day default in tokenStorage
|
|
13143
13162
|
};
|
|
13163
|
+
const stripWhatsAppResumeParams = (url) => {
|
|
13164
|
+
try {
|
|
13165
|
+
const urlObj = new URL(url);
|
|
13166
|
+
if (urlObj.searchParams.get('mode') === 'whatsapp') {
|
|
13167
|
+
urlObj.searchParams.delete('mode');
|
|
13168
|
+
urlObj.searchParams.delete('token');
|
|
13169
|
+
}
|
|
13170
|
+
return urlObj.toString();
|
|
13171
|
+
}
|
|
13172
|
+
catch {
|
|
13173
|
+
return url;
|
|
13174
|
+
}
|
|
13175
|
+
};
|
|
13144
13176
|
const getActionResultErrorMessage = (result) => {
|
|
13145
13177
|
if (!result || typeof result !== 'object')
|
|
13146
13178
|
return null;
|
|
@@ -13498,11 +13530,34 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
13498
13530
|
// Get the full current URL including hash routes, strip query params
|
|
13499
13531
|
return window.location.href.split('?')[0];
|
|
13500
13532
|
};
|
|
13533
|
+
const syncWhatsAppResumeUrl = (pending) => {
|
|
13534
|
+
if (typeof window === 'undefined')
|
|
13535
|
+
return;
|
|
13536
|
+
try {
|
|
13537
|
+
const currentUrl = new URL(window.location.href);
|
|
13538
|
+
const isOnResumeUrl = currentUrl.searchParams.get('mode') === 'whatsapp';
|
|
13539
|
+
if (!pending) {
|
|
13540
|
+
if (!isOnResumeUrl)
|
|
13541
|
+
return;
|
|
13542
|
+
const cleanUrl = stripWhatsAppResumeParams(currentUrl.toString());
|
|
13543
|
+
window.history.replaceState({}, document.title, cleanUrl);
|
|
13544
|
+
return;
|
|
13545
|
+
}
|
|
13546
|
+
const resumedUrl = appendWhatsAppResumeParams(pending.redirectUrl || currentUrl.toString(), pending.token);
|
|
13547
|
+
if (currentUrl.toString() !== resumedUrl) {
|
|
13548
|
+
window.history.replaceState({}, document.title, resumedUrl);
|
|
13549
|
+
}
|
|
13550
|
+
}
|
|
13551
|
+
catch (err) {
|
|
13552
|
+
log.warn('Failed to sync WhatsApp resume URL state:', err);
|
|
13553
|
+
}
|
|
13554
|
+
};
|
|
13501
13555
|
const savePendingWhatsAppSession = async (session) => {
|
|
13502
13556
|
if (proxyMode)
|
|
13503
13557
|
return;
|
|
13504
13558
|
const storage = await getStorage();
|
|
13505
13559
|
await storage.setItem(WHATSAPP_PENDING_SESSION_KEY, session);
|
|
13560
|
+
syncWhatsAppResumeUrl(session);
|
|
13506
13561
|
};
|
|
13507
13562
|
const loadPendingWhatsAppSession = async () => {
|
|
13508
13563
|
if (proxyMode)
|
|
@@ -13515,6 +13570,7 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
13515
13570
|
return;
|
|
13516
13571
|
const storage = await getStorage();
|
|
13517
13572
|
await storage.removeItem(WHATSAPP_PENDING_SESSION_KEY);
|
|
13573
|
+
syncWhatsAppResumeUrl(null);
|
|
13518
13574
|
};
|
|
13519
13575
|
const updatePendingWhatsAppSession = async (updates) => {
|
|
13520
13576
|
if (proxyMode)
|
|
@@ -13698,6 +13754,12 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
13698
13754
|
// Google OAuth redirect callback
|
|
13699
13755
|
handleGoogleAuthCodeCallback(authCode, state);
|
|
13700
13756
|
}
|
|
13757
|
+
else if (urlMode === 'whatsapp') {
|
|
13758
|
+
if (!auth.user?.uid) {
|
|
13759
|
+
setMode('whatsapp');
|
|
13760
|
+
}
|
|
13761
|
+
setUrlAuthProcessing(false);
|
|
13762
|
+
}
|
|
13701
13763
|
else if (urlMode && token) {
|
|
13702
13764
|
handleURLBasedAuth(urlMode, token);
|
|
13703
13765
|
}
|
|
@@ -14621,14 +14683,26 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14621
14683
|
let cancelled = false;
|
|
14622
14684
|
const resumePendingWhatsAppSession = async () => {
|
|
14623
14685
|
try {
|
|
14686
|
+
const urlParams = buildSearchParams(window.location.search);
|
|
14687
|
+
const resumeMode = urlParams.get('mode');
|
|
14688
|
+
const resumeToken = urlParams.get('token');
|
|
14624
14689
|
const pending = await loadPendingWhatsAppSession();
|
|
14625
|
-
if (!pending || cancelled)
|
|
14690
|
+
if (!pending || cancelled) {
|
|
14691
|
+
if (resumeMode === 'whatsapp') {
|
|
14692
|
+
syncWhatsAppResumeUrl(null);
|
|
14693
|
+
}
|
|
14626
14694
|
return;
|
|
14695
|
+
}
|
|
14627
14696
|
// Expire stale pending sessions after 30 minutes to avoid resurrecting old attempts.
|
|
14628
14697
|
if (Date.now() - pending.createdAt > 30 * 60 * 1000) {
|
|
14629
14698
|
await clearPendingWhatsAppSession();
|
|
14630
14699
|
return;
|
|
14631
14700
|
}
|
|
14701
|
+
if (resumeMode === 'whatsapp' && resumeToken && resumeToken !== pending.token) {
|
|
14702
|
+
await clearPendingWhatsAppSession();
|
|
14703
|
+
return;
|
|
14704
|
+
}
|
|
14705
|
+
syncWhatsAppResumeUrl(pending);
|
|
14632
14706
|
whatsappSendRef.current = {
|
|
14633
14707
|
token: pending.token,
|
|
14634
14708
|
sessionKey: pending.sessionKey,
|
|
@@ -14651,7 +14725,7 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14651
14725
|
}
|
|
14652
14726
|
return;
|
|
14653
14727
|
}
|
|
14654
|
-
if (status.status === 'pending') {
|
|
14728
|
+
if (resumeMode === 'whatsapp' || status.status === 'pending') {
|
|
14655
14729
|
setMode('whatsapp');
|
|
14656
14730
|
}
|
|
14657
14731
|
else if (status.status === 'failed' || status.status === 'expired' || status.status === 'unknown') {
|
|
@@ -14773,8 +14847,9 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14773
14847
|
fontSize: '0.875rem'
|
|
14774
14848
|
}, children: initialUrlParams.mode === 'verifyEmail' ? 'Verifying your email...' :
|
|
14775
14849
|
initialUrlParams.mode === 'magicLink' ? 'Processing magic link...' :
|
|
14776
|
-
initialUrlParams.mode === '
|
|
14777
|
-
'
|
|
14850
|
+
initialUrlParams.mode === 'whatsapp' ? 'Resuming your WhatsApp sign-in...' :
|
|
14851
|
+
initialUrlParams.mode === 'resetPassword' ? 'Validating reset link...' :
|
|
14852
|
+
'Processing...' })] }) }));
|
|
14778
14853
|
}
|
|
14779
14854
|
if (configLoading) {
|
|
14780
14855
|
return (jsxRuntime.jsx(AuthContainer, { theme: resolvedTheme, className: className, minimal: minimal || config?.branding?.minimal || false, children: jsxRuntime.jsx("div", { style: { textAlign: 'center', padding: '2rem' }, children: jsxRuntime.jsx("div", { className: "auth-spinner" }) }) }));
|