@donotdev/auth 0.3.0 → 0.3.1

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.
Files changed (39) hide show
  1. package/dist/AuthStore.js +1 -1
  2. package/dist/authHelpers.js +1 -1
  3. package/dist/components/AccountLinking.js +1 -1
  4. package/dist/components/AuthFallback.js +1 -1
  5. package/dist/components/AuthPartnerButton.js +2 -2
  6. package/dist/components/DeleteAccountDialogs.js +1 -1
  7. package/dist/components/EmailLinkForm.js +1 -1
  8. package/dist/components/EmailPasswordForm.js +1 -1
  9. package/dist/components/EmailVerification.js +1 -1
  10. package/dist/components/Feature.js +1 -1
  11. package/dist/components/FeatureGuard.js +1 -1
  12. package/dist/components/FeaturePlaceholder.js +1 -1
  13. package/dist/components/GoogleOneTap.js +1 -1
  14. package/dist/components/LoginModal.js +1 -1
  15. package/dist/components/MultipleAuthProviders.js +1 -1
  16. package/dist/components/NetworkStatusIndicator.js +1 -1
  17. package/dist/components/PasswordResetCallback.js +1 -1
  18. package/dist/components/PasswordStrengthIndicator.js +1 -1
  19. package/dist/components/PasswordUpdateDialog.js +1 -1
  20. package/dist/components/RateLimitAlert.js +1 -1
  21. package/dist/components/index.js +1 -1
  22. package/dist/constants.js +1 -1
  23. package/dist/emailAuth/fields.js +1 -1
  24. package/dist/emailAuth/flows.js +1 -1
  25. package/dist/emailAuth/rules.js +2 -2
  26. package/dist/hooks/useAccountLinking.js +1 -1
  27. package/dist/hooks/useAuthMethodToggle.js +1 -1
  28. package/dist/hooks/useAuthPartner.js +1 -1
  29. package/dist/hooks/useDeleteAccount.js +1 -1
  30. package/dist/hooks/useEmailLinkAuth.js +1 -1
  31. package/dist/hooks/useEmailLinkForm.js +1 -1
  32. package/dist/hooks/useFedCM.js +1 -1
  33. package/dist/hooks/useGoogleOneTap.js +1 -1
  34. package/dist/hooks/useNetworkStatus.js +1 -1
  35. package/dist/index.js +1 -1
  36. package/dist/tsconfig.tsbuildinfo +1 -1
  37. package/dist/useAuth.js +1 -1
  38. package/guidelines/AUTH.md +4 -4
  39. package/package.json +5 -5
