@proveanything/smartlinks-auth-ui 0.5.6 → 0.5.7
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/api.d.ts +7 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/components/AccountManagement.d.ts.map +1 -1
- package/dist/components/SmartlinksAuthUI.d.ts.map +1 -1
- package/dist/index.esm.js +77 -36
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +77 -36
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/api.d.ts
CHANGED
|
@@ -74,7 +74,13 @@ export declare class AuthAPI {
|
|
|
74
74
|
buttonLabel: string;
|
|
75
75
|
buttonUrl: string;
|
|
76
76
|
};
|
|
77
|
-
}, prefillMessage?: string
|
|
77
|
+
}, prefillMessage?: string, contactData?: {
|
|
78
|
+
name?: string;
|
|
79
|
+
email?: string;
|
|
80
|
+
source?: string;
|
|
81
|
+
customFields?: Record<string, any>;
|
|
82
|
+
[key: string]: any;
|
|
83
|
+
}): Promise<{
|
|
78
84
|
waLink: string;
|
|
79
85
|
code: string;
|
|
80
86
|
token: string;
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAIpF;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,UAAU,CAAC,CAAS;IAC5B,OAAO,CAAC,GAAG,CAAyC;gBAExC,YAAY,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,UAAU;IAQxF,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MA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GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAC;QAClE,QAAQ,EAAE,OAAO,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAC5B,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC7B,CAAC;IAII,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC;QAChE,OAAO,EAAE,OAAO,CAAC;QACjB,QAAQ,EAAE,OAAO,CAAC;QAClB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;KAC7B,CAAC;CAGH"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AccountManagement.d.ts","sourceRoot":"","sources":["../../src/components/AccountManagement.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAOhE,OAAO,KAAK,EAAE,sBAAsB,EAAe,MAAM,UAAU,CAAC;AACpE,OAAO,qBAAqB,CAAC;AAK7B,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,
|
|
1
|
+
{"version":3,"file":"AccountManagement.d.ts","sourceRoot":"","sources":["../../src/components/AccountManagement.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA2C,MAAM,OAAO,CAAC;AAOhE,OAAO,KAAK,EAAE,sBAAsB,EAAe,MAAM,UAAU,CAAC;AACpE,OAAO,qBAAqB,CAAC;AAK7B,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAwxB9D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAapE,OAAO,KAAK,EAAE,qBAAqB,EAAyF,MAAM,UAAU,CAAC;AAqQ7I,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,CAq
|
|
1
|
+
{"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA+C,MAAM,OAAO,CAAC;AAapE,OAAO,KAAK,EAAE,qBAAqB,EAAyF,MAAM,UAAU,CAAC;AAqQ7I,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,CAq/D5D,CAAC"}
|
package/dist/index.esm.js
CHANGED
|
@@ -11493,15 +11493,18 @@ class AuthAPI {
|
|
|
11493
11493
|
return smartlinks.authKit.verifyMagicLink(this.clientId, token);
|
|
11494
11494
|
}
|
|
11495
11495
|
// ============= WhatsApp =============
|
|
11496
|
-
async sendWhatsApp(redirectUrl, phoneNumber, reply, prefillMessage) {
|
|
11496
|
+
async sendWhatsApp(redirectUrl, phoneNumber, reply, prefillMessage, contactData) {
|
|
11497
11497
|
// phoneNumber is optional — backend extracts it from the inbound WhatsApp webhook.
|
|
11498
11498
|
// `reply`, when provided, is sent back to the user via WhatsApp on successful verification.
|
|
11499
11499
|
// `prefillMessage` customizes the message body pre-filled in the wa.me link.
|
|
11500
|
+
// `contactData` is upserted onto the contact when the backend creates/links it,
|
|
11501
|
+
// so the returned session.user is fully formed (name, email, custom fields, etc.).
|
|
11500
11502
|
return smartlinks.authKit.sendWhatsApp(this.clientId, {
|
|
11501
11503
|
phoneNumber: phoneNumber ?? '',
|
|
11502
11504
|
redirectUrl,
|
|
11503
11505
|
...(reply ? { reply } : {}),
|
|
11504
11506
|
...(prefillMessage ? { prefillMessage } : {}),
|
|
11507
|
+
...(contactData ? { contactData } : {}),
|
|
11505
11508
|
});
|
|
11506
11509
|
}
|
|
11507
11510
|
async exchangeWhatsAppSession(token, sessionKey) {
|
|
@@ -14271,8 +14274,17 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14271
14274
|
});
|
|
14272
14275
|
// Resolve outbound prefill message: per-call prop wins, then AuthKit default.
|
|
14273
14276
|
const prefillMessage = whatsappPrefillMessage ?? config?.whatsappPrefillMessage;
|
|
14274
|
-
|
|
14275
|
-
|
|
14277
|
+
// Pass collected signup details as contactData so the backend creates the
|
|
14278
|
+
// contact with name/customFields already attached and returns a fully
|
|
14279
|
+
// formed session.user — no follow-up updateProfile call needed.
|
|
14280
|
+
const trimmedName = displayName?.trim() || undefined;
|
|
14281
|
+
const contactData = trimmedName ? { name: trimmedName } : undefined;
|
|
14282
|
+
const result = await api.sendWhatsApp(getRedirectUrl(), undefined, reply, prefillMessage, contactData);
|
|
14283
|
+
whatsappSendRef.current = {
|
|
14284
|
+
token: result.token,
|
|
14285
|
+
sessionKey: result.sessionKey,
|
|
14286
|
+
displayName: trimmedName,
|
|
14287
|
+
};
|
|
14276
14288
|
return result;
|
|
14277
14289
|
}
|
|
14278
14290
|
catch (err) {
|
|
@@ -14291,9 +14303,9 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
|
|
|
14291
14303
|
const target = status.redirectUrl || getRedirectUrl();
|
|
14292
14304
|
setAuthSuccess(true);
|
|
14293
14305
|
setSuccessMessage('WhatsApp verified! Signing you in…');
|
|
14294
|
-
// Exchange the verified WhatsApp proof for a real Auth Kit session token
|
|
14295
|
-
//
|
|
14296
|
-
//
|
|
14306
|
+
// Exchange the verified WhatsApp proof for a real Auth Kit session token.
|
|
14307
|
+
// The backend has already created/updated the contact using contactData
|
|
14308
|
+
// sent at sendWhatsApp time, so session.user is fully formed.
|
|
14297
14309
|
const send = whatsappSendRef.current;
|
|
14298
14310
|
if (send?.sessionKey) {
|
|
14299
14311
|
try {
|
|
@@ -14636,6 +14648,32 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14636
14648
|
const [profile, setProfile] = useState(null);
|
|
14637
14649
|
const [error, setError] = useState();
|
|
14638
14650
|
const [success, setSuccess] = useState();
|
|
14651
|
+
const [resolvedClientId, setResolvedClientId] = useState(clientId);
|
|
14652
|
+
// Keep prop in sync
|
|
14653
|
+
useEffect(() => {
|
|
14654
|
+
if (clientId)
|
|
14655
|
+
setResolvedClientId(clientId);
|
|
14656
|
+
}, [clientId]);
|
|
14657
|
+
// If no clientId was provided, try to resolve the collection's default Auth Kit.
|
|
14658
|
+
// This supports "portal mode" where the host app only knows the collectionId.
|
|
14659
|
+
useEffect(() => {
|
|
14660
|
+
if (clientId || !collectionId)
|
|
14661
|
+
return;
|
|
14662
|
+
let cancelled = false;
|
|
14663
|
+
(async () => {
|
|
14664
|
+
try {
|
|
14665
|
+
const collection = await smartlinks.collection.get(collectionId);
|
|
14666
|
+
const defaultId = collection?.defaultAuthKitId;
|
|
14667
|
+
if (!cancelled && defaultId)
|
|
14668
|
+
setResolvedClientId(defaultId);
|
|
14669
|
+
}
|
|
14670
|
+
catch {
|
|
14671
|
+
// Non-fatal — handlers will surface a friendly error if still missing
|
|
14672
|
+
}
|
|
14673
|
+
})();
|
|
14674
|
+
return () => { cancelled = true; };
|
|
14675
|
+
}, [clientId, collectionId]);
|
|
14676
|
+
const NO_CLIENT_ID_MSG = 'This account section is not connected to an Auth Kit yet. Pass a clientId prop, or set a default Auth Kit on the collection in the admin console.';
|
|
14639
14677
|
// Schema state — now uses SDK type directly
|
|
14640
14678
|
const [schema, setSchema] = useState(null);
|
|
14641
14679
|
const [schemaLoading, setSchemaLoading] = useState(false);
|
|
@@ -14707,26 +14745,29 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14707
14745
|
setLoading(true);
|
|
14708
14746
|
setError(undefined);
|
|
14709
14747
|
try {
|
|
14748
|
+
// Pull contact first so we can fall back to fields the auth user object
|
|
14749
|
+
// may not carry (e.g. WhatsApp phone numbers, displayName, email).
|
|
14750
|
+
let contactData = auth.contact;
|
|
14751
|
+
if (collectionId && !contactData) {
|
|
14752
|
+
try {
|
|
14753
|
+
contactData = (await auth.getContact?.()) || null;
|
|
14754
|
+
}
|
|
14755
|
+
catch { /* non-fatal */ }
|
|
14756
|
+
}
|
|
14757
|
+
const contactAny = contactData;
|
|
14710
14758
|
const profileData = {
|
|
14711
14759
|
uid: auth.user?.uid || '',
|
|
14712
|
-
email: auth.user?.email,
|
|
14713
|
-
displayName: auth.user?.displayName,
|
|
14714
|
-
phoneNumber: auth.user?.phoneNumber,
|
|
14760
|
+
email: auth.user?.email || contactAny?.email,
|
|
14761
|
+
displayName: auth.user?.displayName || contactAny?.displayName || contactAny?.name,
|
|
14762
|
+
phoneNumber: auth.user?.phoneNumber || contactAny?.phone || contactAny?.phoneNumber,
|
|
14715
14763
|
photoURL: auth.user?.photoURL,
|
|
14716
14764
|
emailVerified: true,
|
|
14717
14765
|
accountData: auth.accountData || {},
|
|
14718
14766
|
};
|
|
14719
14767
|
setProfile(profileData);
|
|
14720
14768
|
setDisplayName(profileData.displayName || '');
|
|
14721
|
-
|
|
14722
|
-
|
|
14723
|
-
setCustomFieldValues(auth.contact.customFields || {});
|
|
14724
|
-
}
|
|
14725
|
-
else if (collectionId) {
|
|
14726
|
-
const contact = await auth.getContact?.();
|
|
14727
|
-
if (contact?.customFields) {
|
|
14728
|
-
setCustomFieldValues(contact.customFields);
|
|
14729
|
-
}
|
|
14769
|
+
if (collectionId && contactData?.customFields) {
|
|
14770
|
+
setCustomFieldValues(contactData.customFields);
|
|
14730
14771
|
}
|
|
14731
14772
|
}
|
|
14732
14773
|
catch (err) {
|
|
@@ -14758,15 +14799,15 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14758
14799
|
const editableCustomFields = getEditableFields(schema, customFieldValues).filter(f => !['email', 'displayName', 'phone', 'phoneNumber'].includes(f.key));
|
|
14759
14800
|
const handleUpdateProfile = async (e) => {
|
|
14760
14801
|
e.preventDefault();
|
|
14761
|
-
if (!
|
|
14762
|
-
setError(
|
|
14802
|
+
if (!resolvedClientId) {
|
|
14803
|
+
setError(NO_CLIENT_ID_MSG);
|
|
14763
14804
|
return;
|
|
14764
14805
|
}
|
|
14765
14806
|
setLoading(true);
|
|
14766
14807
|
setError(undefined);
|
|
14767
14808
|
setSuccess(undefined);
|
|
14768
14809
|
try {
|
|
14769
|
-
await smartlinks.authKit.updateProfile(
|
|
14810
|
+
await smartlinks.authKit.updateProfile(resolvedClientId, { displayName });
|
|
14770
14811
|
setSuccess('Profile updated successfully!');
|
|
14771
14812
|
setEditingSection(null);
|
|
14772
14813
|
if (profile) {
|
|
@@ -14805,8 +14846,8 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14805
14846
|
};
|
|
14806
14847
|
const handleChangeEmail = async (e) => {
|
|
14807
14848
|
e.preventDefault();
|
|
14808
|
-
if (!
|
|
14809
|
-
setError(
|
|
14849
|
+
if (!resolvedClientId) {
|
|
14850
|
+
setError(NO_CLIENT_ID_MSG);
|
|
14810
14851
|
return;
|
|
14811
14852
|
}
|
|
14812
14853
|
setLoading(true);
|
|
@@ -14814,7 +14855,7 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14814
14855
|
setSuccess(undefined);
|
|
14815
14856
|
try {
|
|
14816
14857
|
const redirectUrl = window.location.href;
|
|
14817
|
-
await smartlinks.authKit.changeEmail(
|
|
14858
|
+
await smartlinks.authKit.changeEmail(resolvedClientId, newEmail, emailPassword, redirectUrl);
|
|
14818
14859
|
setSuccess('Email change requested. Please check your new email for verification.');
|
|
14819
14860
|
setEditingSection(null);
|
|
14820
14861
|
setNewEmail('');
|
|
@@ -14830,8 +14871,8 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14830
14871
|
};
|
|
14831
14872
|
const handleChangePassword = async (e) => {
|
|
14832
14873
|
e.preventDefault();
|
|
14833
|
-
if (!
|
|
14834
|
-
setError(
|
|
14874
|
+
if (!resolvedClientId) {
|
|
14875
|
+
setError(NO_CLIENT_ID_MSG);
|
|
14835
14876
|
return;
|
|
14836
14877
|
}
|
|
14837
14878
|
if (newPassword !== confirmPassword) {
|
|
@@ -14846,7 +14887,7 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14846
14887
|
setError(undefined);
|
|
14847
14888
|
setSuccess(undefined);
|
|
14848
14889
|
try {
|
|
14849
|
-
await smartlinks.authKit.changePassword(
|
|
14890
|
+
await smartlinks.authKit.changePassword(resolvedClientId, currentPassword, newPassword);
|
|
14850
14891
|
setSuccess('Password changed successfully!');
|
|
14851
14892
|
setEditingSection(null);
|
|
14852
14893
|
setCurrentPassword('');
|
|
@@ -14862,14 +14903,14 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14862
14903
|
}
|
|
14863
14904
|
};
|
|
14864
14905
|
const handleSendPhoneCode = async () => {
|
|
14865
|
-
if (!
|
|
14866
|
-
setError(
|
|
14906
|
+
if (!resolvedClientId) {
|
|
14907
|
+
setError(NO_CLIENT_ID_MSG);
|
|
14867
14908
|
return;
|
|
14868
14909
|
}
|
|
14869
14910
|
setLoading(true);
|
|
14870
14911
|
setError(undefined);
|
|
14871
14912
|
try {
|
|
14872
|
-
await smartlinks.authKit.sendPhoneCode(
|
|
14913
|
+
await smartlinks.authKit.sendPhoneCode(resolvedClientId, newPhone);
|
|
14873
14914
|
setPhoneCodeSent(true);
|
|
14874
14915
|
setSuccess('Verification code sent to your phone');
|
|
14875
14916
|
}
|
|
@@ -14883,15 +14924,15 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14883
14924
|
};
|
|
14884
14925
|
const handleUpdatePhone = async (e) => {
|
|
14885
14926
|
e.preventDefault();
|
|
14886
|
-
if (!
|
|
14887
|
-
setError(
|
|
14927
|
+
if (!resolvedClientId) {
|
|
14928
|
+
setError(NO_CLIENT_ID_MSG);
|
|
14888
14929
|
return;
|
|
14889
14930
|
}
|
|
14890
14931
|
setLoading(true);
|
|
14891
14932
|
setError(undefined);
|
|
14892
14933
|
setSuccess(undefined);
|
|
14893
14934
|
try {
|
|
14894
|
-
await smartlinks.authKit.updatePhone(
|
|
14935
|
+
await smartlinks.authKit.updatePhone(resolvedClientId, newPhone, phoneCode);
|
|
14895
14936
|
setSuccess('Phone number updated successfully!');
|
|
14896
14937
|
setEditingSection(null);
|
|
14897
14938
|
setNewPhone('');
|
|
@@ -14908,8 +14949,8 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14908
14949
|
}
|
|
14909
14950
|
};
|
|
14910
14951
|
const handleDeleteAccount = async () => {
|
|
14911
|
-
if (!
|
|
14912
|
-
setError(
|
|
14952
|
+
if (!resolvedClientId) {
|
|
14953
|
+
setError(NO_CLIENT_ID_MSG);
|
|
14913
14954
|
return;
|
|
14914
14955
|
}
|
|
14915
14956
|
if (deleteConfirmText !== 'DELETE') {
|
|
@@ -14923,7 +14964,7 @@ const AccountManagement = ({ apiEndpoint, clientId, collectionId, onError, class
|
|
|
14923
14964
|
setLoading(true);
|
|
14924
14965
|
setError(undefined);
|
|
14925
14966
|
try {
|
|
14926
|
-
await smartlinks.authKit.deleteAccount(
|
|
14967
|
+
await smartlinks.authKit.deleteAccount(resolvedClientId, deletePassword, deleteConfirmText);
|
|
14927
14968
|
setSuccess('Account deleted successfully');
|
|
14928
14969
|
await auth.logout();
|
|
14929
14970
|
}
|