@proveanything/smartlinks-auth-ui 0.5.10 → 0.5.12
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/index.esm.js +80 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +80 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAcpE,OAAO,KAAK,EAAE,qBAAqB,EAAyF,MAAM,UAAU,CAAC;AAiR7I,QAAA,MAAM,mBAAmB,QAAa,OAAO,CAAC,IAAI,CAqBjD,CAAC;AAqDF,OAAO,EAAE,mBAAmB,EAAE,CAAC;AAI/B,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CA2kE5D,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -12958,13 +12958,18 @@ const getActionResultErrorMessage = (result) => {
|
|
|
12958
12958
|
details: candidate.details,
|
|
12959
12959
|
});
|
|
12960
12960
|
};
|
|
12961
|
+
// ----- WhatsApp reply helpers -----
|
|
12962
|
+
const WHATSAPP_PENDING_SESSION_KEY = 'whatsapp_pending_session';
|
|
12961
12963
|
const interpolateReply = (input, vars) => {
|
|
12962
12964
|
if (!input)
|
|
12963
12965
|
return input;
|
|
12964
12966
|
return input
|
|
12965
12967
|
.replace(/\{\{\s*name\s*\}\}/gi, vars.name?.trim() || 'there')
|
|
12966
12968
|
.replace(/\{\{\s*clientName\s*\}\}/gi, vars.clientName?.trim() || '')
|
|
12967
|
-
.replace(/\{\{\s*phoneNumber\s*\}\}/gi, vars.phoneNumber?.trim() || '')
|
|
12969
|
+
.replace(/\{\{\s*phoneNumber\s*\}\}/gi, vars.phoneNumber?.trim() || '')
|
|
12970
|
+
.replace(/\{\{\s*returnUrl\s*\}\}/gi, vars.returnUrl?.trim() || '')
|
|
12971
|
+
.replace(/\{\{\s*clientId\s*\}\}/gi, vars.clientId?.trim() || '')
|
|
12972
|
+
.replace(/\{\{\s*token\s*\}\}/gi, vars.token?.trim() || '');
|
|
12968
12973
|
};
|
|
12969
12974
|
const buildWhatsAppReply = (cfg, vars) => {
|
|
12970
12975
|
if (!cfg)
|
|
@@ -13290,6 +13295,24 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
13290
13295
|
// Get the full current URL including hash routes, strip query params
|
|
13291
13296
|
return window.location.href.split('?')[0];
|
|
13292
13297
|
};
|
|
13298
|
+
const savePendingWhatsAppSession = async (session) => {
|
|
13299
|
+
if (proxyMode)
|
|
13300
|
+
return;
|
|
13301
|
+
const storage = await getStorage();
|
|
13302
|
+
await storage.setItem(WHATSAPP_PENDING_SESSION_KEY, session);
|
|
13303
|
+
};
|
|
13304
|
+
const loadPendingWhatsAppSession = async () => {
|
|
13305
|
+
if (proxyMode)
|
|
13306
|
+
return null;
|
|
13307
|
+
const storage = await getStorage();
|
|
13308
|
+
return storage.getItem(WHATSAPP_PENDING_SESSION_KEY);
|
|
13309
|
+
};
|
|
13310
|
+
const clearPendingWhatsAppSession = async () => {
|
|
13311
|
+
if (proxyMode)
|
|
13312
|
+
return;
|
|
13313
|
+
const storage = await getStorage();
|
|
13314
|
+
await storage.removeItem(WHATSAPP_PENDING_SESSION_KEY);
|
|
13315
|
+
};
|
|
13293
13316
|
// Fetch UI configuration
|
|
13294
13317
|
useEffect(() => {
|
|
13295
13318
|
// Wait for SDK to be ready before fetching config
|
|
@@ -14379,6 +14402,48 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14379
14402
|
};
|
|
14380
14403
|
// Track the most recent WhatsApp send so we can exchange its sessionKey for a real login session.
|
|
14381
14404
|
const whatsappSendRef = useRef(null);
|
|
14405
|
+
useEffect(() => {
|
|
14406
|
+
if (proxyMode)
|
|
14407
|
+
return;
|
|
14408
|
+
let cancelled = false;
|
|
14409
|
+
const resumePendingWhatsAppSession = async () => {
|
|
14410
|
+
try {
|
|
14411
|
+
const pending = await loadPendingWhatsAppSession();
|
|
14412
|
+
if (!pending || cancelled)
|
|
14413
|
+
return;
|
|
14414
|
+
// Expire stale pending sessions after 30 minutes to avoid resurrecting old attempts.
|
|
14415
|
+
if (Date.now() - pending.createdAt > 30 * 60 * 1000) {
|
|
14416
|
+
await clearPendingWhatsAppSession();
|
|
14417
|
+
return;
|
|
14418
|
+
}
|
|
14419
|
+
whatsappSendRef.current = {
|
|
14420
|
+
token: pending.token,
|
|
14421
|
+
sessionKey: pending.sessionKey,
|
|
14422
|
+
displayName: pending.displayName,
|
|
14423
|
+
};
|
|
14424
|
+
const status = await api.getWhatsAppStatus(pending.token);
|
|
14425
|
+
if (cancelled)
|
|
14426
|
+
return;
|
|
14427
|
+
if (status.verified) {
|
|
14428
|
+
await handleWhatsAppVerified(status);
|
|
14429
|
+
return;
|
|
14430
|
+
}
|
|
14431
|
+
if (status.status === 'pending') {
|
|
14432
|
+
setMode('whatsapp');
|
|
14433
|
+
}
|
|
14434
|
+
else if (status.status === 'failed' || status.status === 'expired' || status.status === 'unknown') {
|
|
14435
|
+
await clearPendingWhatsAppSession();
|
|
14436
|
+
}
|
|
14437
|
+
}
|
|
14438
|
+
catch (err) {
|
|
14439
|
+
log.warn('Failed to resume pending WhatsApp session:', err);
|
|
14440
|
+
}
|
|
14441
|
+
};
|
|
14442
|
+
resumePendingWhatsAppSession();
|
|
14443
|
+
return () => {
|
|
14444
|
+
cancelled = true;
|
|
14445
|
+
};
|
|
14446
|
+
}, [proxyMode, clientId]);
|
|
14382
14447
|
const handleWhatsAppSend = async (displayName) => {
|
|
14383
14448
|
setLoading(true);
|
|
14384
14449
|
setError(undefined);
|
|
@@ -14387,9 +14452,12 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14387
14452
|
// account from the inbound WhatsApp webhook (sender's number is the proof).
|
|
14388
14453
|
// Resolve reply config: per-call prop wins, otherwise fall back to AuthKit default.
|
|
14389
14454
|
const replyConfig = whatsappReply ?? config?.whatsappReply;
|
|
14455
|
+
const effectiveRedirectUrl = getRedirectUrl();
|
|
14390
14456
|
const reply = buildWhatsAppReply(replyConfig, {
|
|
14391
14457
|
name: displayName,
|
|
14392
14458
|
clientName,
|
|
14459
|
+
returnUrl: effectiveRedirectUrl,
|
|
14460
|
+
clientId,
|
|
14393
14461
|
});
|
|
14394
14462
|
// Resolve outbound prefill message: per-call prop wins, then AuthKit default.
|
|
14395
14463
|
const prefillMessage = whatsappPrefillMessage ?? config?.whatsappPrefillMessage;
|
|
@@ -14398,12 +14466,19 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14398
14466
|
// formed session.user — no follow-up updateProfile call needed.
|
|
14399
14467
|
const trimmedName = displayName?.trim() || undefined;
|
|
14400
14468
|
const contactData = trimmedName ? { name: trimmedName } : undefined;
|
|
14401
|
-
const result = await api.sendWhatsApp(
|
|
14469
|
+
const result = await api.sendWhatsApp(effectiveRedirectUrl, undefined, reply, prefillMessage, contactData);
|
|
14402
14470
|
whatsappSendRef.current = {
|
|
14403
14471
|
token: result.token,
|
|
14404
14472
|
sessionKey: result.sessionKey,
|
|
14405
14473
|
displayName: trimmedName,
|
|
14406
14474
|
};
|
|
14475
|
+
await savePendingWhatsAppSession({
|
|
14476
|
+
token: result.token,
|
|
14477
|
+
sessionKey: result.sessionKey,
|
|
14478
|
+
displayName: trimmedName,
|
|
14479
|
+
redirectUrl: effectiveRedirectUrl,
|
|
14480
|
+
createdAt: Date.now(),
|
|
14481
|
+
});
|
|
14407
14482
|
return result;
|
|
14408
14483
|
}
|
|
14409
14484
|
catch (err) {
|
|
@@ -14434,12 +14509,15 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14434
14509
|
if (!proxyMode) {
|
|
14435
14510
|
onAuthSuccess(session.token, session.user, session.accountData);
|
|
14436
14511
|
}
|
|
14512
|
+
await clearPendingWhatsAppSession();
|
|
14513
|
+
return;
|
|
14437
14514
|
}
|
|
14438
14515
|
}
|
|
14439
14516
|
catch (err) {
|
|
14440
14517
|
log.warn('WhatsApp session exchange failed, falling back to redirect-only flow:', err);
|
|
14441
14518
|
}
|
|
14442
14519
|
}
|
|
14520
|
+
await clearPendingWhatsAppSession();
|
|
14443
14521
|
performRedirect(target, 'magic-link');
|
|
14444
14522
|
};
|
|
14445
14523
|
// Show processing state for URL-based auth (verification, magic link, password reset)
|