@proveanything/smartlinks-auth-ui 0.1.4 → 0.1.5
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/AccountManagement.d.ts.map +1 -1
- package/dist/components/ClaimUI.d.ts.map +1 -1
- package/dist/components/SmartlinksAuthUI.d.ts +4 -0
- package/dist/components/SmartlinksAuthUI.d.ts.map +1 -0
- package/dist/index.css +1 -1
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.css.map +1 -1
- package/dist/index.esm.js +930 -930
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +930 -930
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.esm.js
CHANGED
|
@@ -47,7 +47,7 @@ const AuthContainer = ({ children, theme = 'light', className = '', config, mini
|
|
|
47
47
|
// - null or empty string: hide logo completely
|
|
48
48
|
// - string URL: use custom logo
|
|
49
49
|
const logoUrl = config?.branding?.logoUrl === undefined
|
|
50
|
-
? '/smartlinks-
|
|
50
|
+
? 'https://smartlinks.app/smartlinks/landscape-medium.png' // Default Smartlinks logo
|
|
51
51
|
: config?.branding?.logoUrl || null; // Custom or explicitly hidden
|
|
52
52
|
const containerClass = minimal
|
|
53
53
|
? `auth-minimal auth-theme-${theme} ${className}`
|
|
@@ -11411,1092 +11411,1092 @@ const useAuth = () => {
|
|
|
11411
11411
|
return context;
|
|
11412
11412
|
};
|
|
11413
11413
|
|
|
11414
|
-
|
|
11415
|
-
|
|
11414
|
+
// Default Smartlinks Google OAuth Client ID (public - safe to expose)
|
|
11415
|
+
const DEFAULT_GOOGLE_CLIENT_ID = '696509063554-jdlbjl8vsjt7cr0vgkjkjf3ffnvi3a70.apps.googleusercontent.com';
|
|
11416
|
+
const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAuthSuccess, onAuthError, enabledProviders = ['email', 'google', 'phone'], initialMode = 'login', redirectUrl, theme = 'light', className, customization, skipConfigFetch = false, minimal = false, }) => {
|
|
11417
|
+
const [mode, setMode] = useState(initialMode);
|
|
11416
11418
|
const [loading, setLoading] = useState(false);
|
|
11417
|
-
const [profile, setProfile] = useState(null);
|
|
11418
11419
|
const [error, setError] = useState();
|
|
11419
|
-
const [
|
|
11420
|
-
|
|
11421
|
-
const [
|
|
11422
|
-
|
|
11423
|
-
const [
|
|
11424
|
-
|
|
11425
|
-
const [
|
|
11426
|
-
const [
|
|
11427
|
-
|
|
11428
|
-
const [
|
|
11429
|
-
const [
|
|
11430
|
-
const
|
|
11431
|
-
|
|
11432
|
-
|
|
11433
|
-
|
|
11434
|
-
const [phoneCodeSent, setPhoneCodeSent] = useState(false);
|
|
11435
|
-
// Account deletion state
|
|
11436
|
-
const [deletePassword, setDeletePassword] = useState('');
|
|
11437
|
-
const [deleteConfirmText, setDeleteConfirmText] = useState('');
|
|
11438
|
-
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
|
11439
|
-
const { showProfileSection = true, showEmailSection = true, showPasswordSection = true, showPhoneSection = true, showDeleteAccount = false, } = customization;
|
|
11440
|
-
// Reinitialize Smartlinks SDK when apiEndpoint changes
|
|
11420
|
+
const [resetSuccess, setResetSuccess] = useState(false);
|
|
11421
|
+
const [authSuccess, setAuthSuccess] = useState(false);
|
|
11422
|
+
const [successMessage, setSuccessMessage] = useState();
|
|
11423
|
+
const [showResendVerification, setShowResendVerification] = useState(false);
|
|
11424
|
+
const [resendEmail, setResendEmail] = useState();
|
|
11425
|
+
const [showRequestNewReset, setShowRequestNewReset] = useState(false);
|
|
11426
|
+
const [resetRequestEmail, setResetRequestEmail] = useState();
|
|
11427
|
+
const [resetToken, setResetToken] = useState(); // Store the reset token from URL
|
|
11428
|
+
const [config, setConfig] = useState(null);
|
|
11429
|
+
const [configLoading, setConfigLoading] = useState(!skipConfigFetch);
|
|
11430
|
+
const [showEmailForm, setShowEmailForm] = useState(false); // Track if email form should be shown when emailDisplayMode is 'button'
|
|
11431
|
+
const api = new AuthAPI(apiEndpoint, clientId, clientName);
|
|
11432
|
+
const auth = useAuth();
|
|
11433
|
+
// Reinitialize Smartlinks SDK when apiEndpoint changes (for test/dev scenarios)
|
|
11434
|
+
// IMPORTANT: Preserve bearer token during reinitialization
|
|
11441
11435
|
useEffect(() => {
|
|
11442
|
-
|
|
11443
|
-
|
|
11444
|
-
|
|
11445
|
-
|
|
11446
|
-
|
|
11447
|
-
|
|
11448
|
-
|
|
11449
|
-
|
|
11450
|
-
|
|
11436
|
+
const reinitializeWithToken = async () => {
|
|
11437
|
+
if (apiEndpoint) {
|
|
11438
|
+
// Get current token before reinitializing
|
|
11439
|
+
const currentToken = await auth.getToken();
|
|
11440
|
+
smartlinks.initializeApi({
|
|
11441
|
+
baseURL: apiEndpoint,
|
|
11442
|
+
proxyMode: false, // Direct API calls when custom endpoint is provided
|
|
11443
|
+
ngrokSkipBrowserWarning: true,
|
|
11444
|
+
});
|
|
11445
|
+
// Restore bearer token after reinitialization using auth.verifyToken
|
|
11446
|
+
if (currentToken) {
|
|
11447
|
+
smartlinks.auth.verifyToken(currentToken).catch(err => {
|
|
11448
|
+
console.warn('Failed to restore bearer token after reinit:', err);
|
|
11449
|
+
});
|
|
11450
|
+
}
|
|
11451
|
+
}
|
|
11452
|
+
};
|
|
11453
|
+
reinitializeWithToken();
|
|
11454
|
+
}, [apiEndpoint, auth]);
|
|
11455
|
+
// Get the effective redirect URL (use prop or default to current page)
|
|
11456
|
+
const getRedirectUrl = () => {
|
|
11457
|
+
if (redirectUrl)
|
|
11458
|
+
return redirectUrl;
|
|
11459
|
+
// Get the full current URL including hash routes
|
|
11460
|
+
// Remove any existing query parameters to avoid duplication
|
|
11461
|
+
const currentUrl = window.location.href.split('?')[0];
|
|
11462
|
+
return currentUrl;
|
|
11463
|
+
};
|
|
11464
|
+
// Fetch UI configuration
|
|
11451
11465
|
useEffect(() => {
|
|
11452
|
-
|
|
11453
|
-
|
|
11454
|
-
const loadProfile = async () => {
|
|
11455
|
-
if (!auth.isAuthenticated) {
|
|
11456
|
-
setError('You must be logged in to manage your account');
|
|
11466
|
+
if (skipConfigFetch) {
|
|
11467
|
+
setConfig(customization || {});
|
|
11457
11468
|
return;
|
|
11458
11469
|
}
|
|
11459
|
-
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11463
|
-
|
|
11464
|
-
|
|
11465
|
-
|
|
11466
|
-
|
|
11467
|
-
|
|
11468
|
-
|
|
11469
|
-
|
|
11470
|
-
|
|
11471
|
-
|
|
11472
|
-
|
|
11473
|
-
|
|
11474
|
-
|
|
11475
|
-
|
|
11476
|
-
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11485
|
-
|
|
11486
|
-
|
|
11487
|
-
|
|
11488
|
-
|
|
11489
|
-
|
|
11490
|
-
|
|
11491
|
-
|
|
11492
|
-
|
|
11493
|
-
|
|
11494
|
-
|
|
11495
|
-
|
|
11496
|
-
|
|
11497
|
-
|
|
11498
|
-
|
|
11499
|
-
|
|
11500
|
-
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
// setSuccess('Profile updated successfully!');
|
|
11507
|
-
// setEditingSection(null);
|
|
11508
|
-
// onProfileUpdated?.(updatedProfile);
|
|
11509
|
-
}
|
|
11510
|
-
catch (err) {
|
|
11511
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to update profile';
|
|
11512
|
-
setError(errorMessage);
|
|
11513
|
-
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11470
|
+
const fetchConfig = async () => {
|
|
11471
|
+
try {
|
|
11472
|
+
// Check localStorage cache first
|
|
11473
|
+
const cacheKey = `auth_ui_config_${clientId || 'default'}`;
|
|
11474
|
+
const cached = localStorage.getItem(cacheKey);
|
|
11475
|
+
if (cached) {
|
|
11476
|
+
const { config: cachedConfig, timestamp } = JSON.parse(cached);
|
|
11477
|
+
const age = Date.now() - timestamp;
|
|
11478
|
+
// Use cache if less than 1 hour old
|
|
11479
|
+
if (age < 3600000) {
|
|
11480
|
+
setConfig({ ...cachedConfig, ...customization });
|
|
11481
|
+
setConfigLoading(false);
|
|
11482
|
+
// Fetch in background to update cache
|
|
11483
|
+
api.fetchConfig().then(freshConfig => {
|
|
11484
|
+
localStorage.setItem(cacheKey, JSON.stringify({
|
|
11485
|
+
config: freshConfig,
|
|
11486
|
+
timestamp: Date.now()
|
|
11487
|
+
}));
|
|
11488
|
+
});
|
|
11489
|
+
return;
|
|
11490
|
+
}
|
|
11491
|
+
}
|
|
11492
|
+
// Fetch from API
|
|
11493
|
+
const fetchedConfig = await api.fetchConfig();
|
|
11494
|
+
// Merge with customization props (props take precedence)
|
|
11495
|
+
const mergedConfig = { ...fetchedConfig, ...customization };
|
|
11496
|
+
setConfig(mergedConfig);
|
|
11497
|
+
// Cache the fetched config
|
|
11498
|
+
localStorage.setItem(cacheKey, JSON.stringify({
|
|
11499
|
+
config: fetchedConfig,
|
|
11500
|
+
timestamp: Date.now()
|
|
11501
|
+
}));
|
|
11502
|
+
}
|
|
11503
|
+
catch (err) {
|
|
11504
|
+
console.error('Failed to fetch config:', err);
|
|
11505
|
+
setConfig(customization || {});
|
|
11506
|
+
}
|
|
11507
|
+
finally {
|
|
11508
|
+
setConfigLoading(false);
|
|
11509
|
+
}
|
|
11510
|
+
};
|
|
11511
|
+
fetchConfig();
|
|
11512
|
+
}, [apiEndpoint, clientId, customization, skipConfigFetch]);
|
|
11513
|
+
// Reset showEmailForm when mode changes away from login/register
|
|
11514
|
+
useEffect(() => {
|
|
11515
|
+
if (mode !== 'login' && mode !== 'register') {
|
|
11516
|
+
setShowEmailForm(false);
|
|
11514
11517
|
}
|
|
11515
|
-
|
|
11516
|
-
|
|
11518
|
+
}, [mode]);
|
|
11519
|
+
// Handle URL-based auth flows (email verification, password reset)
|
|
11520
|
+
useEffect(() => {
|
|
11521
|
+
// Helper to get URL parameters from either hash or search
|
|
11522
|
+
const getUrlParams = () => {
|
|
11523
|
+
// First check if there are params in the hash (for hash routing)
|
|
11524
|
+
const hash = window.location.hash;
|
|
11525
|
+
const hashQueryIndex = hash.indexOf('?');
|
|
11526
|
+
if (hashQueryIndex !== -1) {
|
|
11527
|
+
// Extract query string from hash (e.g., #/test?mode=verifyEmail&token=abc)
|
|
11528
|
+
const hashQuery = hash.substring(hashQueryIndex + 1);
|
|
11529
|
+
return new URLSearchParams(hashQuery);
|
|
11530
|
+
}
|
|
11531
|
+
// Fall back to regular search params (for non-hash routing)
|
|
11532
|
+
return new URLSearchParams(window.location.search);
|
|
11533
|
+
};
|
|
11534
|
+
const params = getUrlParams();
|
|
11535
|
+
const urlMode = params.get('mode');
|
|
11536
|
+
const token = params.get('token');
|
|
11537
|
+
console.log('URL params detected:', { urlMode, token, hash: window.location.hash, search: window.location.search });
|
|
11538
|
+
if (urlMode && token) {
|
|
11539
|
+
handleURLBasedAuth(urlMode, token);
|
|
11517
11540
|
}
|
|
11518
|
-
};
|
|
11519
|
-
const
|
|
11520
|
-
setEditingSection(null);
|
|
11521
|
-
setDisplayName(profile?.displayName || '');
|
|
11522
|
-
setNewEmail('');
|
|
11523
|
-
setEmailPassword('');
|
|
11524
|
-
setCurrentPassword('');
|
|
11525
|
-
setNewPassword('');
|
|
11526
|
-
setConfirmPassword('');
|
|
11527
|
-
setNewPhone('');
|
|
11528
|
-
setPhoneCode('');
|
|
11529
|
-
setPhoneCodeSent(false);
|
|
11530
|
-
setError(undefined);
|
|
11531
|
-
setSuccess(undefined);
|
|
11532
|
-
};
|
|
11533
|
-
const handleChangeEmail = async (e) => {
|
|
11534
|
-
e.preventDefault();
|
|
11541
|
+
}, []);
|
|
11542
|
+
const handleURLBasedAuth = async (urlMode, token) => {
|
|
11535
11543
|
setLoading(true);
|
|
11536
11544
|
setError(undefined);
|
|
11537
|
-
setSuccess(undefined);
|
|
11538
11545
|
try {
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11552
|
-
|
|
11553
|
-
|
|
11554
|
-
|
|
11555
|
-
|
|
11556
|
-
|
|
11557
|
-
|
|
11558
|
-
|
|
11559
|
-
|
|
11560
|
-
|
|
11561
|
-
|
|
11546
|
+
if (urlMode === 'verifyEmail') {
|
|
11547
|
+
console.log('Verifying email with token:', token);
|
|
11548
|
+
const response = await api.verifyEmailWithToken(token);
|
|
11549
|
+
// Get email verification mode from response or config
|
|
11550
|
+
const verificationMode = response.emailVerificationMode || config?.emailVerification?.mode || 'verify-then-auto-login';
|
|
11551
|
+
if ((verificationMode === 'verify-then-auto-login' || verificationMode === 'immediate') && response.token) {
|
|
11552
|
+
// Auto-login modes: Log the user in immediately if token is provided
|
|
11553
|
+
auth.login(response.token, response.user, response.accountData);
|
|
11554
|
+
setAuthSuccess(true);
|
|
11555
|
+
setSuccessMessage('Email verified successfully! You are now logged in.');
|
|
11556
|
+
onAuthSuccess(response.token, response.user, response.accountData);
|
|
11557
|
+
// Clear the URL parameters
|
|
11558
|
+
const cleanUrl = window.location.href.split('?')[0];
|
|
11559
|
+
window.history.replaceState({}, document.title, cleanUrl);
|
|
11560
|
+
// Redirect after a brief delay to show success message
|
|
11561
|
+
if (redirectUrl) {
|
|
11562
|
+
setTimeout(() => {
|
|
11563
|
+
window.location.href = redirectUrl;
|
|
11564
|
+
}, 2000);
|
|
11565
|
+
}
|
|
11566
|
+
}
|
|
11567
|
+
else {
|
|
11568
|
+
// verify-then-manual-login mode or no token: Show success but require manual login
|
|
11569
|
+
setAuthSuccess(true);
|
|
11570
|
+
setSuccessMessage('Email verified successfully! Please log in with your credentials.');
|
|
11571
|
+
// Clear the URL parameters
|
|
11572
|
+
const cleanUrl = window.location.href.split('?')[0];
|
|
11573
|
+
window.history.replaceState({}, document.title, cleanUrl);
|
|
11574
|
+
// Switch back to login mode after a delay
|
|
11575
|
+
setTimeout(() => {
|
|
11576
|
+
setAuthSuccess(false);
|
|
11577
|
+
setMode('login');
|
|
11578
|
+
}, 3000);
|
|
11579
|
+
}
|
|
11580
|
+
}
|
|
11581
|
+
else if (urlMode === 'resetPassword') {
|
|
11582
|
+
console.log('Verifying reset token:', token);
|
|
11583
|
+
// Verify token is valid, then show password reset form
|
|
11584
|
+
await api.verifyResetToken(token);
|
|
11585
|
+
setResetToken(token); // Store token for use in password reset
|
|
11586
|
+
setMode('reset-password');
|
|
11587
|
+
// Clear the URL parameters
|
|
11588
|
+
const cleanUrl = window.location.href.split('?')[0];
|
|
11589
|
+
window.history.replaceState({}, document.title, cleanUrl);
|
|
11590
|
+
}
|
|
11591
|
+
else if (urlMode === 'magicLink') {
|
|
11592
|
+
console.log('Verifying magic link token:', token);
|
|
11593
|
+
const response = await api.verifyMagicLink(token);
|
|
11594
|
+
// Auto-login with magic link if token is provided
|
|
11595
|
+
if (response.token) {
|
|
11596
|
+
auth.login(response.token, response.user, response.accountData);
|
|
11597
|
+
setAuthSuccess(true);
|
|
11598
|
+
setSuccessMessage('Magic link verified! You are now logged in.');
|
|
11599
|
+
onAuthSuccess(response.token, response.user, response.accountData);
|
|
11600
|
+
// Clear the URL parameters
|
|
11601
|
+
const cleanUrl = window.location.href.split('?')[0];
|
|
11602
|
+
window.history.replaceState({}, document.title, cleanUrl);
|
|
11603
|
+
// Redirect after a brief delay to show success message
|
|
11604
|
+
if (redirectUrl) {
|
|
11605
|
+
setTimeout(() => {
|
|
11606
|
+
window.location.href = redirectUrl;
|
|
11607
|
+
}, 2000);
|
|
11608
|
+
}
|
|
11609
|
+
}
|
|
11610
|
+
else {
|
|
11611
|
+
throw new Error('Authentication failed - no token received');
|
|
11612
|
+
}
|
|
11613
|
+
}
|
|
11562
11614
|
}
|
|
11563
|
-
|
|
11564
|
-
|
|
11565
|
-
|
|
11566
|
-
|
|
11567
|
-
|
|
11568
|
-
|
|
11615
|
+
catch (err) {
|
|
11616
|
+
console.error('URL-based auth error:', err);
|
|
11617
|
+
const errorMessage = err instanceof Error ? err.message : 'An error occurred';
|
|
11618
|
+
// If it's an email verification error (expired/invalid token), show resend option
|
|
11619
|
+
if (urlMode === 'verifyEmail') {
|
|
11620
|
+
setError(`${errorMessage} - Please enter your email below to receive a new verification link.`);
|
|
11621
|
+
setShowResendVerification(true);
|
|
11622
|
+
setMode('login'); // Show the login form UI
|
|
11623
|
+
// Clear the URL parameters
|
|
11624
|
+
const cleanUrl = window.location.href.split('?')[0];
|
|
11625
|
+
window.history.replaceState({}, document.title, cleanUrl);
|
|
11626
|
+
}
|
|
11627
|
+
else if (urlMode === 'resetPassword') {
|
|
11628
|
+
// If password reset token is invalid/expired, show request new reset link option
|
|
11629
|
+
setError(`${errorMessage} - Please enter your email below to receive a new password reset link.`);
|
|
11630
|
+
setShowRequestNewReset(true);
|
|
11631
|
+
setMode('login');
|
|
11632
|
+
// Clear the URL parameters
|
|
11633
|
+
const cleanUrl = window.location.href.split('?')[0];
|
|
11634
|
+
window.history.replaceState({}, document.title, cleanUrl);
|
|
11635
|
+
}
|
|
11636
|
+
else if (urlMode === 'magicLink') {
|
|
11637
|
+
// If magic link is invalid/expired
|
|
11638
|
+
setError(`${errorMessage} - Please request a new magic link below.`);
|
|
11639
|
+
setMode('magic-link');
|
|
11640
|
+
// Clear the URL parameters
|
|
11641
|
+
const cleanUrl = window.location.href.split('?')[0];
|
|
11642
|
+
window.history.replaceState({}, document.title, cleanUrl);
|
|
11643
|
+
}
|
|
11644
|
+
else {
|
|
11645
|
+
setError(errorMessage);
|
|
11646
|
+
}
|
|
11647
|
+
onAuthError?.(err instanceof Error ? err : new Error('An error occurred'));
|
|
11569
11648
|
}
|
|
11570
|
-
|
|
11571
|
-
|
|
11572
|
-
return;
|
|
11649
|
+
finally {
|
|
11650
|
+
setLoading(false);
|
|
11573
11651
|
}
|
|
11652
|
+
};
|
|
11653
|
+
const handleEmailAuth = async (data) => {
|
|
11574
11654
|
setLoading(true);
|
|
11575
11655
|
setError(undefined);
|
|
11576
|
-
|
|
11656
|
+
setAuthSuccess(false);
|
|
11577
11657
|
try {
|
|
11578
|
-
|
|
11579
|
-
|
|
11580
|
-
|
|
11581
|
-
|
|
11582
|
-
|
|
11583
|
-
|
|
11584
|
-
|
|
11585
|
-
//
|
|
11586
|
-
|
|
11587
|
-
|
|
11588
|
-
|
|
11589
|
-
|
|
11590
|
-
|
|
11591
|
-
|
|
11658
|
+
const response = mode === 'login'
|
|
11659
|
+
? await api.login(data.email, data.password)
|
|
11660
|
+
: await api.register({
|
|
11661
|
+
...data,
|
|
11662
|
+
accountData: mode === 'register' ? accountData : undefined,
|
|
11663
|
+
redirectUrl: getRedirectUrl(), // Include redirect URL for email verification
|
|
11664
|
+
});
|
|
11665
|
+
// Get email verification mode from response or config (default: verify-then-auto-login)
|
|
11666
|
+
const verificationMode = response.emailVerificationMode || config?.emailVerification?.mode || 'verify-then-auto-login';
|
|
11667
|
+
const gracePeriodHours = config?.emailVerification?.gracePeriodHours || 24;
|
|
11668
|
+
if (mode === 'register') {
|
|
11669
|
+
// Handle different verification modes
|
|
11670
|
+
if (verificationMode === 'immediate' && response.token) {
|
|
11671
|
+
// Immediate mode: Log in right away if token is provided
|
|
11672
|
+
auth.login(response.token, response.user, response.accountData);
|
|
11673
|
+
setAuthSuccess(true);
|
|
11674
|
+
const deadline = response.emailVerificationDeadline
|
|
11675
|
+
? new Date(response.emailVerificationDeadline).toLocaleString()
|
|
11676
|
+
: `${gracePeriodHours} hours`;
|
|
11677
|
+
setSuccessMessage(`Account created! You're logged in now. Please verify your email by ${deadline} to keep your account active.`);
|
|
11678
|
+
if (response.token) {
|
|
11679
|
+
onAuthSuccess(response.token, response.user, response.accountData);
|
|
11680
|
+
}
|
|
11681
|
+
if (redirectUrl) {
|
|
11682
|
+
setTimeout(() => {
|
|
11683
|
+
window.location.href = redirectUrl;
|
|
11684
|
+
}, 2000);
|
|
11685
|
+
}
|
|
11686
|
+
}
|
|
11687
|
+
else if (verificationMode === 'verify-then-auto-login') {
|
|
11688
|
+
// Verify-then-auto-login mode: Don't log in yet, but will auto-login after email verification
|
|
11689
|
+
setAuthSuccess(true);
|
|
11690
|
+
setSuccessMessage('Account created! Please check your email and click the verification link to complete your registration.');
|
|
11691
|
+
}
|
|
11692
|
+
else {
|
|
11693
|
+
// verify-then-manual-login mode: Traditional flow
|
|
11694
|
+
setAuthSuccess(true);
|
|
11695
|
+
setSuccessMessage('Account created successfully! Please check your email to verify your account, then log in.');
|
|
11696
|
+
}
|
|
11697
|
+
}
|
|
11698
|
+
else {
|
|
11699
|
+
// Login mode - always log in if token is provided
|
|
11700
|
+
if (response.token) {
|
|
11701
|
+
// Check for account lock or verification requirements
|
|
11702
|
+
if (response.accountLocked) {
|
|
11703
|
+
throw new Error('Your account has been locked due to unverified email. Please check your email or request a new verification link.');
|
|
11704
|
+
}
|
|
11705
|
+
if (response.requiresEmailVerification) {
|
|
11706
|
+
throw new Error('Please verify your email before logging in. Check your inbox for the verification link.');
|
|
11707
|
+
}
|
|
11708
|
+
auth.login(response.token, response.user, response.accountData);
|
|
11709
|
+
setAuthSuccess(true);
|
|
11710
|
+
setSuccessMessage('Login successful!');
|
|
11711
|
+
onAuthSuccess(response.token, response.user, response.accountData);
|
|
11712
|
+
if (redirectUrl) {
|
|
11713
|
+
setTimeout(() => {
|
|
11714
|
+
window.location.href = redirectUrl;
|
|
11715
|
+
}, 2000);
|
|
11716
|
+
}
|
|
11717
|
+
}
|
|
11718
|
+
else {
|
|
11719
|
+
throw new Error('Authentication failed - please verify your email before logging in.');
|
|
11720
|
+
}
|
|
11721
|
+
}
|
|
11592
11722
|
}
|
|
11593
11723
|
catch (err) {
|
|
11594
|
-
const errorMessage = err instanceof Error ? err.message : '
|
|
11595
|
-
|
|
11596
|
-
|
|
11724
|
+
const errorMessage = err instanceof Error ? err.message : 'Authentication failed';
|
|
11725
|
+
// Check if error is about email already registered
|
|
11726
|
+
if (mode === 'register' && errorMessage.toLowerCase().includes('already') && errorMessage.toLowerCase().includes('email')) {
|
|
11727
|
+
setShowResendVerification(true);
|
|
11728
|
+
setResendEmail(data.email);
|
|
11729
|
+
setError('This email is already registered. If you didn\'t receive the verification email, you can resend it below.');
|
|
11730
|
+
}
|
|
11731
|
+
else {
|
|
11732
|
+
setError(errorMessage);
|
|
11733
|
+
}
|
|
11734
|
+
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11597
11735
|
}
|
|
11598
11736
|
finally {
|
|
11599
11737
|
setLoading(false);
|
|
11600
11738
|
}
|
|
11601
11739
|
};
|
|
11602
|
-
const
|
|
11740
|
+
const handleResendVerification = async () => {
|
|
11741
|
+
if (!resendEmail)
|
|
11742
|
+
return;
|
|
11603
11743
|
setLoading(true);
|
|
11604
11744
|
setError(undefined);
|
|
11605
11745
|
try {
|
|
11606
|
-
|
|
11607
|
-
|
|
11608
|
-
|
|
11746
|
+
// For resend, we need the userId. If we don't have it, we need to handle this differently
|
|
11747
|
+
// The backend should ideally handle this case
|
|
11748
|
+
await api.resendVerification('unknown', resendEmail, getRedirectUrl());
|
|
11749
|
+
setAuthSuccess(true);
|
|
11750
|
+
setSuccessMessage('Verification email sent! Please check your inbox.');
|
|
11751
|
+
setShowResendVerification(false);
|
|
11609
11752
|
}
|
|
11610
11753
|
catch (err) {
|
|
11611
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to
|
|
11754
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to resend verification email';
|
|
11612
11755
|
setError(errorMessage);
|
|
11613
|
-
|
|
11756
|
+
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11614
11757
|
}
|
|
11615
11758
|
finally {
|
|
11616
11759
|
setLoading(false);
|
|
11617
11760
|
}
|
|
11618
11761
|
};
|
|
11619
|
-
const
|
|
11620
|
-
|
|
11762
|
+
const handleRequestNewReset = async () => {
|
|
11763
|
+
if (!resetRequestEmail)
|
|
11764
|
+
return;
|
|
11621
11765
|
setLoading(true);
|
|
11622
11766
|
setError(undefined);
|
|
11623
|
-
setSuccess(undefined);
|
|
11624
11767
|
try {
|
|
11625
|
-
|
|
11626
|
-
|
|
11627
|
-
|
|
11628
|
-
|
|
11629
|
-
|
|
11630
|
-
console.log('Data:', { phoneNumber: newPhone, code: phoneCode });
|
|
11631
|
-
// Uncomment when backend is ready:
|
|
11632
|
-
// await smartlinks.authKit.updatePhone(clientId, newPhone, phoneCode);
|
|
11633
|
-
// setSuccess('Phone number updated successfully!');
|
|
11634
|
-
// setEditingSection(null);
|
|
11635
|
-
// setNewPhone('');
|
|
11636
|
-
// setPhoneCode('');
|
|
11637
|
-
// setPhoneCodeSent(false);
|
|
11638
|
-
// await loadProfile();
|
|
11768
|
+
await api.requestPasswordReset(resetRequestEmail, getRedirectUrl());
|
|
11769
|
+
setAuthSuccess(true);
|
|
11770
|
+
setSuccessMessage('Password reset email sent! Please check your inbox.');
|
|
11771
|
+
setShowRequestNewReset(false);
|
|
11772
|
+
setResetRequestEmail('');
|
|
11639
11773
|
}
|
|
11640
11774
|
catch (err) {
|
|
11641
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to
|
|
11775
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to send password reset email';
|
|
11642
11776
|
setError(errorMessage);
|
|
11643
|
-
|
|
11777
|
+
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11644
11778
|
}
|
|
11645
11779
|
finally {
|
|
11646
11780
|
setLoading(false);
|
|
11647
11781
|
}
|
|
11648
11782
|
};
|
|
11649
|
-
const
|
|
11650
|
-
|
|
11651
|
-
|
|
11652
|
-
|
|
11783
|
+
const handleGoogleLogin = async () => {
|
|
11784
|
+
// Use custom client ID from config, or fall back to default Smartlinks client ID
|
|
11785
|
+
const googleClientId = config?.googleClientId || DEFAULT_GOOGLE_CLIENT_ID;
|
|
11786
|
+
// Determine OAuth flow: default to 'oneTap' for better UX, but allow 'popup' for iframe compatibility
|
|
11787
|
+
const oauthFlow = config?.googleOAuthFlow || 'oneTap';
|
|
11788
|
+
setLoading(true);
|
|
11789
|
+
setError(undefined);
|
|
11790
|
+
try {
|
|
11791
|
+
const google = window.google;
|
|
11792
|
+
if (!google) {
|
|
11793
|
+
throw new Error('Google Identity Services not loaded. Please check your internet connection.');
|
|
11794
|
+
}
|
|
11795
|
+
if (oauthFlow === 'popup') {
|
|
11796
|
+
// Use OAuth2 popup flow (works in iframes but requires popup permission)
|
|
11797
|
+
if (!google.accounts.oauth2) {
|
|
11798
|
+
throw new Error('Google OAuth2 not available');
|
|
11799
|
+
}
|
|
11800
|
+
const client = google.accounts.oauth2.initTokenClient({
|
|
11801
|
+
client_id: googleClientId,
|
|
11802
|
+
scope: 'openid email profile',
|
|
11803
|
+
callback: async (response) => {
|
|
11804
|
+
try {
|
|
11805
|
+
if (response.error) {
|
|
11806
|
+
throw new Error(response.error_description || response.error);
|
|
11807
|
+
}
|
|
11808
|
+
const accessToken = response.access_token;
|
|
11809
|
+
// Send access token to backend
|
|
11810
|
+
const authResponse = await api.loginWithGoogle(accessToken);
|
|
11811
|
+
if (authResponse.token) {
|
|
11812
|
+
auth.login(authResponse.token, authResponse.user, authResponse.accountData);
|
|
11813
|
+
setAuthSuccess(true);
|
|
11814
|
+
setSuccessMessage('Google login successful!');
|
|
11815
|
+
onAuthSuccess(authResponse.token, authResponse.user, authResponse.accountData);
|
|
11816
|
+
}
|
|
11817
|
+
else {
|
|
11818
|
+
throw new Error('Authentication failed - no token received');
|
|
11819
|
+
}
|
|
11820
|
+
if (redirectUrl) {
|
|
11821
|
+
setTimeout(() => {
|
|
11822
|
+
window.location.href = redirectUrl;
|
|
11823
|
+
}, 2000);
|
|
11824
|
+
}
|
|
11825
|
+
setLoading(false);
|
|
11826
|
+
}
|
|
11827
|
+
catch (err) {
|
|
11828
|
+
const errorMessage = err instanceof Error ? err.message : 'Google login failed';
|
|
11829
|
+
setError(errorMessage);
|
|
11830
|
+
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11831
|
+
setLoading(false);
|
|
11832
|
+
}
|
|
11833
|
+
},
|
|
11834
|
+
});
|
|
11835
|
+
client.requestAccessToken();
|
|
11836
|
+
}
|
|
11837
|
+
else {
|
|
11838
|
+
// Use One Tap / Sign-In button flow (smoother UX but doesn't work in iframes)
|
|
11839
|
+
google.accounts.id.initialize({
|
|
11840
|
+
client_id: googleClientId,
|
|
11841
|
+
callback: async (response) => {
|
|
11842
|
+
try {
|
|
11843
|
+
const idToken = response.credential;
|
|
11844
|
+
const authResponse = await api.loginWithGoogle(idToken);
|
|
11845
|
+
if (authResponse.token) {
|
|
11846
|
+
auth.login(authResponse.token, authResponse.user, authResponse.accountData);
|
|
11847
|
+
setAuthSuccess(true);
|
|
11848
|
+
setSuccessMessage('Google login successful!');
|
|
11849
|
+
onAuthSuccess(authResponse.token, authResponse.user, authResponse.accountData);
|
|
11850
|
+
}
|
|
11851
|
+
else {
|
|
11852
|
+
throw new Error('Authentication failed - no token received');
|
|
11853
|
+
}
|
|
11854
|
+
if (redirectUrl) {
|
|
11855
|
+
setTimeout(() => {
|
|
11856
|
+
window.location.href = redirectUrl;
|
|
11857
|
+
}, 2000);
|
|
11858
|
+
}
|
|
11859
|
+
setLoading(false);
|
|
11860
|
+
}
|
|
11861
|
+
catch (err) {
|
|
11862
|
+
const errorMessage = err instanceof Error ? err.message : 'Google login failed';
|
|
11863
|
+
setError(errorMessage);
|
|
11864
|
+
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11865
|
+
setLoading(false);
|
|
11866
|
+
}
|
|
11867
|
+
},
|
|
11868
|
+
auto_select: false,
|
|
11869
|
+
cancel_on_tap_outside: true,
|
|
11870
|
+
});
|
|
11871
|
+
google.accounts.id.prompt((notification) => {
|
|
11872
|
+
if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
|
|
11873
|
+
setLoading(false);
|
|
11874
|
+
}
|
|
11875
|
+
});
|
|
11876
|
+
}
|
|
11653
11877
|
}
|
|
11654
|
-
|
|
11655
|
-
|
|
11656
|
-
|
|
11878
|
+
catch (err) {
|
|
11879
|
+
const errorMessage = err instanceof Error ? err.message : 'Google login failed';
|
|
11880
|
+
setError(errorMessage);
|
|
11881
|
+
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11882
|
+
setLoading(false);
|
|
11657
11883
|
}
|
|
11884
|
+
};
|
|
11885
|
+
const handlePhoneAuth = async (phoneNumber, verificationCode) => {
|
|
11658
11886
|
setLoading(true);
|
|
11659
11887
|
setError(undefined);
|
|
11660
11888
|
try {
|
|
11661
|
-
|
|
11662
|
-
|
|
11663
|
-
|
|
11664
|
-
|
|
11665
|
-
|
|
11666
|
-
|
|
11667
|
-
|
|
11668
|
-
|
|
11669
|
-
|
|
11670
|
-
|
|
11671
|
-
|
|
11672
|
-
|
|
11673
|
-
|
|
11889
|
+
if (!verificationCode) {
|
|
11890
|
+
// Send verification code via Twilio Verify Service
|
|
11891
|
+
await api.sendPhoneCode(phoneNumber);
|
|
11892
|
+
// Twilio Verify Service tracks the verification by phone number
|
|
11893
|
+
// No need to store verificationId
|
|
11894
|
+
}
|
|
11895
|
+
else {
|
|
11896
|
+
// Verify code - Twilio identifies the verification by phone number
|
|
11897
|
+
const response = await api.verifyPhoneCode(phoneNumber, verificationCode);
|
|
11898
|
+
// Update auth context with account data if token is provided
|
|
11899
|
+
if (response.token) {
|
|
11900
|
+
auth.login(response.token, response.user, response.accountData);
|
|
11901
|
+
onAuthSuccess(response.token, response.user, response.accountData);
|
|
11902
|
+
if (redirectUrl) {
|
|
11903
|
+
window.location.href = redirectUrl;
|
|
11904
|
+
}
|
|
11905
|
+
}
|
|
11906
|
+
else {
|
|
11907
|
+
throw new Error('Authentication failed - no token received');
|
|
11908
|
+
}
|
|
11909
|
+
}
|
|
11674
11910
|
}
|
|
11675
11911
|
catch (err) {
|
|
11676
|
-
const errorMessage = err instanceof Error ? err.message : '
|
|
11912
|
+
const errorMessage = err instanceof Error ? err.message : 'Phone authentication failed';
|
|
11677
11913
|
setError(errorMessage);
|
|
11678
|
-
|
|
11914
|
+
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11679
11915
|
}
|
|
11680
11916
|
finally {
|
|
11681
11917
|
setLoading(false);
|
|
11682
11918
|
}
|
|
11683
11919
|
};
|
|
11684
|
-
|
|
11685
|
-
|
|
11686
|
-
|
|
11687
|
-
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
const [claimStep, setClaimStep] = useState(auth.isAuthenticated ? 'questions' : 'auth');
|
|
11700
|
-
const [claimData, setClaimData] = useState({});
|
|
11701
|
-
const [error, setError] = useState();
|
|
11702
|
-
const [loading, setLoading] = useState(false);
|
|
11703
|
-
const handleAuthSuccess = (token, user, accountData) => {
|
|
11704
|
-
// Authentication successful
|
|
11705
|
-
auth.login(token, user, accountData);
|
|
11706
|
-
// If no additional questions, proceed directly to claim
|
|
11707
|
-
if (additionalFields.length === 0) {
|
|
11708
|
-
executeClaim(user);
|
|
11709
|
-
}
|
|
11710
|
-
else {
|
|
11711
|
-
setClaimStep('questions');
|
|
11920
|
+
const handlePasswordReset = async (emailOrPassword, confirmPassword) => {
|
|
11921
|
+
setLoading(true);
|
|
11922
|
+
setError(undefined);
|
|
11923
|
+
try {
|
|
11924
|
+
if (resetToken && confirmPassword) {
|
|
11925
|
+
// Complete password reset with token
|
|
11926
|
+
await api.completePasswordReset(resetToken, emailOrPassword);
|
|
11927
|
+
setResetSuccess(true);
|
|
11928
|
+
setResetToken(undefined); // Clear token after successful reset
|
|
11929
|
+
}
|
|
11930
|
+
else {
|
|
11931
|
+
// Request password reset email
|
|
11932
|
+
await api.requestPasswordReset(emailOrPassword, getRedirectUrl());
|
|
11933
|
+
setResetSuccess(true);
|
|
11934
|
+
}
|
|
11712
11935
|
}
|
|
11713
|
-
|
|
11714
|
-
|
|
11715
|
-
|
|
11716
|
-
|
|
11717
|
-
const missingFields = additionalFields
|
|
11718
|
-
.filter(field => field.required && !claimData[field.name])
|
|
11719
|
-
.map(field => field.label);
|
|
11720
|
-
if (missingFields.length > 0) {
|
|
11721
|
-
setError(`Please fill in: ${missingFields.join(', ')}`);
|
|
11722
|
-
return;
|
|
11936
|
+
catch (err) {
|
|
11937
|
+
const errorMessage = err instanceof Error ? err.message : 'Password reset failed';
|
|
11938
|
+
setError(errorMessage);
|
|
11939
|
+
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11723
11940
|
}
|
|
11724
|
-
|
|
11725
|
-
|
|
11726
|
-
executeClaim(auth.user);
|
|
11941
|
+
finally {
|
|
11942
|
+
setLoading(false);
|
|
11727
11943
|
}
|
|
11728
11944
|
};
|
|
11729
|
-
const
|
|
11730
|
-
setClaimStep('claiming');
|
|
11945
|
+
const handleMagicLink = async (email) => {
|
|
11731
11946
|
setLoading(true);
|
|
11732
11947
|
setError(undefined);
|
|
11733
11948
|
try {
|
|
11734
|
-
|
|
11735
|
-
|
|
11736
|
-
|
|
11737
|
-
claimed: true,
|
|
11738
|
-
claimedAt: new Date().toISOString(),
|
|
11739
|
-
claimedBy: user.uid,
|
|
11740
|
-
...claimData,
|
|
11741
|
-
},
|
|
11742
|
-
private: {},
|
|
11743
|
-
proof: {},
|
|
11744
|
-
});
|
|
11745
|
-
setClaimStep('success');
|
|
11746
|
-
// Call success callback
|
|
11747
|
-
onClaimSuccess({
|
|
11748
|
-
proofId,
|
|
11749
|
-
user,
|
|
11750
|
-
claimData,
|
|
11751
|
-
attestationId: response.id,
|
|
11752
|
-
});
|
|
11949
|
+
await api.sendMagicLink(email, getRedirectUrl());
|
|
11950
|
+
setAuthSuccess(true);
|
|
11951
|
+
setSuccessMessage('Magic link sent! Check your email to log in.');
|
|
11753
11952
|
}
|
|
11754
11953
|
catch (err) {
|
|
11755
|
-
|
|
11756
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to claim proof';
|
|
11954
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to send magic link';
|
|
11757
11955
|
setError(errorMessage);
|
|
11758
|
-
|
|
11759
|
-
setClaimStep(additionalFields.length > 0 ? 'questions' : 'auth');
|
|
11956
|
+
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
11760
11957
|
}
|
|
11761
11958
|
finally {
|
|
11762
11959
|
setLoading(false);
|
|
11763
11960
|
}
|
|
11764
11961
|
};
|
|
11765
|
-
|
|
11766
|
-
|
|
11767
|
-
...prev,
|
|
11768
|
-
[fieldName]: value,
|
|
11769
|
-
}));
|
|
11770
|
-
};
|
|
11771
|
-
// Render authentication step
|
|
11772
|
-
if (claimStep === 'auth') {
|
|
11773
|
-
return (jsx("div", { className: className, children: jsx(SmartlinksAuthUI, { apiEndpoint: apiEndpoint, clientId: clientId, clientName: clientName, onAuthSuccess: handleAuthSuccess, onAuthError: onClaimError, theme: theme, minimal: minimal, customization: customization.authConfig }) }));
|
|
11774
|
-
}
|
|
11775
|
-
// Render additional questions step
|
|
11776
|
-
if (claimStep === 'questions') {
|
|
11777
|
-
return (jsxs("div", { className: `claim-questions ${className}`, children: [jsxs("div", { className: "claim-header mb-6", children: [jsx("h2", { className: "text-2xl font-bold mb-2", children: customization.claimTitle || 'Complete Your Claim' }), customization.claimDescription && (jsx("p", { className: "text-muted-foreground", children: customization.claimDescription }))] }), error && (jsx("div", { className: "claim-error bg-destructive/10 text-destructive px-4 py-3 rounded-md mb-4", children: error })), jsxs("form", { onSubmit: handleQuestionSubmit, className: "claim-form space-y-4", children: [additionalFields.map((field) => (jsxs("div", { className: "claim-field", children: [jsxs("label", { htmlFor: field.name, className: "block text-sm font-medium mb-2", children: [field.label, field.required && jsx("span", { className: "text-destructive ml-1", children: "*" })] }), field.type === 'textarea' ? (jsx("textarea", { id: field.name, name: field.name, placeholder: field.placeholder, value: claimData[field.name] || '', onChange: (e) => handleFieldChange(field.name, e.target.value), required: field.required, className: "w-full px-3 py-2 border border-input rounded-md bg-background", rows: 4 })) : field.type === 'select' ? (jsxs("select", { id: field.name, name: field.name, value: claimData[field.name] || '', onChange: (e) => handleFieldChange(field.name, e.target.value), required: field.required, className: "w-full px-3 py-2 border border-input rounded-md bg-background", children: [jsx("option", { value: "", children: "Select..." }), field.options?.map((option) => (jsx("option", { value: option, children: option }, option)))] })) : (jsx("input", { id: field.name, name: field.name, type: field.type, placeholder: field.placeholder, value: claimData[field.name] || '', onChange: (e) => handleFieldChange(field.name, e.target.value), required: field.required, className: "w-full px-3 py-2 border border-input rounded-md bg-background" }))] }, field.name))), jsx("button", { type: "submit", disabled: loading, className: "claim-submit-button w-full bg-primary text-primary-foreground px-4 py-2 rounded-md font-medium hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed", children: loading ? 'Claiming...' : 'Submit Claim' })] })] }));
|
|
11962
|
+
if (configLoading) {
|
|
11963
|
+
return (jsx(AuthContainer, { theme: theme, className: className, minimal: minimal || config?.branding?.minimal || false, children: jsx("div", { style: { textAlign: 'center', padding: '2rem' }, children: jsx("div", { className: "auth-spinner" }) }) }));
|
|
11778
11964
|
}
|
|
11779
|
-
|
|
11780
|
-
|
|
11781
|
-
|
|
11782
|
-
|
|
11783
|
-
|
|
11784
|
-
|
|
11785
|
-
|
|
11786
|
-
|
|
11787
|
-
|
|
11788
|
-
|
|
11789
|
-
|
|
11790
|
-
|
|
11791
|
-
|
|
11792
|
-
|
|
11793
|
-
|
|
11794
|
-
|
|
11795
|
-
|
|
11796
|
-
|
|
11797
|
-
|
|
11798
|
-
|
|
11799
|
-
|
|
11800
|
-
|
|
11801
|
-
|
|
11802
|
-
|
|
11803
|
-
|
|
11804
|
-
|
|
11805
|
-
|
|
11806
|
-
|
|
11807
|
-
|
|
11808
|
-
|
|
11809
|
-
|
|
11810
|
-
|
|
11811
|
-
|
|
11812
|
-
|
|
11813
|
-
|
|
11814
|
-
|
|
11815
|
-
|
|
11816
|
-
|
|
11817
|
-
|
|
11818
|
-
|
|
11819
|
-
|
|
11820
|
-
|
|
11821
|
-
|
|
11822
|
-
|
|
11823
|
-
|
|
11824
|
-
|
|
11825
|
-
|
|
11826
|
-
|
|
11827
|
-
|
|
11828
|
-
|
|
11829
|
-
|
|
11830
|
-
|
|
11831
|
-
|
|
11832
|
-
|
|
11833
|
-
|
|
11834
|
-
|
|
11835
|
-
|
|
11836
|
-
|
|
11965
|
+
return (jsx(AuthContainer, { theme: theme, className: className, config: config, minimal: minimal || config?.branding?.minimal || false, children: authSuccess ? (jsxs("div", { style: { textAlign: 'center', padding: '2rem' }, children: [jsx("div", { style: {
|
|
11966
|
+
color: 'var(--auth-primary-color, #4F46E5)',
|
|
11967
|
+
fontSize: '3rem',
|
|
11968
|
+
marginBottom: '1rem'
|
|
11969
|
+
}, children: "\u2713" }), jsx("h2", { style: {
|
|
11970
|
+
marginBottom: '0.5rem',
|
|
11971
|
+
fontSize: '1.5rem',
|
|
11972
|
+
fontWeight: 600
|
|
11973
|
+
}, children: successMessage?.includes('verified') ? 'Email Verified!' :
|
|
11974
|
+
successMessage?.includes('Magic link') ? 'Check Your Email!' :
|
|
11975
|
+
mode === 'register' ? 'Account Created!' : 'Login Successful!' }), jsx("p", { style: {
|
|
11976
|
+
color: '#6B7280',
|
|
11977
|
+
fontSize: '0.875rem'
|
|
11978
|
+
}, children: successMessage })] })) : mode === 'magic-link' ? (jsx(MagicLinkForm, { onSubmit: handleMagicLink, onCancel: () => setMode('login'), loading: loading, error: error })) : mode === 'phone' ? (jsx(PhoneAuthForm, { onSubmit: handlePhoneAuth, onBack: () => setMode('login'), loading: loading, error: error })) : mode === 'reset-password' ? (jsx(PasswordResetForm, { onSubmit: handlePasswordReset, onBack: () => {
|
|
11979
|
+
setMode('login');
|
|
11980
|
+
setResetSuccess(false);
|
|
11981
|
+
setResetToken(undefined); // Clear token when going back
|
|
11982
|
+
}, loading: loading, error: error, success: resetSuccess, token: resetToken })) : (mode === 'login' || mode === 'register') ? (jsx(Fragment, { children: showResendVerification ? (jsxs("div", { style: { marginTop: '1rem', padding: '1.5rem', backgroundColor: 'rgba(79, 70, 229, 0.05)', borderRadius: '0.5rem' }, children: [jsx("h3", { style: { marginBottom: '0.75rem', fontSize: '1rem', fontWeight: 600, color: 'var(--auth-text-color, #374151)' }, children: "Verification Link Expired" }), jsx("p", { style: { marginBottom: '1rem', fontSize: '0.875rem', color: 'var(--auth-text-color, #6B7280)', lineHeight: '1.5' }, children: "Your verification link has expired or is no longer valid. Please enter your email address below and we'll send you a new verification link." }), jsx("input", { type: "email", value: resendEmail || '', onChange: (e) => setResendEmail(e.target.value), placeholder: "your@email.com", style: {
|
|
11983
|
+
width: '100%',
|
|
11984
|
+
padding: '0.625rem',
|
|
11985
|
+
marginBottom: '1rem',
|
|
11986
|
+
border: '1px solid var(--auth-border-color, #D1D5DB)',
|
|
11987
|
+
borderRadius: '0.375rem',
|
|
11988
|
+
fontSize: '0.875rem',
|
|
11989
|
+
boxSizing: 'border-box'
|
|
11990
|
+
} }), jsxs("div", { style: { display: 'flex', gap: '0.75rem' }, children: [jsx("button", { onClick: handleResendVerification, disabled: loading || !resendEmail, style: {
|
|
11991
|
+
flex: 1,
|
|
11992
|
+
padding: '0.625rem 1rem',
|
|
11993
|
+
backgroundColor: 'var(--auth-primary-color, #4F46E5)',
|
|
11994
|
+
color: 'white',
|
|
11995
|
+
border: 'none',
|
|
11996
|
+
borderRadius: '0.375rem',
|
|
11997
|
+
cursor: (loading || !resendEmail) ? 'not-allowed' : 'pointer',
|
|
11998
|
+
fontSize: '0.875rem',
|
|
11999
|
+
fontWeight: 500,
|
|
12000
|
+
opacity: (loading || !resendEmail) ? 0.6 : 1
|
|
12001
|
+
}, children: loading ? 'Sending...' : 'Send New Verification Link' }), jsx("button", { onClick: () => {
|
|
12002
|
+
setShowResendVerification(false);
|
|
12003
|
+
setResendEmail('');
|
|
12004
|
+
setError(undefined);
|
|
12005
|
+
}, disabled: loading, style: {
|
|
12006
|
+
padding: '0.625rem 1rem',
|
|
12007
|
+
backgroundColor: 'transparent',
|
|
12008
|
+
color: 'var(--auth-text-color, #6B7280)',
|
|
12009
|
+
border: '1px solid var(--auth-border-color, #D1D5DB)',
|
|
12010
|
+
borderRadius: '0.375rem',
|
|
12011
|
+
cursor: loading ? 'not-allowed' : 'pointer',
|
|
12012
|
+
fontSize: '0.875rem',
|
|
12013
|
+
fontWeight: 500,
|
|
12014
|
+
opacity: loading ? 0.6 : 1
|
|
12015
|
+
}, children: "Cancel" })] })] })) : showRequestNewReset ? (jsxs("div", { style: { marginTop: '1rem', padding: '1.5rem', backgroundColor: 'rgba(239, 68, 68, 0.05)', borderRadius: '0.5rem' }, children: [jsx("h3", { style: { marginBottom: '0.75rem', fontSize: '1rem', fontWeight: 600, color: 'var(--auth-text-color, #374151)' }, children: "Password Reset Link Expired" }), jsx("p", { style: { marginBottom: '1rem', fontSize: '0.875rem', color: 'var(--auth-text-color, #6B7280)', lineHeight: '1.5' }, children: "Your password reset link has expired or is no longer valid. Please enter your email address below and we'll send you a new password reset link." }), jsx("input", { type: "email", value: resetRequestEmail || '', onChange: (e) => setResetRequestEmail(e.target.value), placeholder: "your@email.com", style: {
|
|
12016
|
+
width: '100%',
|
|
12017
|
+
padding: '0.625rem',
|
|
12018
|
+
marginBottom: '1rem',
|
|
12019
|
+
border: '1px solid var(--auth-border-color, #D1D5DB)',
|
|
12020
|
+
borderRadius: '0.375rem',
|
|
12021
|
+
fontSize: '0.875rem',
|
|
12022
|
+
boxSizing: 'border-box'
|
|
12023
|
+
} }), jsxs("div", { style: { display: 'flex', gap: '0.75rem' }, children: [jsx("button", { onClick: handleRequestNewReset, disabled: loading || !resetRequestEmail, style: {
|
|
12024
|
+
flex: 1,
|
|
12025
|
+
padding: '0.625rem 1rem',
|
|
12026
|
+
backgroundColor: '#EF4444',
|
|
12027
|
+
color: 'white',
|
|
12028
|
+
border: 'none',
|
|
12029
|
+
borderRadius: '0.375rem',
|
|
12030
|
+
cursor: (loading || !resetRequestEmail) ? 'not-allowed' : 'pointer',
|
|
12031
|
+
fontSize: '0.875rem',
|
|
12032
|
+
fontWeight: 500,
|
|
12033
|
+
opacity: (loading || !resetRequestEmail) ? 0.6 : 1
|
|
12034
|
+
}, children: loading ? 'Sending...' : 'Send New Reset Link' }), jsx("button", { onClick: () => {
|
|
12035
|
+
setShowRequestNewReset(false);
|
|
12036
|
+
setResetRequestEmail('');
|
|
12037
|
+
setError(undefined);
|
|
12038
|
+
}, disabled: loading, style: {
|
|
12039
|
+
padding: '0.625rem 1rem',
|
|
12040
|
+
backgroundColor: 'transparent',
|
|
12041
|
+
color: 'var(--auth-text-color, #6B7280)',
|
|
12042
|
+
border: '1px solid var(--auth-border-color, #D1D5DB)',
|
|
12043
|
+
borderRadius: '0.375rem',
|
|
12044
|
+
cursor: loading ? 'not-allowed' : 'pointer',
|
|
12045
|
+
fontSize: '0.875rem',
|
|
12046
|
+
fontWeight: 500,
|
|
12047
|
+
opacity: loading ? 0.6 : 1
|
|
12048
|
+
}, children: "Cancel" })] })] })) : (jsx(Fragment, { children: (() => {
|
|
12049
|
+
const emailDisplayMode = config?.emailDisplayMode || 'form';
|
|
12050
|
+
const providerOrder = config?.providerOrder || (config?.enabledProviders || enabledProviders);
|
|
12051
|
+
const actualProviders = config?.enabledProviders || enabledProviders;
|
|
12052
|
+
// Button mode: show provider selection first, then email form if email is selected
|
|
12053
|
+
if (emailDisplayMode === 'button' && !showEmailForm) {
|
|
12054
|
+
return (jsx(ProviderButtons, { enabledProviders: actualProviders, providerOrder: providerOrder, onEmailLogin: () => setShowEmailForm(true), onGoogleLogin: handleGoogleLogin, onPhoneLogin: () => setMode('phone'), onMagicLinkLogin: () => setMode('magic-link'), loading: loading }));
|
|
12055
|
+
}
|
|
12056
|
+
// Form mode or email button was clicked: show email form with other providers
|
|
12057
|
+
return (jsxs(Fragment, { children: [emailDisplayMode === 'button' && showEmailForm && (jsx("button", { onClick: () => setShowEmailForm(false), style: {
|
|
12058
|
+
marginBottom: '1rem',
|
|
12059
|
+
padding: '0.5rem',
|
|
12060
|
+
background: 'none',
|
|
12061
|
+
border: 'none',
|
|
12062
|
+
color: 'var(--auth-text-color, #6B7280)',
|
|
12063
|
+
cursor: 'pointer',
|
|
12064
|
+
fontSize: '0.875rem',
|
|
12065
|
+
display: 'flex',
|
|
12066
|
+
alignItems: 'center',
|
|
12067
|
+
gap: '0.25rem'
|
|
12068
|
+
}, children: "\u2190 Back to options" })), jsx(EmailAuthForm, { mode: mode, onSubmit: handleEmailAuth, onModeSwitch: () => {
|
|
12069
|
+
setMode(mode === 'login' ? 'register' : 'login');
|
|
12070
|
+
setShowResendVerification(false);
|
|
12071
|
+
setShowRequestNewReset(false);
|
|
12072
|
+
setError(undefined);
|
|
12073
|
+
}, onForgotPassword: () => setMode('reset-password'), loading: loading, error: error, additionalFields: config?.signupAdditionalFields }), emailDisplayMode === 'form' && actualProviders.length > 1 && (jsx(ProviderButtons, { enabledProviders: actualProviders.filter((p) => p !== 'email'), providerOrder: providerOrder, onGoogleLogin: handleGoogleLogin, onPhoneLogin: () => setMode('phone'), onMagicLinkLogin: () => setMode('magic-link'), loading: loading }))] }));
|
|
12074
|
+
})() })) })) : null }));
|
|
11837
12075
|
};
|
|
11838
12076
|
|
|
11839
|
-
|
|
11840
|
-
const
|
|
11841
|
-
const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAuthSuccess, onAuthError, enabledProviders = ['email', 'google', 'phone'], initialMode = 'login', redirectUrl, theme = 'light', className, customization, skipConfigFetch = false, minimal = false, }) => {
|
|
11842
|
-
const [mode, setMode] = useState(initialMode);
|
|
12077
|
+
const AccountManagement = ({ apiEndpoint, clientId, onError, className = '', customization = {}, }) => {
|
|
12078
|
+
const auth = useAuth();
|
|
11843
12079
|
const [loading, setLoading] = useState(false);
|
|
12080
|
+
const [profile, setProfile] = useState(null);
|
|
11844
12081
|
const [error, setError] = useState();
|
|
11845
|
-
const [
|
|
11846
|
-
|
|
11847
|
-
const [
|
|
11848
|
-
|
|
11849
|
-
const [
|
|
11850
|
-
|
|
11851
|
-
const [
|
|
11852
|
-
const [
|
|
11853
|
-
|
|
11854
|
-
const [
|
|
11855
|
-
const [
|
|
11856
|
-
const
|
|
11857
|
-
|
|
11858
|
-
|
|
11859
|
-
|
|
11860
|
-
|
|
11861
|
-
|
|
11862
|
-
|
|
11863
|
-
|
|
11864
|
-
|
|
11865
|
-
|
|
11866
|
-
|
|
11867
|
-
proxyMode: false, // Direct API calls when custom endpoint is provided
|
|
11868
|
-
ngrokSkipBrowserWarning: true,
|
|
11869
|
-
});
|
|
11870
|
-
// Restore bearer token after reinitialization using auth.verifyToken
|
|
11871
|
-
if (currentToken) {
|
|
11872
|
-
smartlinks.auth.verifyToken(currentToken).catch(err => {
|
|
11873
|
-
console.warn('Failed to restore bearer token after reinit:', err);
|
|
11874
|
-
});
|
|
11875
|
-
}
|
|
11876
|
-
}
|
|
11877
|
-
};
|
|
11878
|
-
reinitializeWithToken();
|
|
11879
|
-
}, [apiEndpoint, auth]);
|
|
11880
|
-
// Get the effective redirect URL (use prop or default to current page)
|
|
11881
|
-
const getRedirectUrl = () => {
|
|
11882
|
-
if (redirectUrl)
|
|
11883
|
-
return redirectUrl;
|
|
11884
|
-
// Get the full current URL including hash routes
|
|
11885
|
-
// Remove any existing query parameters to avoid duplication
|
|
11886
|
-
const currentUrl = window.location.href.split('?')[0];
|
|
11887
|
-
return currentUrl;
|
|
11888
|
-
};
|
|
11889
|
-
// Fetch UI configuration
|
|
11890
|
-
useEffect(() => {
|
|
11891
|
-
if (skipConfigFetch) {
|
|
11892
|
-
setConfig(customization || {});
|
|
11893
|
-
return;
|
|
11894
|
-
}
|
|
11895
|
-
const fetchConfig = async () => {
|
|
11896
|
-
try {
|
|
11897
|
-
// Check localStorage cache first
|
|
11898
|
-
const cacheKey = `auth_ui_config_${clientId || 'default'}`;
|
|
11899
|
-
const cached = localStorage.getItem(cacheKey);
|
|
11900
|
-
if (cached) {
|
|
11901
|
-
const { config: cachedConfig, timestamp } = JSON.parse(cached);
|
|
11902
|
-
const age = Date.now() - timestamp;
|
|
11903
|
-
// Use cache if less than 1 hour old
|
|
11904
|
-
if (age < 3600000) {
|
|
11905
|
-
setConfig({ ...cachedConfig, ...customization });
|
|
11906
|
-
setConfigLoading(false);
|
|
11907
|
-
// Fetch in background to update cache
|
|
11908
|
-
api.fetchConfig().then(freshConfig => {
|
|
11909
|
-
localStorage.setItem(cacheKey, JSON.stringify({
|
|
11910
|
-
config: freshConfig,
|
|
11911
|
-
timestamp: Date.now()
|
|
11912
|
-
}));
|
|
11913
|
-
});
|
|
11914
|
-
return;
|
|
11915
|
-
}
|
|
11916
|
-
}
|
|
11917
|
-
// Fetch from API
|
|
11918
|
-
const fetchedConfig = await api.fetchConfig();
|
|
11919
|
-
// Merge with customization props (props take precedence)
|
|
11920
|
-
const mergedConfig = { ...fetchedConfig, ...customization };
|
|
11921
|
-
setConfig(mergedConfig);
|
|
11922
|
-
// Cache the fetched config
|
|
11923
|
-
localStorage.setItem(cacheKey, JSON.stringify({
|
|
11924
|
-
config: fetchedConfig,
|
|
11925
|
-
timestamp: Date.now()
|
|
11926
|
-
}));
|
|
11927
|
-
}
|
|
11928
|
-
catch (err) {
|
|
11929
|
-
console.error('Failed to fetch config:', err);
|
|
11930
|
-
setConfig(customization || {});
|
|
11931
|
-
}
|
|
11932
|
-
finally {
|
|
11933
|
-
setConfigLoading(false);
|
|
11934
|
-
}
|
|
11935
|
-
};
|
|
11936
|
-
fetchConfig();
|
|
11937
|
-
}, [apiEndpoint, clientId, customization, skipConfigFetch]);
|
|
11938
|
-
// Reset showEmailForm when mode changes away from login/register
|
|
12082
|
+
const [success, setSuccess] = useState();
|
|
12083
|
+
// Track which section is being edited
|
|
12084
|
+
const [editingSection, setEditingSection] = useState(null);
|
|
12085
|
+
// Profile form state
|
|
12086
|
+
const [displayName, setDisplayName] = useState('');
|
|
12087
|
+
// Email change state
|
|
12088
|
+
const [newEmail, setNewEmail] = useState('');
|
|
12089
|
+
const [emailPassword, setEmailPassword] = useState('');
|
|
12090
|
+
// Password change state
|
|
12091
|
+
const [currentPassword, setCurrentPassword] = useState('');
|
|
12092
|
+
const [newPassword, setNewPassword] = useState('');
|
|
12093
|
+
const [confirmPassword, setConfirmPassword] = useState('');
|
|
12094
|
+
// Phone change state (reuses existing sendPhoneCode flow)
|
|
12095
|
+
const [newPhone, setNewPhone] = useState('');
|
|
12096
|
+
const [phoneCode, setPhoneCode] = useState('');
|
|
12097
|
+
const [phoneCodeSent, setPhoneCodeSent] = useState(false);
|
|
12098
|
+
// Account deletion state
|
|
12099
|
+
const [deletePassword, setDeletePassword] = useState('');
|
|
12100
|
+
const [deleteConfirmText, setDeleteConfirmText] = useState('');
|
|
12101
|
+
const [showDeleteConfirm, setShowDeleteConfirm] = useState(false);
|
|
12102
|
+
const { showProfileSection = true, showEmailSection = true, showPasswordSection = true, showPhoneSection = true, showDeleteAccount = false, } = customization;
|
|
12103
|
+
// Reinitialize Smartlinks SDK when apiEndpoint changes
|
|
11939
12104
|
useEffect(() => {
|
|
11940
|
-
if (
|
|
11941
|
-
|
|
12105
|
+
if (apiEndpoint) {
|
|
12106
|
+
smartlinks.initializeApi({
|
|
12107
|
+
baseURL: apiEndpoint,
|
|
12108
|
+
proxyMode: false,
|
|
12109
|
+
ngrokSkipBrowserWarning: true,
|
|
12110
|
+
});
|
|
11942
12111
|
}
|
|
11943
|
-
}, [
|
|
11944
|
-
//
|
|
12112
|
+
}, [apiEndpoint]);
|
|
12113
|
+
// Load user profile on mount
|
|
11945
12114
|
useEffect(() => {
|
|
11946
|
-
|
|
11947
|
-
|
|
11948
|
-
|
|
11949
|
-
|
|
11950
|
-
|
|
11951
|
-
|
|
11952
|
-
// Extract query string from hash (e.g., #/test?mode=verifyEmail&token=abc)
|
|
11953
|
-
const hashQuery = hash.substring(hashQueryIndex + 1);
|
|
11954
|
-
return new URLSearchParams(hashQuery);
|
|
11955
|
-
}
|
|
11956
|
-
// Fall back to regular search params (for non-hash routing)
|
|
11957
|
-
return new URLSearchParams(window.location.search);
|
|
11958
|
-
};
|
|
11959
|
-
const params = getUrlParams();
|
|
11960
|
-
const urlMode = params.get('mode');
|
|
11961
|
-
const token = params.get('token');
|
|
11962
|
-
console.log('URL params detected:', { urlMode, token, hash: window.location.hash, search: window.location.search });
|
|
11963
|
-
if (urlMode && token) {
|
|
11964
|
-
handleURLBasedAuth(urlMode, token);
|
|
12115
|
+
loadProfile();
|
|
12116
|
+
}, [clientId]);
|
|
12117
|
+
const loadProfile = async () => {
|
|
12118
|
+
if (!auth.isAuthenticated) {
|
|
12119
|
+
setError('You must be logged in to manage your account');
|
|
12120
|
+
return;
|
|
11965
12121
|
}
|
|
11966
|
-
}, []);
|
|
11967
|
-
const handleURLBasedAuth = async (urlMode, token) => {
|
|
11968
12122
|
setLoading(true);
|
|
11969
12123
|
setError(undefined);
|
|
11970
12124
|
try {
|
|
11971
|
-
|
|
11972
|
-
|
|
11973
|
-
|
|
11974
|
-
|
|
11975
|
-
|
|
11976
|
-
|
|
11977
|
-
|
|
11978
|
-
|
|
11979
|
-
|
|
11980
|
-
|
|
11981
|
-
|
|
11982
|
-
|
|
11983
|
-
|
|
11984
|
-
|
|
11985
|
-
|
|
11986
|
-
if (redirectUrl) {
|
|
11987
|
-
setTimeout(() => {
|
|
11988
|
-
window.location.href = redirectUrl;
|
|
11989
|
-
}, 2000);
|
|
11990
|
-
}
|
|
11991
|
-
}
|
|
11992
|
-
else {
|
|
11993
|
-
// verify-then-manual-login mode or no token: Show success but require manual login
|
|
11994
|
-
setAuthSuccess(true);
|
|
11995
|
-
setSuccessMessage('Email verified successfully! Please log in with your credentials.');
|
|
11996
|
-
// Clear the URL parameters
|
|
11997
|
-
const cleanUrl = window.location.href.split('?')[0];
|
|
11998
|
-
window.history.replaceState({}, document.title, cleanUrl);
|
|
11999
|
-
// Switch back to login mode after a delay
|
|
12000
|
-
setTimeout(() => {
|
|
12001
|
-
setAuthSuccess(false);
|
|
12002
|
-
setMode('login');
|
|
12003
|
-
}, 3000);
|
|
12004
|
-
}
|
|
12005
|
-
}
|
|
12006
|
-
else if (urlMode === 'resetPassword') {
|
|
12007
|
-
console.log('Verifying reset token:', token);
|
|
12008
|
-
// Verify token is valid, then show password reset form
|
|
12009
|
-
await api.verifyResetToken(token);
|
|
12010
|
-
setResetToken(token); // Store token for use in password reset
|
|
12011
|
-
setMode('reset-password');
|
|
12012
|
-
// Clear the URL parameters
|
|
12013
|
-
const cleanUrl = window.location.href.split('?')[0];
|
|
12014
|
-
window.history.replaceState({}, document.title, cleanUrl);
|
|
12015
|
-
}
|
|
12016
|
-
else if (urlMode === 'magicLink') {
|
|
12017
|
-
console.log('Verifying magic link token:', token);
|
|
12018
|
-
const response = await api.verifyMagicLink(token);
|
|
12019
|
-
// Auto-login with magic link if token is provided
|
|
12020
|
-
if (response.token) {
|
|
12021
|
-
auth.login(response.token, response.user, response.accountData);
|
|
12022
|
-
setAuthSuccess(true);
|
|
12023
|
-
setSuccessMessage('Magic link verified! You are now logged in.');
|
|
12024
|
-
onAuthSuccess(response.token, response.user, response.accountData);
|
|
12025
|
-
// Clear the URL parameters
|
|
12026
|
-
const cleanUrl = window.location.href.split('?')[0];
|
|
12027
|
-
window.history.replaceState({}, document.title, cleanUrl);
|
|
12028
|
-
// Redirect after a brief delay to show success message
|
|
12029
|
-
if (redirectUrl) {
|
|
12030
|
-
setTimeout(() => {
|
|
12031
|
-
window.location.href = redirectUrl;
|
|
12032
|
-
}, 2000);
|
|
12033
|
-
}
|
|
12034
|
-
}
|
|
12035
|
-
else {
|
|
12036
|
-
throw new Error('Authentication failed - no token received');
|
|
12037
|
-
}
|
|
12038
|
-
}
|
|
12125
|
+
// TODO: Backend implementation required
|
|
12126
|
+
// Endpoint: GET /api/v1/authkit/:clientId/account/profile
|
|
12127
|
+
// SDK method: smartlinks.authKit.getProfile(clientId)
|
|
12128
|
+
// Temporary mock data for UI testing
|
|
12129
|
+
const profileData = {
|
|
12130
|
+
uid: auth.user?.uid || '',
|
|
12131
|
+
email: auth.user?.email,
|
|
12132
|
+
displayName: auth.user?.displayName,
|
|
12133
|
+
phoneNumber: auth.user?.phoneNumber,
|
|
12134
|
+
photoURL: auth.user?.photoURL,
|
|
12135
|
+
emailVerified: true,
|
|
12136
|
+
accountData: auth.accountData || {},
|
|
12137
|
+
};
|
|
12138
|
+
setProfile(profileData);
|
|
12139
|
+
setDisplayName(profileData.displayName || '');
|
|
12039
12140
|
}
|
|
12040
12141
|
catch (err) {
|
|
12041
|
-
|
|
12042
|
-
|
|
12043
|
-
|
|
12044
|
-
if (urlMode === 'verifyEmail') {
|
|
12045
|
-
setError(`${errorMessage} - Please enter your email below to receive a new verification link.`);
|
|
12046
|
-
setShowResendVerification(true);
|
|
12047
|
-
setMode('login'); // Show the login form UI
|
|
12048
|
-
// Clear the URL parameters
|
|
12049
|
-
const cleanUrl = window.location.href.split('?')[0];
|
|
12050
|
-
window.history.replaceState({}, document.title, cleanUrl);
|
|
12051
|
-
}
|
|
12052
|
-
else if (urlMode === 'resetPassword') {
|
|
12053
|
-
// If password reset token is invalid/expired, show request new reset link option
|
|
12054
|
-
setError(`${errorMessage} - Please enter your email below to receive a new password reset link.`);
|
|
12055
|
-
setShowRequestNewReset(true);
|
|
12056
|
-
setMode('login');
|
|
12057
|
-
// Clear the URL parameters
|
|
12058
|
-
const cleanUrl = window.location.href.split('?')[0];
|
|
12059
|
-
window.history.replaceState({}, document.title, cleanUrl);
|
|
12060
|
-
}
|
|
12061
|
-
else if (urlMode === 'magicLink') {
|
|
12062
|
-
// If magic link is invalid/expired
|
|
12063
|
-
setError(`${errorMessage} - Please request a new magic link below.`);
|
|
12064
|
-
setMode('magic-link');
|
|
12065
|
-
// Clear the URL parameters
|
|
12066
|
-
const cleanUrl = window.location.href.split('?')[0];
|
|
12067
|
-
window.history.replaceState({}, document.title, cleanUrl);
|
|
12068
|
-
}
|
|
12069
|
-
else {
|
|
12070
|
-
setError(errorMessage);
|
|
12071
|
-
}
|
|
12072
|
-
onAuthError?.(err instanceof Error ? err : new Error('An error occurred'));
|
|
12142
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to load profile';
|
|
12143
|
+
setError(errorMessage);
|
|
12144
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12073
12145
|
}
|
|
12074
12146
|
finally {
|
|
12075
12147
|
setLoading(false);
|
|
12076
12148
|
}
|
|
12077
12149
|
};
|
|
12078
|
-
const
|
|
12150
|
+
const handleUpdateProfile = async (e) => {
|
|
12151
|
+
e.preventDefault();
|
|
12079
12152
|
setLoading(true);
|
|
12080
12153
|
setError(undefined);
|
|
12081
|
-
|
|
12154
|
+
setSuccess(undefined);
|
|
12082
12155
|
try {
|
|
12083
|
-
|
|
12084
|
-
|
|
12085
|
-
|
|
12086
|
-
|
|
12087
|
-
|
|
12088
|
-
|
|
12089
|
-
|
|
12090
|
-
//
|
|
12091
|
-
|
|
12092
|
-
|
|
12093
|
-
|
|
12094
|
-
|
|
12095
|
-
|
|
12096
|
-
|
|
12097
|
-
|
|
12098
|
-
|
|
12099
|
-
const deadline = response.emailVerificationDeadline
|
|
12100
|
-
? new Date(response.emailVerificationDeadline).toLocaleString()
|
|
12101
|
-
: `${gracePeriodHours} hours`;
|
|
12102
|
-
setSuccessMessage(`Account created! You're logged in now. Please verify your email by ${deadline} to keep your account active.`);
|
|
12103
|
-
if (response.token) {
|
|
12104
|
-
onAuthSuccess(response.token, response.user, response.accountData);
|
|
12105
|
-
}
|
|
12106
|
-
if (redirectUrl) {
|
|
12107
|
-
setTimeout(() => {
|
|
12108
|
-
window.location.href = redirectUrl;
|
|
12109
|
-
}, 2000);
|
|
12110
|
-
}
|
|
12111
|
-
}
|
|
12112
|
-
else if (verificationMode === 'verify-then-auto-login') {
|
|
12113
|
-
// Verify-then-auto-login mode: Don't log in yet, but will auto-login after email verification
|
|
12114
|
-
setAuthSuccess(true);
|
|
12115
|
-
setSuccessMessage('Account created! Please check your email and click the verification link to complete your registration.');
|
|
12116
|
-
}
|
|
12117
|
-
else {
|
|
12118
|
-
// verify-then-manual-login mode: Traditional flow
|
|
12119
|
-
setAuthSuccess(true);
|
|
12120
|
-
setSuccessMessage('Account created successfully! Please check your email to verify your account, then log in.');
|
|
12121
|
-
}
|
|
12122
|
-
}
|
|
12123
|
-
else {
|
|
12124
|
-
// Login mode - always log in if token is provided
|
|
12125
|
-
if (response.token) {
|
|
12126
|
-
// Check for account lock or verification requirements
|
|
12127
|
-
if (response.accountLocked) {
|
|
12128
|
-
throw new Error('Your account has been locked due to unverified email. Please check your email or request a new verification link.');
|
|
12129
|
-
}
|
|
12130
|
-
if (response.requiresEmailVerification) {
|
|
12131
|
-
throw new Error('Please verify your email before logging in. Check your inbox for the verification link.');
|
|
12132
|
-
}
|
|
12133
|
-
auth.login(response.token, response.user, response.accountData);
|
|
12134
|
-
setAuthSuccess(true);
|
|
12135
|
-
setSuccessMessage('Login successful!');
|
|
12136
|
-
onAuthSuccess(response.token, response.user, response.accountData);
|
|
12137
|
-
if (redirectUrl) {
|
|
12138
|
-
setTimeout(() => {
|
|
12139
|
-
window.location.href = redirectUrl;
|
|
12140
|
-
}, 2000);
|
|
12141
|
-
}
|
|
12142
|
-
}
|
|
12143
|
-
else {
|
|
12144
|
-
throw new Error('Authentication failed - please verify your email before logging in.');
|
|
12145
|
-
}
|
|
12146
|
-
}
|
|
12156
|
+
// TODO: Backend implementation required
|
|
12157
|
+
// Endpoint: POST /api/v1/authkit/:clientId/account/update-profile
|
|
12158
|
+
// SDK method: smartlinks.authKit.updateProfile(clientId, updateData)
|
|
12159
|
+
setError('Backend API not yet implemented. See console for required endpoint.');
|
|
12160
|
+
console.log('Required API endpoint: POST /api/v1/authkit/:clientId/account/update-profile');
|
|
12161
|
+
console.log('Update data:', { displayName });
|
|
12162
|
+
// Uncomment when backend is ready:
|
|
12163
|
+
// const updateData: ProfileUpdateData = {
|
|
12164
|
+
// displayName: displayName || undefined,
|
|
12165
|
+
// photoURL: photoURL || undefined,
|
|
12166
|
+
// };
|
|
12167
|
+
// const updatedProfile = await smartlinks.authKit.updateProfile(clientId, updateData);
|
|
12168
|
+
// setProfile(updatedProfile);
|
|
12169
|
+
// setSuccess('Profile updated successfully!');
|
|
12170
|
+
// setEditingSection(null);
|
|
12171
|
+
// onProfileUpdated?.(updatedProfile);
|
|
12147
12172
|
}
|
|
12148
12173
|
catch (err) {
|
|
12149
|
-
const errorMessage = err instanceof Error ? err.message : '
|
|
12150
|
-
|
|
12151
|
-
|
|
12152
|
-
|
|
12153
|
-
|
|
12154
|
-
|
|
12155
|
-
|
|
12156
|
-
|
|
12157
|
-
|
|
12158
|
-
|
|
12159
|
-
|
|
12174
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to update profile';
|
|
12175
|
+
setError(errorMessage);
|
|
12176
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12177
|
+
}
|
|
12178
|
+
finally {
|
|
12179
|
+
setLoading(false);
|
|
12180
|
+
}
|
|
12181
|
+
};
|
|
12182
|
+
const cancelEdit = () => {
|
|
12183
|
+
setEditingSection(null);
|
|
12184
|
+
setDisplayName(profile?.displayName || '');
|
|
12185
|
+
setNewEmail('');
|
|
12186
|
+
setEmailPassword('');
|
|
12187
|
+
setCurrentPassword('');
|
|
12188
|
+
setNewPassword('');
|
|
12189
|
+
setConfirmPassword('');
|
|
12190
|
+
setNewPhone('');
|
|
12191
|
+
setPhoneCode('');
|
|
12192
|
+
setPhoneCodeSent(false);
|
|
12193
|
+
setError(undefined);
|
|
12194
|
+
setSuccess(undefined);
|
|
12195
|
+
};
|
|
12196
|
+
const handleChangeEmail = async (e) => {
|
|
12197
|
+
e.preventDefault();
|
|
12198
|
+
setLoading(true);
|
|
12199
|
+
setError(undefined);
|
|
12200
|
+
setSuccess(undefined);
|
|
12201
|
+
try {
|
|
12202
|
+
// TODO: Backend implementation required
|
|
12203
|
+
// Endpoint: POST /api/v1/authkit/:clientId/account/change-email
|
|
12204
|
+
// SDK method: smartlinks.authKit.changeEmail(clientId, newEmail, password)
|
|
12205
|
+
// Note: No verification flow for now - direct email update
|
|
12206
|
+
setError('Backend API not yet implemented. See console for required endpoint.');
|
|
12207
|
+
console.log('Required API endpoint: POST /api/v1/authkit/:clientId/account/change-email');
|
|
12208
|
+
console.log('Data:', { newEmail });
|
|
12209
|
+
// Uncomment when backend is ready:
|
|
12210
|
+
// await smartlinks.authKit.changeEmail(clientId, newEmail, emailPassword);
|
|
12211
|
+
// setSuccess('Email changed successfully!');
|
|
12212
|
+
// setEditingSection(null);
|
|
12213
|
+
// setNewEmail('');
|
|
12214
|
+
// setEmailPassword('');
|
|
12215
|
+
// onEmailChangeRequested?.();
|
|
12216
|
+
// await loadProfile(); // Reload to show new email
|
|
12217
|
+
}
|
|
12218
|
+
catch (err) {
|
|
12219
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to change email';
|
|
12220
|
+
setError(errorMessage);
|
|
12221
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12160
12222
|
}
|
|
12161
12223
|
finally {
|
|
12162
12224
|
setLoading(false);
|
|
12163
12225
|
}
|
|
12164
12226
|
};
|
|
12165
|
-
const
|
|
12166
|
-
|
|
12227
|
+
const handleChangePassword = async (e) => {
|
|
12228
|
+
e.preventDefault();
|
|
12229
|
+
if (newPassword !== confirmPassword) {
|
|
12230
|
+
setError('New passwords do not match');
|
|
12231
|
+
return;
|
|
12232
|
+
}
|
|
12233
|
+
if (newPassword.length < 6) {
|
|
12234
|
+
setError('Password must be at least 6 characters');
|
|
12167
12235
|
return;
|
|
12236
|
+
}
|
|
12168
12237
|
setLoading(true);
|
|
12169
12238
|
setError(undefined);
|
|
12239
|
+
setSuccess(undefined);
|
|
12170
12240
|
try {
|
|
12171
|
-
//
|
|
12172
|
-
//
|
|
12173
|
-
|
|
12174
|
-
|
|
12175
|
-
|
|
12176
|
-
|
|
12241
|
+
// TODO: Backend implementation required
|
|
12242
|
+
// Endpoint: POST /api/v1/authkit/:clientId/account/change-password
|
|
12243
|
+
// SDK method: smartlinks.authKit.changePassword(clientId, currentPassword, newPassword)
|
|
12244
|
+
setError('Backend API not yet implemented. See console for required endpoint.');
|
|
12245
|
+
console.log('Required API endpoint: POST /api/v1/authkit/:clientId/account/change-password');
|
|
12246
|
+
console.log('Data: currentPassword and newPassword provided');
|
|
12247
|
+
// Uncomment when backend is ready:
|
|
12248
|
+
// await smartlinks.authKit.changePassword(clientId, currentPassword, newPassword);
|
|
12249
|
+
// setSuccess('Password changed successfully!');
|
|
12250
|
+
// setEditingSection(null);
|
|
12251
|
+
// setCurrentPassword('');
|
|
12252
|
+
// setNewPassword('');
|
|
12253
|
+
// setConfirmPassword('');
|
|
12254
|
+
// onPasswordChanged?.();
|
|
12177
12255
|
}
|
|
12178
12256
|
catch (err) {
|
|
12179
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to
|
|
12257
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to change password';
|
|
12180
12258
|
setError(errorMessage);
|
|
12181
|
-
|
|
12259
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12182
12260
|
}
|
|
12183
12261
|
finally {
|
|
12184
12262
|
setLoading(false);
|
|
12185
12263
|
}
|
|
12186
12264
|
};
|
|
12187
|
-
const
|
|
12188
|
-
if (!resetRequestEmail)
|
|
12189
|
-
return;
|
|
12265
|
+
const handleSendPhoneCode = async () => {
|
|
12190
12266
|
setLoading(true);
|
|
12191
12267
|
setError(undefined);
|
|
12192
12268
|
try {
|
|
12193
|
-
await
|
|
12194
|
-
|
|
12195
|
-
|
|
12196
|
-
setShowRequestNewReset(false);
|
|
12197
|
-
setResetRequestEmail('');
|
|
12269
|
+
await smartlinks.authKit.sendPhoneCode(clientId, newPhone);
|
|
12270
|
+
setPhoneCodeSent(true);
|
|
12271
|
+
setSuccess('Verification code sent to your phone');
|
|
12198
12272
|
}
|
|
12199
12273
|
catch (err) {
|
|
12200
|
-
const errorMessage = err instanceof Error ? err.message : 'Failed to send
|
|
12274
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to send verification code';
|
|
12201
12275
|
setError(errorMessage);
|
|
12202
|
-
|
|
12276
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12203
12277
|
}
|
|
12204
12278
|
finally {
|
|
12205
12279
|
setLoading(false);
|
|
12206
12280
|
}
|
|
12207
12281
|
};
|
|
12208
|
-
const
|
|
12209
|
-
|
|
12210
|
-
const googleClientId = config?.googleClientId || DEFAULT_GOOGLE_CLIENT_ID;
|
|
12211
|
-
// Determine OAuth flow: default to 'oneTap' for better UX, but allow 'popup' for iframe compatibility
|
|
12212
|
-
const oauthFlow = config?.googleOAuthFlow || 'oneTap';
|
|
12282
|
+
const handleUpdatePhone = async (e) => {
|
|
12283
|
+
e.preventDefault();
|
|
12213
12284
|
setLoading(true);
|
|
12214
12285
|
setError(undefined);
|
|
12286
|
+
setSuccess(undefined);
|
|
12215
12287
|
try {
|
|
12216
|
-
|
|
12217
|
-
|
|
12218
|
-
|
|
12219
|
-
|
|
12220
|
-
|
|
12221
|
-
|
|
12222
|
-
|
|
12223
|
-
|
|
12224
|
-
|
|
12225
|
-
|
|
12226
|
-
|
|
12227
|
-
|
|
12228
|
-
|
|
12229
|
-
|
|
12230
|
-
if (response.error) {
|
|
12231
|
-
throw new Error(response.error_description || response.error);
|
|
12232
|
-
}
|
|
12233
|
-
const accessToken = response.access_token;
|
|
12234
|
-
// Send access token to backend
|
|
12235
|
-
const authResponse = await api.loginWithGoogle(accessToken);
|
|
12236
|
-
if (authResponse.token) {
|
|
12237
|
-
auth.login(authResponse.token, authResponse.user, authResponse.accountData);
|
|
12238
|
-
setAuthSuccess(true);
|
|
12239
|
-
setSuccessMessage('Google login successful!');
|
|
12240
|
-
onAuthSuccess(authResponse.token, authResponse.user, authResponse.accountData);
|
|
12241
|
-
}
|
|
12242
|
-
else {
|
|
12243
|
-
throw new Error('Authentication failed - no token received');
|
|
12244
|
-
}
|
|
12245
|
-
if (redirectUrl) {
|
|
12246
|
-
setTimeout(() => {
|
|
12247
|
-
window.location.href = redirectUrl;
|
|
12248
|
-
}, 2000);
|
|
12249
|
-
}
|
|
12250
|
-
setLoading(false);
|
|
12251
|
-
}
|
|
12252
|
-
catch (err) {
|
|
12253
|
-
const errorMessage = err instanceof Error ? err.message : 'Google login failed';
|
|
12254
|
-
setError(errorMessage);
|
|
12255
|
-
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12256
|
-
setLoading(false);
|
|
12257
|
-
}
|
|
12258
|
-
},
|
|
12259
|
-
});
|
|
12260
|
-
client.requestAccessToken();
|
|
12261
|
-
}
|
|
12262
|
-
else {
|
|
12263
|
-
// Use One Tap / Sign-In button flow (smoother UX but doesn't work in iframes)
|
|
12264
|
-
google.accounts.id.initialize({
|
|
12265
|
-
client_id: googleClientId,
|
|
12266
|
-
callback: async (response) => {
|
|
12267
|
-
try {
|
|
12268
|
-
const idToken = response.credential;
|
|
12269
|
-
const authResponse = await api.loginWithGoogle(idToken);
|
|
12270
|
-
if (authResponse.token) {
|
|
12271
|
-
auth.login(authResponse.token, authResponse.user, authResponse.accountData);
|
|
12272
|
-
setAuthSuccess(true);
|
|
12273
|
-
setSuccessMessage('Google login successful!');
|
|
12274
|
-
onAuthSuccess(authResponse.token, authResponse.user, authResponse.accountData);
|
|
12275
|
-
}
|
|
12276
|
-
else {
|
|
12277
|
-
throw new Error('Authentication failed - no token received');
|
|
12278
|
-
}
|
|
12279
|
-
if (redirectUrl) {
|
|
12280
|
-
setTimeout(() => {
|
|
12281
|
-
window.location.href = redirectUrl;
|
|
12282
|
-
}, 2000);
|
|
12283
|
-
}
|
|
12284
|
-
setLoading(false);
|
|
12285
|
-
}
|
|
12286
|
-
catch (err) {
|
|
12287
|
-
const errorMessage = err instanceof Error ? err.message : 'Google login failed';
|
|
12288
|
-
setError(errorMessage);
|
|
12289
|
-
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12290
|
-
setLoading(false);
|
|
12291
|
-
}
|
|
12292
|
-
},
|
|
12293
|
-
auto_select: false,
|
|
12294
|
-
cancel_on_tap_outside: true,
|
|
12295
|
-
});
|
|
12296
|
-
google.accounts.id.prompt((notification) => {
|
|
12297
|
-
if (notification.isNotDisplayed() || notification.isSkippedMoment()) {
|
|
12298
|
-
setLoading(false);
|
|
12299
|
-
}
|
|
12300
|
-
});
|
|
12301
|
-
}
|
|
12288
|
+
// TODO: Backend implementation required
|
|
12289
|
+
// Endpoint: POST /api/v1/authkit/:clientId/account/update-phone
|
|
12290
|
+
// SDK method: smartlinks.authKit.updatePhone(clientId, phoneNumber, verificationCode)
|
|
12291
|
+
setError('Backend API not yet implemented. See console for required endpoint.');
|
|
12292
|
+
console.log('Required API endpoint: POST /api/v1/authkit/:clientId/account/update-phone');
|
|
12293
|
+
console.log('Data:', { phoneNumber: newPhone, code: phoneCode });
|
|
12294
|
+
// Uncomment when backend is ready:
|
|
12295
|
+
// await smartlinks.authKit.updatePhone(clientId, newPhone, phoneCode);
|
|
12296
|
+
// setSuccess('Phone number updated successfully!');
|
|
12297
|
+
// setEditingSection(null);
|
|
12298
|
+
// setNewPhone('');
|
|
12299
|
+
// setPhoneCode('');
|
|
12300
|
+
// setPhoneCodeSent(false);
|
|
12301
|
+
// await loadProfile();
|
|
12302
12302
|
}
|
|
12303
12303
|
catch (err) {
|
|
12304
|
-
const errorMessage = err instanceof Error ? err.message : '
|
|
12304
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to update phone number';
|
|
12305
12305
|
setError(errorMessage);
|
|
12306
|
-
|
|
12306
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12307
|
+
}
|
|
12308
|
+
finally {
|
|
12307
12309
|
setLoading(false);
|
|
12308
12310
|
}
|
|
12309
12311
|
};
|
|
12310
|
-
const
|
|
12312
|
+
const handleDeleteAccount = async () => {
|
|
12313
|
+
if (deleteConfirmText !== 'DELETE') {
|
|
12314
|
+
setError('Please type DELETE to confirm account deletion');
|
|
12315
|
+
return;
|
|
12316
|
+
}
|
|
12317
|
+
if (!deletePassword) {
|
|
12318
|
+
setError('Password is required');
|
|
12319
|
+
return;
|
|
12320
|
+
}
|
|
12311
12321
|
setLoading(true);
|
|
12312
12322
|
setError(undefined);
|
|
12313
12323
|
try {
|
|
12314
|
-
|
|
12315
|
-
|
|
12316
|
-
|
|
12317
|
-
|
|
12318
|
-
|
|
12319
|
-
|
|
12320
|
-
|
|
12321
|
-
|
|
12322
|
-
|
|
12323
|
-
|
|
12324
|
-
|
|
12325
|
-
|
|
12326
|
-
|
|
12327
|
-
|
|
12328
|
-
|
|
12329
|
-
|
|
12330
|
-
|
|
12331
|
-
|
|
12332
|
-
|
|
12333
|
-
|
|
12334
|
-
|
|
12324
|
+
// TODO: Backend implementation required
|
|
12325
|
+
// Endpoint: DELETE /api/v1/authkit/:clientId/account/delete
|
|
12326
|
+
// SDK method: smartlinks.authKit.deleteAccount(clientId, password, confirmText)
|
|
12327
|
+
// Note: This performs a SOFT DELETE (marks as deleted, obfuscates email)
|
|
12328
|
+
setError('Backend API not yet implemented. See console for required endpoint.');
|
|
12329
|
+
console.log('Required API endpoint: DELETE /api/v1/authkit/:clientId/account/delete');
|
|
12330
|
+
console.log('Data: password and confirmText="DELETE" provided');
|
|
12331
|
+
console.log('Note: Backend should soft delete (mark deleted, obfuscate email, disable account)');
|
|
12332
|
+
// Uncomment when backend is ready:
|
|
12333
|
+
// await smartlinks.authKit.deleteAccount(clientId, deletePassword, deleteConfirmText);
|
|
12334
|
+
// setSuccess('Account deleted successfully');
|
|
12335
|
+
// onAccountDeleted?.();
|
|
12336
|
+
// await auth.logout();
|
|
12337
|
+
}
|
|
12338
|
+
catch (err) {
|
|
12339
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to delete account';
|
|
12340
|
+
setError(errorMessage);
|
|
12341
|
+
onError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12342
|
+
}
|
|
12343
|
+
finally {
|
|
12344
|
+
setLoading(false);
|
|
12345
|
+
}
|
|
12346
|
+
};
|
|
12347
|
+
if (!auth.isAuthenticated) {
|
|
12348
|
+
return (jsx("div", { className: `account-management ${className}`, children: jsx("p", { className: "text-muted-foreground", children: "Please log in to manage your account" }) }));
|
|
12349
|
+
}
|
|
12350
|
+
if (loading && !profile) {
|
|
12351
|
+
return (jsx("div", { className: `account-management ${className}`, children: jsx("p", { className: "text-muted-foreground", children: "Loading..." }) }));
|
|
12352
|
+
}
|
|
12353
|
+
return (jsxs("div", { className: `account-management ${className}`, style: { maxWidth: '600px' }, children: [error && (jsx("div", { className: "auth-error", role: "alert", children: error })), success && (jsx("div", { className: "auth-success", role: "alert", children: success })), showProfileSection && (jsxs("section", { className: "account-section", children: [jsxs("div", { className: "account-field", children: [jsxs("div", { className: "field-info", children: [jsx("label", { className: "field-label", children: "Display Name" }), jsx("div", { className: "field-value", children: profile?.displayName || 'Not set' })] }), editingSection !== 'profile' && (jsx("button", { type: "button", onClick: () => setEditingSection('profile'), className: "auth-button button-secondary", children: "Change" }))] }), editingSection === 'profile' && (jsxs("form", { onSubmit: handleUpdateProfile, className: "edit-form", children: [jsx("div", { className: "form-group", children: jsx("input", { id: "displayName", type: "text", value: displayName, onChange: (e) => setDisplayName(e.target.value), placeholder: "Your display name", className: "auth-input" }) }), jsxs("div", { className: "button-group", children: [jsx("button", { type: "submit", className: "auth-button", disabled: loading, children: loading ? 'Saving...' : 'Save' }), jsx("button", { type: "button", onClick: cancelEdit, className: "auth-button button-secondary", children: "Cancel" })] })] }))] })), showEmailSection && (jsxs("section", { className: "account-section", children: [jsxs("div", { className: "account-field", children: [jsxs("div", { className: "field-info", children: [jsx("label", { className: "field-label", children: "Email Address" }), jsxs("div", { className: "field-value", children: [profile?.email || 'Not set', profile?.emailVerified && (jsx("span", { className: "verification-badge verified", children: "Verified" })), profile?.email && !profile?.emailVerified && (jsx("span", { className: "verification-badge unverified", children: "Unverified" }))] })] }), editingSection !== 'email' && (jsx("button", { type: "button", onClick: () => setEditingSection('email'), className: "auth-button button-secondary", children: "Change Email" }))] }), editingSection === 'email' && (jsxs("form", { onSubmit: handleChangeEmail, className: "edit-form", children: [jsxs("div", { className: "form-group", children: [jsx("label", { htmlFor: "newEmail", children: "New Email" }), jsx("input", { id: "newEmail", type: "email", value: newEmail, onChange: (e) => setNewEmail(e.target.value), placeholder: "new.email@example.com", className: "auth-input", required: true })] }), jsxs("div", { className: "form-group", children: [jsx("label", { htmlFor: "emailPassword", children: "Confirm Password" }), jsx("input", { id: "emailPassword", type: "password", value: emailPassword, onChange: (e) => setEmailPassword(e.target.value), placeholder: "Enter your password", className: "auth-input", required: true })] }), jsxs("div", { className: "button-group", children: [jsx("button", { type: "submit", className: "auth-button", disabled: loading, children: loading ? 'Changing...' : 'Change Email' }), jsx("button", { type: "button", onClick: cancelEdit, className: "auth-button button-secondary", children: "Cancel" })] })] }))] })), showPasswordSection && (jsxs("section", { className: "account-section", children: [jsxs("div", { className: "account-field", children: [jsxs("div", { className: "field-info", children: [jsx("label", { className: "field-label", children: "Password" }), jsx("div", { className: "field-value", children: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022" })] }), editingSection !== 'password' && (jsx("button", { type: "button", onClick: () => setEditingSection('password'), className: "auth-button button-secondary", children: "Change Password" }))] }), editingSection === 'password' && (jsxs("form", { onSubmit: handleChangePassword, className: "edit-form", children: [jsxs("div", { className: "form-group", children: [jsx("label", { htmlFor: "currentPassword", children: "Current Password" }), jsx("input", { id: "currentPassword", type: "password", value: currentPassword, onChange: (e) => setCurrentPassword(e.target.value), placeholder: "Enter current password", className: "auth-input", required: true })] }), jsxs("div", { className: "form-group", children: [jsx("label", { htmlFor: "newPassword", children: "New Password" }), jsx("input", { id: "newPassword", type: "password", value: newPassword, onChange: (e) => setNewPassword(e.target.value), placeholder: "Enter new password", className: "auth-input", required: true, minLength: 6 })] }), jsxs("div", { className: "form-group", children: [jsx("label", { htmlFor: "confirmPassword", children: "Confirm New Password" }), jsx("input", { id: "confirmPassword", type: "password", value: confirmPassword, onChange: (e) => setConfirmPassword(e.target.value), placeholder: "Confirm new password", className: "auth-input", required: true, minLength: 6 })] }), jsxs("div", { className: "button-group", children: [jsx("button", { type: "submit", className: "auth-button", disabled: loading, children: loading ? 'Changing...' : 'Change Password' }), jsx("button", { type: "button", onClick: cancelEdit, className: "auth-button button-secondary", children: "Cancel" })] })] }))] })), showPhoneSection && (jsxs("section", { className: "account-section", children: [jsxs("div", { className: "account-field", children: [jsxs("div", { className: "field-info", children: [jsx("label", { className: "field-label", children: "Phone Number" }), jsx("div", { className: "field-value", children: profile?.phoneNumber || 'Not set' })] }), editingSection !== 'phone' && (jsx("button", { type: "button", onClick: () => setEditingSection('phone'), className: "auth-button button-secondary", children: "Change Phone" }))] }), editingSection === 'phone' && (jsxs("form", { onSubmit: handleUpdatePhone, className: "edit-form", children: [jsxs("div", { className: "form-group", children: [jsx("label", { htmlFor: "newPhone", children: "New Phone Number" }), jsx("input", { id: "newPhone", type: "tel", value: newPhone, onChange: (e) => setNewPhone(e.target.value), placeholder: "+1234567890", className: "auth-input", required: true })] }), !phoneCodeSent ? (jsxs("div", { className: "button-group", children: [jsx("button", { type: "button", onClick: handleSendPhoneCode, className: "auth-button", disabled: loading || !newPhone, children: loading ? 'Sending...' : 'Send Code' }), jsx("button", { type: "button", onClick: cancelEdit, className: "auth-button button-secondary", children: "Cancel" })] })) : (jsxs(Fragment, { children: [jsxs("div", { className: "form-group", children: [jsx("label", { htmlFor: "phoneCode", children: "Verification Code" }), jsx("input", { id: "phoneCode", type: "text", value: phoneCode, onChange: (e) => setPhoneCode(e.target.value), placeholder: "Enter 6-digit code", className: "auth-input", required: true, maxLength: 6 })] }), jsxs("div", { className: "button-group", children: [jsx("button", { type: "submit", className: "auth-button", disabled: loading, children: loading ? 'Verifying...' : 'Verify & Save' }), jsx("button", { type: "button", onClick: cancelEdit, className: "auth-button button-secondary", children: "Cancel" })] })] }))] }))] })), showDeleteAccount && (jsxs("section", { className: "account-section danger-zone", children: [jsx("h3", { className: "section-title text-danger", children: "Danger Zone" }), !showDeleteConfirm ? (jsx("button", { type: "button", onClick: () => setShowDeleteConfirm(true), className: "auth-button button-danger", children: "Delete Account" })) : (jsxs("div", { className: "delete-confirm", children: [jsx("p", { className: "warning-text", children: "\u26A0\uFE0F This action cannot be undone. This will permanently delete your account and all associated data." }), jsxs("div", { className: "form-group", children: [jsx("label", { htmlFor: "deletePassword", children: "Confirm Password" }), jsx("input", { id: "deletePassword", type: "password", value: deletePassword, onChange: (e) => setDeletePassword(e.target.value), placeholder: "Enter your password", className: "auth-input" })] }), jsxs("div", { className: "form-group", children: [jsx("label", { htmlFor: "deleteConfirm", children: "Type DELETE to confirm" }), jsx("input", { id: "deleteConfirm", type: "text", value: deleteConfirmText, onChange: (e) => setDeleteConfirmText(e.target.value), placeholder: "DELETE", className: "auth-input" })] }), jsxs("div", { className: "button-group", children: [jsx("button", { type: "button", onClick: handleDeleteAccount, className: "auth-button button-danger", disabled: loading, children: loading ? 'Deleting...' : 'Permanently Delete Account' }), jsx("button", { type: "button", onClick: () => {
|
|
12354
|
+
setShowDeleteConfirm(false);
|
|
12355
|
+
setDeletePassword('');
|
|
12356
|
+
setDeleteConfirmText('');
|
|
12357
|
+
}, className: "auth-button button-secondary", children: "Cancel" })] })] }))] }))] }));
|
|
12358
|
+
};
|
|
12359
|
+
|
|
12360
|
+
const SmartlinksClaimUI = ({ apiEndpoint, clientId, clientName, collectionId, productId, proofId, onClaimSuccess, onClaimError, additionalFields = [], theme = 'light', className = '', minimal = false, customization = {}, }) => {
|
|
12361
|
+
const auth = useAuth();
|
|
12362
|
+
const [claimStep, setClaimStep] = useState(auth.isAuthenticated ? 'questions' : 'auth');
|
|
12363
|
+
const [claimData, setClaimData] = useState({});
|
|
12364
|
+
const [error, setError] = useState();
|
|
12365
|
+
const [loading, setLoading] = useState(false);
|
|
12366
|
+
const handleAuthSuccess = (token, user, accountData) => {
|
|
12367
|
+
// Authentication successful
|
|
12368
|
+
auth.login(token, user, accountData);
|
|
12369
|
+
// If no additional questions, proceed directly to claim
|
|
12370
|
+
if (additionalFields.length === 0) {
|
|
12371
|
+
executeClaim(user);
|
|
12335
12372
|
}
|
|
12336
|
-
|
|
12337
|
-
|
|
12338
|
-
setError(errorMessage);
|
|
12339
|
-
onAuthError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12373
|
+
else {
|
|
12374
|
+
setClaimStep('questions');
|
|
12340
12375
|
}
|
|
12341
|
-
|
|
12342
|
-
|
|
12376
|
+
};
|
|
12377
|
+
const handleQuestionSubmit = async (e) => {
|
|
12378
|
+
e.preventDefault();
|
|
12379
|
+
// Validate required fields
|
|
12380
|
+
const missingFields = additionalFields
|
|
12381
|
+
.filter(field => field.required && !claimData[field.name])
|
|
12382
|
+
.map(field => field.label);
|
|
12383
|
+
if (missingFields.length > 0) {
|
|
12384
|
+
setError(`Please fill in: ${missingFields.join(', ')}`);
|
|
12385
|
+
return;
|
|
12386
|
+
}
|
|
12387
|
+
// Execute claim with collected data
|
|
12388
|
+
if (auth.user) {
|
|
12389
|
+
executeClaim(auth.user);
|
|
12343
12390
|
}
|
|
12344
12391
|
};
|
|
12345
|
-
const
|
|
12392
|
+
const executeClaim = async (user) => {
|
|
12393
|
+
setClaimStep('claiming');
|
|
12346
12394
|
setLoading(true);
|
|
12347
12395
|
setError(undefined);
|
|
12348
12396
|
try {
|
|
12349
|
-
|
|
12350
|
-
|
|
12351
|
-
|
|
12352
|
-
|
|
12353
|
-
|
|
12354
|
-
|
|
12355
|
-
|
|
12356
|
-
|
|
12357
|
-
|
|
12358
|
-
|
|
12359
|
-
}
|
|
12397
|
+
// Create attestation to claim the proof
|
|
12398
|
+
const response = await smartlinks.attestation.create(collectionId, productId, proofId, {
|
|
12399
|
+
public: {
|
|
12400
|
+
claimed: true,
|
|
12401
|
+
claimedAt: new Date().toISOString(),
|
|
12402
|
+
claimedBy: user.uid,
|
|
12403
|
+
...claimData,
|
|
12404
|
+
},
|
|
12405
|
+
private: {},
|
|
12406
|
+
proof: {},
|
|
12407
|
+
});
|
|
12408
|
+
setClaimStep('success');
|
|
12409
|
+
// Call success callback
|
|
12410
|
+
onClaimSuccess({
|
|
12411
|
+
proofId,
|
|
12412
|
+
user,
|
|
12413
|
+
claimData,
|
|
12414
|
+
attestationId: response.id,
|
|
12415
|
+
});
|
|
12360
12416
|
}
|
|
12361
12417
|
catch (err) {
|
|
12362
|
-
|
|
12418
|
+
console.error('Claim error:', err);
|
|
12419
|
+
const errorMessage = err instanceof Error ? err.message : 'Failed to claim proof';
|
|
12363
12420
|
setError(errorMessage);
|
|
12364
|
-
|
|
12421
|
+
onClaimError?.(err instanceof Error ? err : new Error(errorMessage));
|
|
12422
|
+
setClaimStep(additionalFields.length > 0 ? 'questions' : 'auth');
|
|
12365
12423
|
}
|
|
12366
12424
|
finally {
|
|
12367
12425
|
setLoading(false);
|
|
12368
12426
|
}
|
|
12369
12427
|
};
|
|
12370
|
-
const
|
|
12371
|
-
|
|
12372
|
-
|
|
12373
|
-
|
|
12374
|
-
|
|
12375
|
-
|
|
12376
|
-
|
|
12428
|
+
const handleFieldChange = (fieldName, value) => {
|
|
12429
|
+
setClaimData(prev => ({
|
|
12430
|
+
...prev,
|
|
12431
|
+
[fieldName]: value,
|
|
12432
|
+
}));
|
|
12433
|
+
};
|
|
12434
|
+
// Render authentication step
|
|
12435
|
+
if (claimStep === 'auth') {
|
|
12436
|
+
return (jsx("div", { className: className, children: jsx(SmartlinksAuthUI, { apiEndpoint: apiEndpoint, clientId: clientId, clientName: clientName, onAuthSuccess: handleAuthSuccess, onAuthError: onClaimError, theme: theme, minimal: minimal, customization: customization.authConfig }) }));
|
|
12437
|
+
}
|
|
12438
|
+
// Render additional questions step
|
|
12439
|
+
if (claimStep === 'questions') {
|
|
12440
|
+
return (jsxs("div", { className: `claim-questions ${className}`, children: [jsxs("div", { className: "claim-header mb-6", children: [jsx("h2", { className: "text-2xl font-bold mb-2", children: customization.claimTitle || 'Complete Your Claim' }), customization.claimDescription && (jsx("p", { className: "text-muted-foreground", children: customization.claimDescription }))] }), error && (jsx("div", { className: "claim-error bg-destructive/10 text-destructive px-4 py-3 rounded-md mb-4", children: error })), jsxs("form", { onSubmit: handleQuestionSubmit, className: "claim-form space-y-4", children: [additionalFields.map((field) => (jsxs("div", { className: "claim-field", children: [jsxs("label", { htmlFor: field.name, className: "block text-sm font-medium mb-2", children: [field.label, field.required && jsx("span", { className: "text-destructive ml-1", children: "*" })] }), field.type === 'textarea' ? (jsx("textarea", { id: field.name, name: field.name, placeholder: field.placeholder, value: claimData[field.name] || '', onChange: (e) => handleFieldChange(field.name, e.target.value), required: field.required, className: "w-full px-3 py-2 border border-input rounded-md bg-background", rows: 4 })) : field.type === 'select' ? (jsxs("select", { id: field.name, name: field.name, value: claimData[field.name] || '', onChange: (e) => handleFieldChange(field.name, e.target.value), required: field.required, className: "w-full px-3 py-2 border border-input rounded-md bg-background", children: [jsx("option", { value: "", children: "Select..." }), field.options?.map((option) => (jsx("option", { value: option, children: option }, option)))] })) : (jsx("input", { id: field.name, name: field.name, type: field.type, placeholder: field.placeholder, value: claimData[field.name] || '', onChange: (e) => handleFieldChange(field.name, e.target.value), required: field.required, className: "w-full px-3 py-2 border border-input rounded-md bg-background" }))] }, field.name))), jsx("button", { type: "submit", disabled: loading, className: "claim-submit-button w-full bg-primary text-primary-foreground px-4 py-2 rounded-md font-medium hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed", children: loading ? 'Claiming...' : 'Submit Claim' })] })] }));
|
|
12441
|
+
}
|
|
12442
|
+
// Render claiming step (loading state)
|
|
12443
|
+
if (claimStep === 'claiming') {
|
|
12444
|
+
return (jsxs("div", { className: `claim-loading ${className} flex flex-col items-center justify-center py-12`, children: [jsx("div", { className: "claim-spinner w-12 h-12 border-4 border-primary border-t-transparent rounded-full animate-spin mb-4" }), jsx("p", { className: "text-muted-foreground", children: "Claiming your product..." })] }));
|
|
12445
|
+
}
|
|
12446
|
+
// Render success step
|
|
12447
|
+
if (claimStep === 'success') {
|
|
12448
|
+
return (jsxs("div", { className: `claim-success ${className} text-center py-12`, children: [jsx("div", { className: "claim-success-icon w-16 h-16 bg-green-500 text-white rounded-full flex items-center justify-center text-3xl font-bold mx-auto mb-4", children: "\u2713" }), jsx("h2", { className: "text-2xl font-bold mb-2", children: "Claim Successful!" }), jsx("p", { className: "text-muted-foreground", children: customization.successMessage || 'Your product has been successfully claimed and registered to your account.' })] }));
|
|
12449
|
+
}
|
|
12450
|
+
return null;
|
|
12451
|
+
};
|
|
12452
|
+
|
|
12453
|
+
const ProtectedRoute = ({ children, fallback, redirectTo, }) => {
|
|
12454
|
+
const { isAuthenticated, isLoading } = useAuth();
|
|
12455
|
+
// Show loading state
|
|
12456
|
+
if (isLoading) {
|
|
12457
|
+
return jsx("div", { children: "Loading..." });
|
|
12458
|
+
}
|
|
12459
|
+
// If not authenticated, redirect or show fallback
|
|
12460
|
+
if (!isAuthenticated) {
|
|
12461
|
+
if (redirectTo) {
|
|
12462
|
+
window.location.href = redirectTo;
|
|
12463
|
+
return null;
|
|
12377
12464
|
}
|
|
12378
|
-
|
|
12379
|
-
|
|
12380
|
-
|
|
12381
|
-
|
|
12465
|
+
return fallback ? jsx(Fragment, { children: fallback }) : jsx("div", { children: "Access denied. Please log in." });
|
|
12466
|
+
}
|
|
12467
|
+
// Render protected content
|
|
12468
|
+
return jsx(Fragment, { children: children });
|
|
12469
|
+
};
|
|
12470
|
+
|
|
12471
|
+
const AuthUIPreview = ({ customization, enabledProviders = ['email', 'google', 'phone'], providerOrder, emailDisplayMode = 'form', theme = 'light', className, minimal = false, }) => {
|
|
12472
|
+
const showEmail = enabledProviders.includes('email');
|
|
12473
|
+
const showGoogle = enabledProviders.includes('google');
|
|
12474
|
+
const showPhone = enabledProviders.includes('phone');
|
|
12475
|
+
const showMagicLink = enabledProviders.includes('magic-link');
|
|
12476
|
+
// Determine ordered providers (excluding email if in button mode)
|
|
12477
|
+
const orderedProviders = providerOrder && providerOrder.length > 0
|
|
12478
|
+
? providerOrder.filter(p => enabledProviders.includes(p) && p !== 'email')
|
|
12479
|
+
: enabledProviders.filter(p => p !== 'email');
|
|
12480
|
+
const hasOtherProviders = showGoogle || showPhone || showMagicLink;
|
|
12481
|
+
// Render provider button helper
|
|
12482
|
+
const renderProviderButton = (provider) => {
|
|
12483
|
+
if (provider === 'google' && showGoogle) {
|
|
12484
|
+
return (jsxs("button", { className: "auth-provider-button", disabled: true, children: [jsxs("svg", { width: "18", height: "18", viewBox: "0 0 18 18", fill: "none", children: [jsx("path", { d: "M17.64 9.2c0-.637-.057-1.251-.164-1.84H9v3.481h4.844c-.209 1.125-.843 2.078-1.796 2.717v2.258h2.908c1.702-1.567 2.684-3.874 2.684-6.615z", fill: "#4285F4" }), jsx("path", { d: "M9 18c2.43 0 4.467-.806 5.956-2.183l-2.908-2.259c-.806.54-1.837.86-3.048.86-2.344 0-4.328-1.584-5.036-3.711H.957v2.332C2.438 15.983 5.482 18 9 18z", fill: "#34A853" }), jsx("path", { d: "M3.964 10.707c-.18-.54-.282-1.117-.282-1.707 0-.593.102-1.167.282-1.707V4.961H.957C.347 6.175 0 7.548 0 9s.348 2.825.957 4.039l3.007-2.332z", fill: "#FBBC05" }), jsx("path", { d: "M9 3.58c1.321 0 2.508.454 3.44 1.345l2.582-2.58C13.463.891 11.426 0 9 0 5.482 0 2.438 2.017.957 4.958L3.964 7.29C4.672 5.163 6.656 3.58 9 3.58z", fill: "#EA4335" })] }), jsx("span", { children: "Continue with Google" })] }, "google"));
|
|
12382
12485
|
}
|
|
12383
|
-
|
|
12384
|
-
|
|
12486
|
+
if (provider === 'phone' && showPhone) {
|
|
12487
|
+
return (jsxs("button", { className: "auth-provider-button", disabled: true, children: [jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: jsx("path", { d: "M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z" }) }), jsx("span", { children: "Continue with Phone" })] }, "phone"));
|
|
12488
|
+
}
|
|
12489
|
+
if (provider === 'magic-link' && showMagicLink) {
|
|
12490
|
+
return (jsxs("button", { className: "auth-provider-button", disabled: true, children: [jsx("svg", { width: "18", height: "18", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" }) }), jsx("span", { children: "Continue with Magic Link" })] }, "magic-link"));
|
|
12385
12491
|
}
|
|
12492
|
+
if (provider === 'email' && showEmail && emailDisplayMode === 'button') {
|
|
12493
|
+
return (jsxs("button", { className: "auth-provider-button", disabled: true, children: [jsx("svg", { width: "18", height: "18", viewBox: "0 0 20 20", fill: "none", stroke: "currentColor", children: jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z" }) }), jsx("span", { children: "Continue with Email" })] }, "email"));
|
|
12494
|
+
}
|
|
12495
|
+
return null;
|
|
12386
12496
|
};
|
|
12387
|
-
|
|
12388
|
-
|
|
12389
|
-
|
|
12390
|
-
return (jsx(AuthContainer, { theme: theme, className: className, config: config, minimal: minimal || config?.branding?.minimal || false, children: authSuccess ? (jsxs("div", { style: { textAlign: 'center', padding: '2rem' }, children: [jsx("div", { style: {
|
|
12391
|
-
color: 'var(--auth-primary-color, #4F46E5)',
|
|
12392
|
-
fontSize: '3rem',
|
|
12393
|
-
marginBottom: '1rem'
|
|
12394
|
-
}, children: "\u2713" }), jsx("h2", { style: {
|
|
12395
|
-
marginBottom: '0.5rem',
|
|
12396
|
-
fontSize: '1.5rem',
|
|
12397
|
-
fontWeight: 600
|
|
12398
|
-
}, children: successMessage?.includes('verified') ? 'Email Verified!' :
|
|
12399
|
-
successMessage?.includes('Magic link') ? 'Check Your Email!' :
|
|
12400
|
-
mode === 'register' ? 'Account Created!' : 'Login Successful!' }), jsx("p", { style: {
|
|
12401
|
-
color: '#6B7280',
|
|
12402
|
-
fontSize: '0.875rem'
|
|
12403
|
-
}, children: successMessage })] })) : mode === 'magic-link' ? (jsx(MagicLinkForm, { onSubmit: handleMagicLink, onCancel: () => setMode('login'), loading: loading, error: error })) : mode === 'phone' ? (jsx(PhoneAuthForm, { onSubmit: handlePhoneAuth, onBack: () => setMode('login'), loading: loading, error: error })) : mode === 'reset-password' ? (jsx(PasswordResetForm, { onSubmit: handlePasswordReset, onBack: () => {
|
|
12404
|
-
setMode('login');
|
|
12405
|
-
setResetSuccess(false);
|
|
12406
|
-
setResetToken(undefined); // Clear token when going back
|
|
12407
|
-
}, loading: loading, error: error, success: resetSuccess, token: resetToken })) : (mode === 'login' || mode === 'register') ? (jsx(Fragment, { children: showResendVerification ? (jsxs("div", { style: { marginTop: '1rem', padding: '1.5rem', backgroundColor: 'rgba(79, 70, 229, 0.05)', borderRadius: '0.5rem' }, children: [jsx("h3", { style: { marginBottom: '0.75rem', fontSize: '1rem', fontWeight: 600, color: 'var(--auth-text-color, #374151)' }, children: "Verification Link Expired" }), jsx("p", { style: { marginBottom: '1rem', fontSize: '0.875rem', color: 'var(--auth-text-color, #6B7280)', lineHeight: '1.5' }, children: "Your verification link has expired or is no longer valid. Please enter your email address below and we'll send you a new verification link." }), jsx("input", { type: "email", value: resendEmail || '', onChange: (e) => setResendEmail(e.target.value), placeholder: "your@email.com", style: {
|
|
12408
|
-
width: '100%',
|
|
12409
|
-
padding: '0.625rem',
|
|
12410
|
-
marginBottom: '1rem',
|
|
12411
|
-
border: '1px solid var(--auth-border-color, #D1D5DB)',
|
|
12412
|
-
borderRadius: '0.375rem',
|
|
12413
|
-
fontSize: '0.875rem',
|
|
12414
|
-
boxSizing: 'border-box'
|
|
12415
|
-
} }), jsxs("div", { style: { display: 'flex', gap: '0.75rem' }, children: [jsx("button", { onClick: handleResendVerification, disabled: loading || !resendEmail, style: {
|
|
12416
|
-
flex: 1,
|
|
12417
|
-
padding: '0.625rem 1rem',
|
|
12418
|
-
backgroundColor: 'var(--auth-primary-color, #4F46E5)',
|
|
12419
|
-
color: 'white',
|
|
12420
|
-
border: 'none',
|
|
12421
|
-
borderRadius: '0.375rem',
|
|
12422
|
-
cursor: (loading || !resendEmail) ? 'not-allowed' : 'pointer',
|
|
12423
|
-
fontSize: '0.875rem',
|
|
12424
|
-
fontWeight: 500,
|
|
12425
|
-
opacity: (loading || !resendEmail) ? 0.6 : 1
|
|
12426
|
-
}, children: loading ? 'Sending...' : 'Send New Verification Link' }), jsx("button", { onClick: () => {
|
|
12427
|
-
setShowResendVerification(false);
|
|
12428
|
-
setResendEmail('');
|
|
12429
|
-
setError(undefined);
|
|
12430
|
-
}, disabled: loading, style: {
|
|
12431
|
-
padding: '0.625rem 1rem',
|
|
12432
|
-
backgroundColor: 'transparent',
|
|
12433
|
-
color: 'var(--auth-text-color, #6B7280)',
|
|
12434
|
-
border: '1px solid var(--auth-border-color, #D1D5DB)',
|
|
12435
|
-
borderRadius: '0.375rem',
|
|
12436
|
-
cursor: loading ? 'not-allowed' : 'pointer',
|
|
12437
|
-
fontSize: '0.875rem',
|
|
12438
|
-
fontWeight: 500,
|
|
12439
|
-
opacity: loading ? 0.6 : 1
|
|
12440
|
-
}, children: "Cancel" })] })] })) : showRequestNewReset ? (jsxs("div", { style: { marginTop: '1rem', padding: '1.5rem', backgroundColor: 'rgba(239, 68, 68, 0.05)', borderRadius: '0.5rem' }, children: [jsx("h3", { style: { marginBottom: '0.75rem', fontSize: '1rem', fontWeight: 600, color: 'var(--auth-text-color, #374151)' }, children: "Password Reset Link Expired" }), jsx("p", { style: { marginBottom: '1rem', fontSize: '0.875rem', color: 'var(--auth-text-color, #6B7280)', lineHeight: '1.5' }, children: "Your password reset link has expired or is no longer valid. Please enter your email address below and we'll send you a new password reset link." }), jsx("input", { type: "email", value: resetRequestEmail || '', onChange: (e) => setResetRequestEmail(e.target.value), placeholder: "your@email.com", style: {
|
|
12441
|
-
width: '100%',
|
|
12442
|
-
padding: '0.625rem',
|
|
12443
|
-
marginBottom: '1rem',
|
|
12444
|
-
border: '1px solid var(--auth-border-color, #D1D5DB)',
|
|
12445
|
-
borderRadius: '0.375rem',
|
|
12446
|
-
fontSize: '0.875rem',
|
|
12447
|
-
boxSizing: 'border-box'
|
|
12448
|
-
} }), jsxs("div", { style: { display: 'flex', gap: '0.75rem' }, children: [jsx("button", { onClick: handleRequestNewReset, disabled: loading || !resetRequestEmail, style: {
|
|
12449
|
-
flex: 1,
|
|
12450
|
-
padding: '0.625rem 1rem',
|
|
12451
|
-
backgroundColor: '#EF4444',
|
|
12452
|
-
color: 'white',
|
|
12453
|
-
border: 'none',
|
|
12454
|
-
borderRadius: '0.375rem',
|
|
12455
|
-
cursor: (loading || !resetRequestEmail) ? 'not-allowed' : 'pointer',
|
|
12456
|
-
fontSize: '0.875rem',
|
|
12457
|
-
fontWeight: 500,
|
|
12458
|
-
opacity: (loading || !resetRequestEmail) ? 0.6 : 1
|
|
12459
|
-
}, children: loading ? 'Sending...' : 'Send New Reset Link' }), jsx("button", { onClick: () => {
|
|
12460
|
-
setShowRequestNewReset(false);
|
|
12461
|
-
setResetRequestEmail('');
|
|
12462
|
-
setError(undefined);
|
|
12463
|
-
}, disabled: loading, style: {
|
|
12464
|
-
padding: '0.625rem 1rem',
|
|
12465
|
-
backgroundColor: 'transparent',
|
|
12466
|
-
color: 'var(--auth-text-color, #6B7280)',
|
|
12467
|
-
border: '1px solid var(--auth-border-color, #D1D5DB)',
|
|
12468
|
-
borderRadius: '0.375rem',
|
|
12469
|
-
cursor: loading ? 'not-allowed' : 'pointer',
|
|
12470
|
-
fontSize: '0.875rem',
|
|
12471
|
-
fontWeight: 500,
|
|
12472
|
-
opacity: loading ? 0.6 : 1
|
|
12473
|
-
}, children: "Cancel" })] })] })) : (jsx(Fragment, { children: (() => {
|
|
12474
|
-
const emailDisplayMode = config?.emailDisplayMode || 'form';
|
|
12475
|
-
const providerOrder = config?.providerOrder || (config?.enabledProviders || enabledProviders);
|
|
12476
|
-
const actualProviders = config?.enabledProviders || enabledProviders;
|
|
12477
|
-
// Button mode: show provider selection first, then email form if email is selected
|
|
12478
|
-
if (emailDisplayMode === 'button' && !showEmailForm) {
|
|
12479
|
-
return (jsx(ProviderButtons, { enabledProviders: actualProviders, providerOrder: providerOrder, onEmailLogin: () => setShowEmailForm(true), onGoogleLogin: handleGoogleLogin, onPhoneLogin: () => setMode('phone'), onMagicLinkLogin: () => setMode('magic-link'), loading: loading }));
|
|
12480
|
-
}
|
|
12481
|
-
// Form mode or email button was clicked: show email form with other providers
|
|
12482
|
-
return (jsxs(Fragment, { children: [emailDisplayMode === 'button' && showEmailForm && (jsx("button", { onClick: () => setShowEmailForm(false), style: {
|
|
12483
|
-
marginBottom: '1rem',
|
|
12484
|
-
padding: '0.5rem',
|
|
12485
|
-
background: 'none',
|
|
12486
|
-
border: 'none',
|
|
12487
|
-
color: 'var(--auth-text-color, #6B7280)',
|
|
12488
|
-
cursor: 'pointer',
|
|
12489
|
-
fontSize: '0.875rem',
|
|
12490
|
-
display: 'flex',
|
|
12491
|
-
alignItems: 'center',
|
|
12492
|
-
gap: '0.25rem'
|
|
12493
|
-
}, children: "\u2190 Back to options" })), jsx(EmailAuthForm, { mode: mode, onSubmit: handleEmailAuth, onModeSwitch: () => {
|
|
12494
|
-
setMode(mode === 'login' ? 'register' : 'login');
|
|
12495
|
-
setShowResendVerification(false);
|
|
12496
|
-
setShowRequestNewReset(false);
|
|
12497
|
-
setError(undefined);
|
|
12498
|
-
}, onForgotPassword: () => setMode('reset-password'), loading: loading, error: error, additionalFields: config?.signupAdditionalFields }), emailDisplayMode === 'form' && actualProviders.length > 1 && (jsx(ProviderButtons, { enabledProviders: actualProviders.filter((p) => p !== 'email'), providerOrder: providerOrder, onGoogleLogin: handleGoogleLogin, onPhoneLogin: () => setMode('phone'), onMagicLinkLogin: () => setMode('magic-link'), loading: loading }))] }));
|
|
12499
|
-
})() })) })) : null }));
|
|
12497
|
+
return (jsx(AuthContainer, { theme: theme, className: className, config: customization, minimal: minimal, children: emailDisplayMode === 'button' ? (jsx("div", { className: "auth-provider-buttons", children: orderedProviders.concat(showEmail ? ['email'] : []).map(provider => renderProviderButton(provider)) })) : (
|
|
12498
|
+
/* Form mode: show email form first, then other providers */
|
|
12499
|
+
jsxs(Fragment, { children: [showEmail && (jsxs("div", { className: "auth-form", children: [jsxs("div", { className: "auth-form-group", children: [jsx("label", { className: "auth-label", children: "Email" }), jsx("input", { type: "email", className: "auth-input", placeholder: "Enter your email", disabled: true })] }), jsxs("div", { className: "auth-form-group", children: [jsx("label", { className: "auth-label", children: "Password" }), jsx("input", { type: "password", className: "auth-input", placeholder: "Enter your password", disabled: true })] }), jsx("button", { className: "auth-button auth-button-primary", disabled: true, children: "Sign In" }), jsx("div", { style: { textAlign: 'center', marginTop: '1rem' }, children: jsx("button", { className: "auth-link", disabled: true, children: "Forgot password?" }) }), jsxs("div", { style: { textAlign: 'center', marginTop: '0.5rem', fontSize: '0.875rem', color: 'var(--auth-text-muted, #6B7280)' }, children: ["Don't have an account?", ' ', jsx("button", { className: "auth-link", disabled: true, children: "Sign up" })] })] })), hasOtherProviders && (jsxs(Fragment, { children: [showEmail && (jsx("div", { className: "auth-or-divider", children: jsx("span", { children: "or continue with" }) })), jsx("div", { className: "auth-provider-buttons", children: orderedProviders.map(provider => renderProviderButton(provider)) })] }))] })) }));
|
|
12500
12500
|
};
|
|
12501
12501
|
|
|
12502
12502
|
export { AccountManagement, AuthProvider, AuthUIPreview, SmartlinksAuthUI as FirebaseAuthUI, ProtectedRoute, SmartlinksAuthUI, SmartlinksClaimUI, tokenStorage, useAuth };
|