@proveanything/smartlinks-auth-ui 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAUnD,OAAO,KAAK,EAAE,qBAAqB,EAAyC,MAAM,UAAU,CAAC;AAqB7F,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAk4B5D,CAAC"}
1
+ {"version":3,"file":"SmartlinksAuthUI.d.ts","sourceRoot":"","sources":["../../src/components/SmartlinksAuthUI.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAUnD,OAAO,KAAK,EAAE,qBAAqB,EAAyC,MAAM,UAAU,CAAC;AAkD7F,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAu5B5D,CAAC"}
package/dist/index.esm.js CHANGED
@@ -11428,10 +11428,37 @@ const DEFAULT_AUTH_CONFIG = {
11428
11428
  emailDisplayMode: 'button',
11429
11429
  googleOAuthFlow: 'oneTap'
11430
11430
  };
11431
- const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAuthSuccess, onAuthError, enabledProviders = ['email', 'google', 'phone'], initialMode = 'login', redirectUrl, theme = 'light', className, customization, skipConfigFetch = false, minimal = false, }) => {
11431
+ // Helper to dynamically load Google Identity Services if not already loaded
11432
+ const loadGoogleIdentityServices = () => {
11433
+ return new Promise((resolve, reject) => {
11434
+ // Check if already loaded
11435
+ if (window.google?.accounts) {
11436
+ resolve();
11437
+ return;
11438
+ }
11439
+ // Check if script is already being loaded
11440
+ const existingScript = document.querySelector('script[src="https://accounts.google.com/gsi/client"]');
11441
+ if (existingScript) {
11442
+ // Wait for existing script to load
11443
+ existingScript.addEventListener('load', () => resolve());
11444
+ existingScript.addEventListener('error', () => reject(new Error('Failed to load Google Identity Services')));
11445
+ return;
11446
+ }
11447
+ // Dynamically inject the script
11448
+ const script = document.createElement('script');
11449
+ script.src = 'https://accounts.google.com/gsi/client';
11450
+ script.async = true;
11451
+ script.defer = true;
11452
+ script.onload = () => resolve();
11453
+ script.onerror = () => reject(new Error('Failed to load Google Identity Services'));
11454
+ document.head.appendChild(script);
11455
+ });
11456
+ };
11457
+ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAuthSuccess, onAuthError, enabledProviders = ['email', 'google', 'phone'], initialMode = 'login', redirectUrl, theme = 'auto', className, customization, skipConfigFetch = false, minimal = false, }) => {
11432
11458
  const [mode, setMode] = useState(initialMode);
11433
11459
  const [loading, setLoading] = useState(false);
11434
11460
  const [error, setError] = useState();
11461
+ const [resolvedTheme, setResolvedTheme] = useState('light');
11435
11462
  const [resetSuccess, setResetSuccess] = useState(false);
11436
11463
  const [authSuccess, setAuthSuccess] = useState(false);
11437
11464
  const [successMessage, setSuccessMessage] = useState();
@@ -11445,6 +11472,19 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
11445
11472
  const [showEmailForm, setShowEmailForm] = useState(false); // Track if email form should be shown when emailDisplayMode is 'button'
11446
11473
  const api = new AuthAPI(apiEndpoint, clientId, clientName);
11447
11474
  const auth = useAuth();
11475
+ // Dark mode detection and theme management
11476
+ useEffect(() => {
11477
+ if (theme !== 'auto') {
11478
+ setResolvedTheme(theme);
11479
+ return;
11480
+ }
11481
+ // Auto-detect system theme preference
11482
+ const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');
11483
+ const updateTheme = () => setResolvedTheme(mediaQuery.matches ? 'dark' : 'light');
11484
+ updateTheme();
11485
+ mediaQuery.addEventListener('change', updateTheme);
11486
+ return () => mediaQuery.removeEventListener('change', updateTheme);
11487
+ }, [theme]);
11448
11488
  // Reinitialize Smartlinks SDK when apiEndpoint changes (for test/dev scenarios)
11449
11489
  // IMPORTANT: Preserve bearer token during reinitialization
11450
11490
  useEffect(() => {
@@ -11813,9 +11853,11 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
11813
11853
  setLoading(true);
11814
11854
  setError(undefined);
11815
11855
  try {
11856
+ // Dynamically load Google Identity Services if not already loaded
11857
+ await loadGoogleIdentityServices();
11816
11858
  const google = window.google;
11817
- if (!google) {
11818
- throw new Error('Google Identity Services not loaded. Please check your internet connection.');
11859
+ if (!google?.accounts) {
11860
+ throw new Error('Google Identity Services failed to initialize');
11819
11861
  }
11820
11862
  if (oauthFlow === 'popup') {
11821
11863
  // Use OAuth2 popup flow (works in iframes but requires popup permission)
@@ -11985,9 +12027,9 @@ const SmartlinksAuthUI = ({ apiEndpoint, clientId, clientName, accountData, onAu
11985
12027
  }
11986
12028
  };
11987
12029
  if (configLoading) {
11988
- 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" }) }) }));
12030
+ return (jsx(AuthContainer, { theme: resolvedTheme, className: className, minimal: minimal || config?.branding?.minimal || false, children: jsx("div", { style: { textAlign: 'center', padding: '2rem' }, children: jsx("div", { className: "auth-spinner" }) }) }));
11989
12031
  }
11990
- 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: {
12032
+ return (jsx(AuthContainer, { theme: resolvedTheme, className: className, config: config, minimal: minimal || config?.branding?.minimal || false, children: authSuccess ? (jsxs("div", { style: { textAlign: 'center', padding: '2rem' }, children: [jsx("div", { style: {
11991
12033
  color: 'var(--auth-primary-color, #4F46E5)',
11992
12034
  fontSize: '3rem',
11993
12035
  marginBottom: '1rem'