@@ -1 +1 @@
1
- "use client";import{useState as G,useEffect as L,useRef as f,useCallback as j,startTransition as _,useMemo as B}from"react";import{useIsDark as oe}from"@donotdev/components";import{handleError as g,getOAuthClientId as te,getEnabledAuthPartners as re,isClient as ne,useTranslation as ae,useScriptLoader as ie}from"@donotdev/core";import{useAuth as J}from"../useAuth";import{useFedCM as se}from"./useFedCM";function ce({clientId:Q,autoSelect:x=!0,cancelOnTapOutside:v=!0,promptParentId:y,disabled:l=!1,onSuccess:C,onError:i,allowedParentOrigins:N,cspNonce:S,clientOnly:R=!1}={}){const{t:n}=ae("auth"),T=J("user"),A=J("signInWithGoogleCredential"),I=oe(),s=Q||te("google"),E=re().includes("google"),{isSupported:r,isReady:d,error:F,browserInfo:U}=se({checkGoogleServices:!0,onError:o=>{const t=g(o,{userMessage:n("auth.fedcmNotSupported","Your browser does not support Google One Tap"),context:{operation:"fedcm_detection"},severity:"warning"});i?.(t)}}),{isLoading:V,isLoaded:O,error:P,isReady:q,load:X,loadTriggered:Z}=ie("https://accounts.google.com/gsi/client",{enabled:E&&!!s&&!l&&d&&r,nonce:S,checkExisting:!0,isLoaded:()=>!!window.google?.accounts?.id,onError:o=>{const t=g(o,{userMessage:n("auth.googleScriptLoadError","Failed to load Google Identity Services"),context:{operation:"google_script_load"},severity:"error"});i?.(t)}}),[b,$]=G(!1),[z,Y]=G(null),K=f(null),a=f(!1),c=f(null),D=f(0),[H,p]=G(!1),m="gsi_hide_until",w=600*1e3,M=B(()=>E&&!!s&&!l&&!T&&r&&(R?b:!0)&&!H,[E,s,l,T,r,R,b,H]),ee=B(()=>!r&&d?new Error(n("auth.fedcmRequired","Google One Tap requires a modern browser (Chrome 116+ or Edge 116+)")):P||F||z,[P,F,z,r,d,n]),h=j(async o=>{try{if(!o||typeof o!="string")throw new Error("Invalid credential format");await A(o),_(()=>{C?.(o)})}catch(t){const e=g(t,{userMessage:n("auth.googleOneTapError","Google One Tap authentication failed"),context:{operation:"google_one_tap_signin",credentialLength:o?.length||0},severity:"error"});throw _(()=>{Y(e)}),i?.(e),e}},[A,C,i,n]),k=j(()=>{if(!ne()||!q||!s||!window.google?.accounts?.id||!r||a.current)return;const o=Date.now();if(!(o-D.current<w&&D.current>0))try{a.current=!0,D.current=o;const t={client_id:s,callback:async e=>{try{await h(e.credential)}catch(W){g(W,{userMessage:"Google One Tap credential handling failed",context:{operation:"google_one_tap_callback"},severity:"error"})}},auto_select:x,cancel_on_tap_outside:v,context:"signin",ux_mode:"popup",itp_support:!0,state:I?"dark":"light",use_fedcm_for_prompt:!0,allowed_parent_origins:N,csp_nonce:S,moment_callback:e=>{const W=e.getMomentType();if(e.isDisplayMoment?.()){if(!e.isDisplayed?.()&&e.getNotDisplayedReason){a.current=!1;try{const u=Date.now()+w;localStorage.setItem(m,String(u)),p(!0)}catch{}}}else if(e.isSkippedMoment?.()){a.current=!1;try{const u=Date.now()+w;localStorage.setItem(m,String(u)),p(!0)}catch{}}else if(e.isDismissedMoment?.()){a.current=!1;try{const u=Date.now()+w;localStorage.setItem(m,String(u)),p(!0)}catch{}}}};y&&(t.prompt_parent_id=y),window.google.accounts.id.initialize(t),c.current&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>{window.google?.accounts?.id?.prompt(e=>{e?.credential&&h(e.credential)}),c.current=null},100)}catch(t){const e=g(t,{userMessage:n("auth.googleOneTapInitError","Failed to initialize Google One Tap"),context:{operation:"google_one_tap_initialize",fedcmSupported:r},severity:"error"});_(()=>{Y(e)}),i?.(e),a.current=!1}},[q,s,r,x,v,y,I,h,i,N,S,n]);return L(()=>{if(typeof window<"u"){_(()=>{$(!0)});try{const o=Number(localStorage.getItem(m)||0);p(o>Date.now())}catch{}}},[]),L(()=>{O&&!l&&M&&d&&k()},[O,l,M,d,k]),L(()=>()=>{c.current&&window.clearTimeout(c.current),a.current=!1},[]),{isLoaded:O,isLoading:V,error:ee,user:T,isDark:I,fedcmSupported:r,isHydrated:b,containerRef:K,initialize:k,handleCredential:h,shouldShow:M,browserInfo:U,triggerLoad:X,loadTriggered:Z}}export{ce as useGoogleOneTap};
1
+ "use client";import{useState as b,useEffect as k,useRef as _,useCallback as K,startTransition as y,useMemo as j}from"react";import{useIsDark as re}from"@donotdev/components";import{handleError as p,getOAuthClientId as oe,getEnabledAuthPartners as ne,isClient as ie,useTranslation as se,useScriptLoader as ae}from"@donotdev/core";import{useAuth as B}from"../useAuth";import{useFedCM as ce}from"./useFedCM";function me({clientId:J,autoSelect:v=!0,cancelOnTapOutside:x=!0,promptParentId:T,disabled:u=!1,onSuccess:O,onError:s,allowedParentOrigins:z,cspNonce:S,clientOnly:A=!1}={}){const{t:o}=se("auth"),E=B("user"),N=B("signInWithGoogleCredential"),L=re(),a=J||oe("google"),I=ne().includes("google"),{isSupported:r,isReady:d,error:U,browserInfo:Q}=ce({checkGoogleServices:!0,onError:e=>{const l=p(e,{userMessage:o("auth.fedcmNotSupported","Your browser does not support Google One Tap"),context:{operation:"fedcm_detection"},severity:"warning"});s?.(l)}}),{isLoading:V,isLoaded:D,error:F,isReady:P,load:X,loadTriggered:Z}=ae("https://accounts.google.com/gsi/client",{enabled:I&&!!a&&!u&&d&&r,nonce:S,checkExisting:!0,isLoaded:()=>!!window.google?.accounts?.id,onError:e=>{const l=p(e,{userMessage:o("auth.googleScriptLoadError","Failed to load Google Identity Services"),context:{operation:"google_script_load"},severity:"error"});s?.(l)}}),[M,$]=b(!1),[W,q]=b(null),ee=_(null),i=_(!1),c=_(null),C=_(0),[H,f]=b(!1),m="gsi_hide_until",h=600*1e3,G=j(()=>I&&!!a&&!u&&!E&&r&&(A?M:!0)&&!H,[I,a,u,E,r,A,M,H]),te=j(()=>!r&&d?new Error(o("auth.fedcmRequired","Google One Tap requires a modern browser (Chrome 116+ or Edge 116+)")):F||U||W,[F,U,W,r,d,o]),w=K(async e=>{try{if(!e||typeof e!="string")throw new Error("Invalid credential format");await N(e),y(()=>{O?.(e)})}catch(l){const n=p(l,{userMessage:o("auth.googleOneTapError","Google One Tap authentication failed"),context:{operation:"google_one_tap_signin",credentialLength:e?.length||0},severity:"error"});throw y(()=>{q(n)}),s?.(n),n}},[N,O,s,o]),R=K(()=>{if(!ie()||!P||!a||!window.google?.accounts?.id||!r||i.current)return;const e=Date.now();if(!(e-C.current<h&&C.current>0))try{i.current=!0,C.current=e;const n={client_id:a,callback:async t=>{try{await w(t.credential)}catch(Y){p(Y,{userMessage:"Google One Tap credential handling failed",context:{operation:"google_one_tap_callback"},severity:"error"})}},auto_select:v,cancel_on_tap_outside:x,context:"signin",ux_mode:"popup",itp_support:!0,state:L?"dark":"light",use_fedcm_for_prompt:!0,allowed_parent_origins:z,csp_nonce:S,moment_callback:t=>{const Y=t.getMomentType();if(t.isDisplayMoment?.()){if(!t.isDisplayed?.()){if(t.getNotDisplayedReason){i.current=!1;try{const g=Date.now()+h;localStorage.setItem(m,String(g)),f(!0)}catch{}}}}else if(t.isSkippedMoment?.()){i.current=!1;try{const g=Date.now()+h;localStorage.setItem(m,String(g)),f(!0)}catch{}}else if(t.isDismissedMoment?.()){i.current=!1;try{const g=Date.now()+h;localStorage.setItem(m,String(g)),f(!0)}catch{}}}};T&&(n.prompt_parent_id=T),window.google.accounts.id.initialize(n),c.current&&window.clearTimeout(c.current),c.current=window.setTimeout(()=>{window.google?.accounts?.id?.prompt(t=>{t?.credential&&w(t.credential)}),c.current=null},100)}catch(n){const t=p(n,{userMessage:o("auth.googleOneTapInitError","Failed to initialize Google One Tap"),context:{operation:"google_one_tap_initialize",fedcmSupported:r},severity:"error"});y(()=>{q(t)}),s?.(t),i.current=!1}},[P,a,r,v,x,T,L,w,s,z,S,o]);return k(()=>{if(typeof window<"u"){y(()=>{$(!0)});try{const e=Number(localStorage.getItem(m)||0);f(e>Date.now())}catch{}}},[]),k(()=>{D&&!u&&G&&d&&R()},[D,u,G,d,R]),k(()=>()=>{c.current&&window.clearTimeout(c.current),i.current=!1},[]),{isLoaded:D,isLoading:V,error:te,user:E,isDark:L,fedcmSupported:r,isHydrated:M,containerRef:ee,initialize:R,handleCredential:w,shouldShow:G,browserInfo:Q,triggerLoad:X,loadTriggered:Z}}export{me as useGoogleOneTap};
@@ -1 +1 @@
1
- "use client";import{useState as r,useEffect as w}from"react";import{isClient as s}from"@donotdev/core";function l(){const[n,o]=r(()=>s()?navigator.onLine:!0),[e,f]=r("unknown");return w(()=>{if(!s())return;const i=()=>o(!0),t=()=>o(!1),a=()=>{if("connection"in navigator){const c=navigator.connection;f(c.effectiveType||"unknown")}};return window.addEventListener("online",i),window.addEventListener("offline",t),a(),()=>{window.removeEventListener("online",i),window.removeEventListener("offline",t)}},[]),{online:n,connectionType:e,isSlowConnection:e==="slow-2g"||e==="2g",isOnline:n,isOffline:!n}}export{l as useNetworkStatus};
1
+ "use client";import{useState as s,useEffect as u}from"react";import{isClient as c}from"@donotdev/core";function O(){const[n,o]=s(()=>c()?navigator.onLine:!0),[e,r]=s("unknown");return u(()=>{if(!c())return;const t=()=>o(!0),i=()=>o(!1),f=()=>{if("connection"in navigator){const l=navigator.connection;r(l.effectiveType||"unknown")}};return window.addEventListener("online",t),window.addEventListener("offline",i),f(),()=>{window.removeEventListener("online",t),window.removeEventListener("offline",i)}},[]),{online:n,connectionType:e,isSlowConnection:e==="slow-2g"||e==="2g",isOnline:n,isOffline:!n}}export{O as useNetworkStatus};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{useAuth as s}from"./useAuth";import{useDeleteAccount as a}from"./hooks/useDeleteAccount";import{getAuthState as e,subscribeToAuth as t}from"./authHelpers";import{AuthPartnerButton as o,ConfirmDeleteDialog as u,FeatureGuard as r,GoogleOneTap as i,LoginModal as A,MultipleAuthProviders as l,PasswordResetCallback as m,ReauthDialog as h}from"./components";import{default as d}from"./components/EmailPasswordForm";import{AUTH_FIELD as n,useEmailSignIn as F,useEmailSignUp as T,usePasswordResetRequest as E}from"./emailAuth/flows";import{AuthConfirmPasswordField as g,AuthConsentField as R,AuthEmailField as p,AuthForm as P,AuthFormAlerts as S,AuthPasswordField as f,AuthRememberMeField as I,AuthSubmitButton as b}from"./emailAuth/fields";import{getAuthMethod as C,PARTNER_STATE as D,EMAIL_VERIFICATION_STATUS as M}from"./constants";export{n as AUTH_FIELD,g as AuthConfirmPasswordField,R as AuthConsentField,p as AuthEmailField,P as AuthForm,S as AuthFormAlerts,o as AuthPartnerButton,f as AuthPasswordField,I as AuthRememberMeField,b as AuthSubmitButton,u as ConfirmDeleteDialog,M as EMAIL_VERIFICATION_STATUS,d as EmailPasswordForm,r as FeatureGuard,i as GoogleOneTap,A as LoginModal,l as MultipleAuthProviders,D as PARTNER_STATE,m as PasswordResetCallback,h as ReauthDialog,C as getAuthMethod,e as getAuthState,t as subscribeToAuth,s as useAuth,a as useDeleteAccount,F as useEmailSignIn,T as useEmailSignUp,E as usePasswordResetRequest};
1
+ import{useAuth as o}from"./useAuth";import{useDeleteAccount as u}from"./hooks/useDeleteAccount";import{getAuthState as a,subscribeToAuth as A}from"./authHelpers";import{AuthPartnerButton as i,ConfirmDeleteDialog as m,FeatureGuard as h,GoogleOneTap as d,LoginModal as n,MultipleAuthProviders as f,PasswordResetCallback as p,ReauthDialog as F}from"./components";import{default as T}from"./components/EmailPasswordForm";import{AUTH_FIELD as x,useEmailSignIn as P,useEmailSignUp as R,usePasswordResetRequest as S}from"./emailAuth/flows";import{AuthConfirmPasswordField as b,AuthConsentField as w,AuthEmailField as C,AuthForm as D,AuthFormAlerts as M,AuthPasswordField as c,AuthRememberMeField as _,AuthSubmitButton as L}from"./emailAuth/fields";import{getAuthMethod as B,PARTNER_STATE as G,EMAIL_VERIFICATION_STATUS as N}from"./constants";export{x as AUTH_FIELD,b as AuthConfirmPasswordField,w as AuthConsentField,C as AuthEmailField,D as AuthForm,M as AuthFormAlerts,i as AuthPartnerButton,c as AuthPasswordField,_ as AuthRememberMeField,L as AuthSubmitButton,m as ConfirmDeleteDialog,N as EMAIL_VERIFICATION_STATUS,T as EmailPasswordForm,h as FeatureGuard,d as GoogleOneTap,n as LoginModal,f as MultipleAuthProviders,G as PARTNER_STATE,p as PasswordResetCallback,F as ReauthDialog,B as getAuthMethod,a as getAuthState,A as subscribeToAuth,o as useAuth,u as useDeleteAccount,P as useEmailSignIn,R as useEmailSignUp,S as usePasswordResetRequest};