@donotdev/auth 0.1.1 → 0.1.42
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/LICENSE.md +21 -242
- package/README.md +0 -0
- package/dist/AuthStore.d.ts.map +1 -1
- package/dist/AuthStore.js +1 -1
- package/dist/authHelpers.js +1 -1
- package/dist/components/AccountLinking.js +1 -1
- package/dist/components/AuthFallback.js +1 -1
- package/dist/components/AuthPartnerButton.js +2 -2
- package/dist/components/DeleteAccountDialogs.js +1 -1
- package/dist/components/EmailLinkForm.js +1 -1
- package/dist/components/EmailPasswordForm.d.ts.map +1 -1
- package/dist/components/EmailPasswordForm.js +2 -2
- package/dist/components/EmailVerification.js +1 -1
- package/dist/components/Feature.js +1 -1
- package/dist/components/FeatureGuard.js +1 -1
- package/dist/components/FeaturePlaceholder.js +1 -1
- package/dist/components/GoogleOneTap.js +1 -1
- package/dist/components/LoginModal.js +1 -1
- package/dist/components/MultipleAuthProviders.js +1 -1
- package/dist/components/NetworkStatusIndicator.js +1 -1
- package/dist/components/PasswordResetCallback.d.ts.map +1 -1
- package/dist/components/PasswordResetCallback.js +2 -2
- package/dist/components/PasswordStrengthIndicator.js +1 -1
- package/dist/components/PasswordUpdateDialog.js +1 -1
- package/dist/components/RateLimitAlert.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/constants.js +1 -1
- package/dist/hooks/useAccountLinking.js +1 -1
- package/dist/hooks/useAuthMethodToggle.js +1 -1
- package/dist/hooks/useAuthPartner.js +1 -1
- package/dist/hooks/useDeleteAccount.js +1 -1
- package/dist/hooks/useEmailLinkAuth.js +1 -1
- package/dist/hooks/useEmailLinkForm.js +1 -1
- package/dist/hooks/useFedCM.js +1 -1
- package/dist/hooks/useGoogleOneTap.js +1 -1
- package/dist/hooks/useNetworkStatus.js +1 -1
- package/dist/index.js +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useAuth.d.ts.map +1 -1
- package/dist/useAuth.js +1 -1
- package/package.json +6 -6
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import{jsx as s,jsxs as
|
|
2
|
-
`).some(
|
|
1
|
+
"use client";import{jsx as s,jsxs as w}from"react/jsx-runtime";import{useCallback as L,useEffect as D,useState as h}from"react";import{useForm as B,Controller as N,useWatch as z}from"react-hook-form";import{Alert as R,ALERT_VARIANT as S,Button as C,BUTTON_VARIANT as x,Dialog as F,PasswordInput as O,Spinner as Z,Stack as m,Text as g}from"@donotdev/components";import{useTranslation as $}from"@donotdev/core";import{useAuth as f}from"../useAuth";import{useAuthStore as V}from"../AuthStore";import{PasswordStrengthIndicator as G}from"./PasswordStrengthIndicator";function H(){if(typeof window>"u")return{type:null};const r=window.location.hash.slice(1);if(r){const i=new URLSearchParams(r),l=i.get("error_code");if(l){const p={type:"supabase_error",errorCode:l,errorDescription:i.get("error_description")?.replace(/\+/g," ")||void 0};return window.history.replaceState(null,"",window.location.pathname+window.location.search),p}if(i.get("type")==="recovery")return window.history.replaceState(null,"",window.location.pathname+window.location.search),{type:"supabase_recovery"}}const n=new URLSearchParams(window.location.search),d=n.get("oobCode");return d&&n.get("mode")==="resetPassword"?{type:"firebase",oobCode:d}:{type:null}}async function X(r){try{const n=new TextEncoder().encode(r),d=await crypto.subtle.digest("SHA-1",n),i=Array.from(new Uint8Array(d)).map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase(),l=i.slice(0,5),p=i.slice(5),a=await fetch(`https://api.pwnedpasswords.com/range/${l}`,{headers:{"Add-Padding":"true"},credentials:"omit"});return a.ok?(await a.text()).split(`
|
|
2
|
+
`).some(o=>{const[c]=o.split(":");return c?.trim()===p}):!1}catch{return!1}}function J(){const{t:r}=$("auth"),n=f("passwordResetPending"),d=f("verifyPasswordResetCode"),i=f("confirmPasswordReset"),l=f("updatePassword"),p=f("signInWithEmail"),[a,o]=h("idle"),[c,A]=h(null),[v,_]=h(null),[k,W]=h(!1),[U,q]=h(null),{control:y,handleSubmit:M,getValues:Y,formState:{errors:t,isSubmitting:P},setError:E}=B({mode:"onChange",defaultValues:{password:"",confirmPassword:""}}),I=z({control:y,name:"password"});D(()=>{if(a!=="idle")return;const e=H();if(e.type==="supabase_error"){e.errorCode==="otp_expired"?o("expired"):(q(e.errorDescription||null),o("invalid"));return}if(e.type==="firebase"&&e.oobCode){W(!0),_(e.oobCode),o("loading"),d(e.oobCode).then(u=>{u?(A(u),o("ready")):o("expired")});return}n&&o("ready")},[n,a,d]);const j=L(async e=>{try{if(k&&v){if(await i(v,e.password),c)try{await p(c,e.password)}catch{}}else await l(e.password),V.getState().setPasswordResetPending(!1);o("idle")}catch(u){const T=u instanceof Error?u.message:String(u);T.includes("expired")||T.includes("EXPIRED")?o("expired"):E("root",{message:r("resetPassword.error","Failed to reset password. Please try again.")})}},[k,v,c,i,l,p,E,r]),b=L(()=>{o("idle"),A(null),_(null),q(null),V.getState().setPasswordResetPending(!1),typeof window<"u"&&window.history.replaceState(null,"",window.location.pathname)},[]);return a==="idle"?null:w(F,{open:!0,onOpenChange:e=>{e||b()},style:{maxWidth:"min(28rem, 90vw)"},title:a==="success"?r("resetPassword.success_title","Password updated"):a==="expired"||a==="invalid"?r("resetPassword.expired_title","Link expired"):a==="loading"?r("resetPassword.verifying","Verifying..."):r("resetPassword.title","Set new password"),showClose:!0,children:[a==="loading"&&w(m,{align:"center",justify:"center",children:[s(Z,{}),s(g,{level:"body",variant:"muted",children:r("resetPassword.verifying","Verifying reset link...")})]}),(a==="expired"||a==="invalid")&&w(m,{children:[s(R,{variant:S.WARNING,description:a==="expired"?r("resetPassword.expired_description","This password reset link has expired. Please request a new one."):U||r("resetPassword.invalid_description","This password reset link is invalid. Please request a new one.")}),s(C,{variant:x.PRIMARY,onClick:b,fullWidth:!0,children:r("resetPassword.back_to_signin","Back to Sign In")})]}),a==="success"&&w(m,{children:[s(R,{variant:S.SUCCESS,description:r("resetPassword.success_description","Your password has been reset successfully. You are now signed in.")}),s(C,{variant:x.PRIMARY,onClick:b,fullWidth:!0,children:r("resetPassword.continue","Continue")})]}),a==="ready"&&s("form",{onSubmit:M(j),noValidate:!0,children:w(m,{children:[c&&s(g,{level:"small",variant:"muted",children:r("resetPassword.for_email",`Enter a new password for ${c}`)}),t.root&&s(R,{variant:S.ERROR,description:t.root.message}),s(N,{name:"password",control:y,rules:{required:r("passwordRequired","Password is required"),minLength:{value:8,message:r("passwordMinLength","Password must be at least 8 characters")},validate:{uppercase:e=>!e||/[A-Z]/.test(e)||r("passwordRequirement.uppercase","One uppercase letter"),lowercase:e=>!e||/[a-z]/.test(e)||r("passwordRequirement.lowercase","One lowercase letter"),number:e=>!e||/[0-9]/.test(e)||r("passwordRequirement.number","One number"),special:e=>!e||/[^a-zA-Z0-9]/.test(e)||r("passwordRequirement.special","One special character"),breached:async e=>!e||e.length<8?!0:!await X(e)||r("errors.breached_password","This password has appeared in a data breach.")}},render:({field:e})=>w(m,{gap:"tight",children:[s(O,{...e,label:r("resetPassword.new_password","New password"),placeholder:r("passwordPlaceholder","Enter your password"),autoComplete:"new-password",disabled:P,"aria-invalid":!!t.password,"aria-describedby":t.password?"reset-password-error":void 0,className:"dndev-w-full","data-variant":t.password?"destructive":void 0}),t.password&&s(g,{as:"span",level:"caption",variant:"destructive",id:"reset-password-error",role:"alert",children:t.password.message})]})}),s(N,{name:"confirmPassword",control:y,rules:{required:r("confirmPasswordRequired","Please confirm your password"),validate:e=>e===Y("password")||r("confirmPasswordMismatch","Passwords do not match")},render:({field:e})=>w(m,{gap:"tight",children:[s(O,{...e,label:r("confirmPassword","Confirm password"),placeholder:r("confirmPasswordPlaceholder","Re-enter your password"),autoComplete:"new-password",disabled:P,"aria-invalid":!!t.confirmPassword,"aria-describedby":t.confirmPassword?"reset-confirm-error":void 0,className:"dndev-w-full","data-variant":t.confirmPassword?"destructive":void 0}),t.confirmPassword&&s(g,{as:"span",level:"caption",variant:"destructive",id:"reset-confirm-error",role:"alert",children:t.confirmPassword.message})]})}),I&&s(G,{password:I,minLength:8,showRequirements:!0}),s(C,{type:"submit",variant:x.PRIMARY,disabled:P,fullWidth:!0,children:P?r("loading","Loading..."):r("resetPassword.submit","Reset Password")})]})})]})}export{J as PasswordResetCallback};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsxs as
|
|
1
|
+
"use client";import{jsxs as r,jsx as i}from"react/jsx-runtime";import{Check as w,Circle as v}from"lucide-react";import{useMemo as m}from"react";import{Progress as f,Stack as o,Text as l,cn as b}from"@donotdev/components";import{useTranslation as q}from"@donotdev/core";function k(e){if(!e)return"weak";let t=0;return e.length>=8&&(t+=1),e.length>=12&&(t+=1),/[a-z]/.test(e)&&(t+=1),/[A-Z]/.test(e)&&(t+=1),/[0-9]/.test(e)&&(t+=1),/[^a-zA-Z0-9]/.test(e)&&(t+=1),t<=2?"weak":t<=4?"fair":t<=5?"good":"strong"}function S(e,t,a){return[{label:a("passwordRequirement.length",`At least ${t} characters`),met:e.length>=t},{label:a("passwordRequirement.uppercase","One uppercase letter"),met:/[A-Z]/.test(e)},{label:a("passwordRequirement.lowercase","One lowercase letter"),met:/[a-z]/.test(e)},{label:a("passwordRequirement.number","One number"),met:/[0-9]/.test(e)},{label:a("passwordRequirement.special","One special character (!@#$%^&*)"),met:/[^a-zA-Z0-9]/.test(e)}]}const x={weak:25,fair:50,good:75,strong:100},g={weak:"destructive",fair:"warning",good:"accent",strong:"success"};function N({password:e,minLength:t=8,showRequirements:a=!0,className:p}){const{t:s}=q("auth"),d=m(()=>k(e),[e]),u=m(()=>S(e,t,(n,c)=>s(n,c||"")),[e,t,s]),h={weak:s("passwordStrength.weak","Weak"),fair:s("passwordStrength.fair","Fair"),good:s("passwordStrength.good","Good"),strong:s("passwordStrength.strong","Strong")};return r(o,{gap:"tight",className:b("dndev-password-strength",p),children:[r(o,{gap:"tight",children:[r(o,{direction:"row",align:"center",justify:"between",gap:"tight",children:[r(l,{as:"span",level:"caption",variant:"muted",children:[s("passwordStrength.label","Password strength"),":"]}),i(l,{as:"strong",level:"caption",variant:g[d],children:h[d]})]}),i(f,{value:x[d],variant:g[d],className:"dndev-password-strength-bar"})]}),a&&r(o,{gap:"tight",className:"dndev-password-requirements",children:[r(l,{as:"strong",level:"caption",variant:"muted",children:[s("passwordRequirements","Password requirements"),":"]}),i(o,{gap:"tight","data-inset":"true",children:u.map((n,c)=>r(o,{direction:"row",align:"center",gap:"tight",className:"dndev-password-requirement-item",children:[n.met?i(w,{className:"dndev-size-xs","data-variant":"success"}):i(v,{className:"dndev-size-xs","data-variant":"muted"}),i(l,{as:"span",level:"caption",variant:n.met?"success":"muted","data-opacity":n.met?void 0:"70",children:n.label})]},c))})]})]})}export{N as PasswordStrengthIndicator};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as s,jsxs as t,Fragment as P}from"react/jsx-runtime";import{useState as T}from"react";import{useForm as C,Controller as E,useWatch as N}from"react-hook-form";import{Alert as S,ALERT_VARIANT as A,Button as d,BUTTON_VARIANT as u,Dialog as I,PasswordInput as L,Stack as g,Text as R}from"@donotdev/components";import{useTranslation as O}from"@donotdev/core";import{PasswordStrengthIndicator as U}from"./PasswordStrengthIndicator";function x({updatePassword:m}){const{t:r}=O("profile"),[f,l]=T(!1),{control:n,handleSubmit:h,formState:{errors:a,isSubmitting:o},setError:y,reset:p}=C({mode:"onChange",defaultValues:{password:""}}),c=N({control:n,name:"password"}),v=async e=>{try{await m(e.password),l(!1),p()}catch(i){const b=i instanceof Error?i.message:String(i);y("root",{message:b||r("profile.security.password.dialog.error","Failed to update password")})}},w=e=>{l(e),e||p()};return s(I,{open:f,onOpenChange:w,trigger:s(d,{variant:u.OUTLINE,children:r("profile.security.password.change","Change Password")}),title:r("profile.security.password.dialog.title","Change Password"),description:r("profile.security.password.dialog.description","Enter your new password below"),footer:t(P,{children:[s(d,{variant:u.OUTLINE,onClick:()=>w(!1),disabled:o,children:r("profile.security.password.dialog.cancel","Cancel")}),s(d,{onClick:h(v),disabled:o||!c,children:o?r("profile.security.password.dialog.updating","Updating..."):r("profile.security.password.dialog.update","Update Password")})]}),children:t(g,{children:[a.root&&s(S,{variant:A.ERROR,description:a.root.message}),s(E,{name:"password",control:n,rules:{required:r("profile.security.password.dialog.required","Password is required"),minLength:{value:8,message:r("profile.security.password.dialog.minLength","Password must be at least 8 characters")}},render:({field:e})=>t(g,{gap:"tight",children:[s(L,{...e,label:r("profile.security.password.dialog.newPassword","New Password"),placeholder:r("profile.security.password.dialog.placeholder","Enter new password"),disabled:o,"aria-invalid":!!a.password,"aria-describedby":a.password?"password-update-error":void 0,className:"dndev-w-full","data-variant":a.password?"destructive":void 0}),a.password&&s(R,{as:"span",level:"caption",variant:"destructive",id:"password-update-error",role:"alert",children:a.password.message})]})}),s(U,{password:c||"",minLength:8})]})})}var q=x;export{q as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useTranslation as t}from"@donotdev/core";const e=({identifier:
|
|
1
|
+
"use client";import{useTranslation as t}from"@donotdev/core";const e=({identifier:n,className:r=""})=>{const{t:s}=t("auth");return null};var a=e;export{a as default};
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./AuthFallback";import{default as
|
|
1
|
+
export*from"./AuthFallback";import{default as a}from"./EmailPasswordForm";import{default as o}from"./AuthPartnerButton";import{default as r}from"./EmailVerification";export*from"./Feature";export*from"./FeatureGuard";export*from"./FeaturePlaceholder";import{default as t}from"./GoogleOneTap";import{default as s}from"./LoginModal";import{default as e}from"./MultipleAuthProviders";import{default as m}from"./NetworkStatusIndicator";import{default as f}from"./PasswordUpdateDialog";import{PasswordResetCallback as i}from"./PasswordResetCallback";import{PasswordStrengthIndicator as d}from"./PasswordStrengthIndicator";import{default as l}from"./RateLimitAlert";export*from"./DeleteAccountDialogs";export{o as AuthPartnerButton,a as EmailPasswordForm,r as EmailVerification,t as GoogleOneTap,s as LoginModal,e as MultipleAuthProviders,m as NetworkStatusIndicator,i as PasswordResetCallback,d as PasswordStrengthIndicator,f as PasswordUpdateDialog,l as RateLimitAlert};
|
package/dist/constants.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getAuthMethod as
|
|
1
|
+
import{getAuthMethod as A,EMAIL_VERIFICATION_STATUS as T}from"@donotdev/core";import{AUTH_PARTNER_STATE as t}from"@donotdev/core";export{T as EMAIL_VERIFICATION_STATUS,t as PARTNER_STATE,A as getAuthMethod};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as
|
|
1
|
+
"use client";import{useState as k,useEffect as v,useCallback as a}from"react";import{safeSessionStorage as e,handleError as p,isClient as t,isDev as r}from"@donotdev/core";import{getAuthMethod as L}from"../constants";import{useAuth as c}from"../useAuth";function P(){const s=c("signInWithPartner"),u=c("user"),[i,o]=k(null);v(()=>{if(t()){try{const n=e.getItem("accountLinkingInfo");if(n){const I=JSON.parse(n);o(I)}}catch{r()}return()=>{if(!t())return;const n=e.getItem("accountLinkingInfo");if(n)try{JSON.parse(n).isRequired||e.removeItem("accountLinkingInfo")}catch{}}}},[u]);const l=a(async()=>{if(!(!i||!i.isRequired))try{const{existingProvider:n}=i;if(n==="password"||n==="emailLink"){r();return}r(),await s(n,L())}catch(n){p(n)}},[i,s]),f=a(()=>{t()&&(e.removeItem("accountLinkingInfo"),o(null))},[]),g=i?.isRequired||!1,m=i?.email||null,d=i?.existingProvider||null,h=i?.newProvider||null;return{accountLinking:i,isRequired:g,email:m,existingProvider:d,newProvider:h,handleSignInWithExistingProvider:l,clearAccountLinking:f}}export{P as useAccountLinking};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as
|
|
1
|
+
"use client";import{useState as l,useCallback as t}from"react";function g({defaultValue:r="popup"}={}){const[o,e]=l(r),u=o==="redirect",d=o==="popup",i=t(()=>{e(p=>p==="redirect"?"popup":"redirect")},[]),s=t(()=>{e("redirect")},[]),a=t(()=>{e("popup")},[]),c=t(p=>{e(p?"redirect":"popup")},[]);return{isRedirectMode:u,isPopupMode:d,authMethod:o,toggleMode:i,setRedirectMode:s,setPopupMode:a,handleToggleChange:c}}export{g as useAuthMethodToggle};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useCallback as
|
|
1
|
+
"use client";import{useCallback as t}from"react";import"../constants";import{useAuth as o}from"../useAuth";function I(r,g={}){const h=o("getPartnerState"),e=o("setPartnerState"),d=o("signInWithPartner"),i=o("partnerError"),{onSuccess:s,onError:l}=g,u=h(r),p=u==="authenticated",m=u==="loading",n=i?.partnerId===r,E=n&&i?.error?new Error(i.error):null,c=t(()=>{n&&e(r,"idle")},[n,r,e]),S=t(()=>{e(r,"loading")},[r,e]),f=t(()=>{e(r,"idle")},[r,e]),A=t(async P=>{n&&c();try{e(r,"loading");const a=await d(r,P);if(a===null){e(r,"idle");return}a&&s&&s(a)}catch(a){e(r,"error",a),l&&l(a)}},[r,n,c,e,d,s,l]);return{partnerState:u,isAuthenticated:p,isAuthenticating:m,hasError:n,error:E,handleSignIn:A,clearError:c,setLoading:S,setIdle:f}}export{I as useAuthPartner};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as
|
|
1
|
+
"use client";import{useState as o}from"react";import{useAuth as f}from"../useAuth";function A(){const c=f("deleteAccount"),[r,e]=o(!1),[u,t]=o(!1),[i,n]=o(!1),[m,l]=o(null);return{showConfirmDialog:r,showPasswordDialog:u,isDeleting:i,error:m,startDeleteFlow:()=>{l(null),e(!0)},confirmDelete:async D=>{n(!0),l(null);try{await c(D),e(!1),t(!1)}catch(a){const s=a.message||a.message;s==="REQUIRES_PASSWORD"?(e(!1),t(!0)):s==="REAUTH_CANCELLED"?(e(!1),t(!1)):l(s||"Failed to delete account")}finally{n(!1)}},cancel:()=>{e(!1),t(!1),l(null)}}}export{A as useDeleteAccount};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useEffect as g,useState as
|
|
1
|
+
"use client";import{useEffect as g,useState as t,useCallback as E}from"react";import{handleError as k,isDev as s}from"@donotdev/core";import{useAuth as l}from"../useAuth";function p(){const o=l("isSignInWithEmailLink"),n=l("signInWithEmailLink"),[r,e]=t(!1),[m,a]=t(null),c=o();g(()=>{if(typeof window<"u"){const i=localStorage.getItem("emailForSignIn");i&&a(i)}},[]);const u=E(async i=>{if(!i){s();return}e(!0);try{s(),(await n(i))?.success&&(localStorage.removeItem("emailForSignIn"),a(null))}catch(f){k(f)}finally{e(!1)}},[n]);return{isEmailLink:c,isProcessing:r,email:m,completeEmailLinkSignIn:u}}export{p as useEmailLinkAuth};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as
|
|
1
|
+
"use client";import{useState as r,useCallback as l}from"react";import{handleError as v}from"@donotdev/core";import{useAuth as f}from"../useAuth";function F(S={}){const t=f("sendSignInLinkToEmail"),g=f("isAvailable"),{onSuccess:s,onError:o,actionCodeSettings:m}=S,[e,E]=r(""),[u,c]=r(!1),[h,d]=r(!1),[p,n]=r(null),i=e.trim().length>0&&e.includes("@"),k=i&&!u&&g,y=l(()=>{n(null)},[]),L=l(async w=>{if(w.preventDefault(),!i){n("Please enter a valid email address");return}c(!0),n(null);try{typeof window<"u"&&localStorage.setItem("emailForSignIn",e.trim()),await t(e.trim(),m),d(!0),s?.()}catch(a){const I=a instanceof Error?a.message:"Failed to send sign-in link";n(I),o?.(a),v(a)}finally{c(!1)}},[e,i,t,m,s,o]),b=l(()=>{d(!1),n(null)},[]);return{email:e,setEmail:E,isLoading:u,isSent:h,error:p,handleSendLink:L,handleResend:b,clearError:y,isValid:i,canSubmit:k}}export{F as useEmailLinkForm};
|
package/dist/hooks/useFedCM.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as
|
|
1
|
+
"use client";import{useState as s,useEffect as h,useMemo as C,useRef as E}from"react";import{handleError as S,isClient as u}from"@donotdev/core";function y({checkGoogleServices:a=!0,onError:i}={}){const[n,l]=s(!1),[m,c]=s(!1),[p,f]=s(null),d=E(i);d.current=i,h(()=>{u()&&(async()=>{try{const e="IdentityCredential"in window;let o=!0;if(a){const r=new Promise(t=>setTimeout(t,2e3));await Promise.race([new Promise(t=>{const w=setInterval(()=>{window.google?.accounts?.id&&(clearInterval(w),t(!0))},100)}),r]),o=!!window.google?.accounts?.id}l(e&&o),c(!0)}catch(e){const o=S(e,{userMessage:"Failed to detect FedCM support",context:{operation:"fedcm_detection"},severity:"warning"});f(o),c(!0),d.current?.(o)}})()},[a]);const g=C(()=>{if(!u())return{name:"Unknown",isSupported:!1,recommendation:"Loading..."};const e=navigator.userAgent;let o="Unknown",r="Please update your browser";if(e.includes("Chrome/")){const t=parseInt(e.match(/Chrome\/(\d+)/)?.[1]||"0");o=`Chrome ${t}`,r=t>=116?"Supported":"Please update to Chrome 116 or later"}else if(e.includes("Edg/")){const t=parseInt(e.match(/Edg\/(\d+)/)?.[1]||"0");o=`Edge ${t}`,r=t>=116?"Supported":"Please update to Edge 116 or later"}else e.includes("Safari/")&&!e.includes("Chrome")?(o="Safari",r="Not supported yet. Please use Chrome or Edge"):e.includes("Firefox/")&&(o="Firefox",r="Not supported yet. Please use Chrome or Edge");return{name:o,isSupported:n,recommendation:r}},[n]);return{isSupported:n,isReady:m,error:p,browserInfo:g}}export{y as useFedCM};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as
|
|
1
|
+
"use client";import{useState as G,useEffect as L,useRef as h,useCallback as j,startTransition as _,useMemo as B}from"react";import{useIsDark as oe}from"@donotdev/components";import{handleError as u,getOAuthClientId as te,getEnabledAuthPartners as re,isClient as ne,useTranslation as ae,useScriptLoader as ie}from"@donotdev/core";import{useAuth as K}from"../useAuth";import{useFedCM as se}from"./useFedCM";function ce({clientId:Q,autoSelect:x=!0,cancelOnTapOutside:C=!0,promptParentId:y,disabled:l=!1,onSuccess:v,onError:i,allowedParentOrigins:R,cspNonce:S,clientOnly:N=!1}={}){const{t:n}=ae("auth"),I=K("user"),F=K("signInWithGoogleCredential"),T=oe(),s=Q||te("google"),E=re().includes("google"),{isSupported:r,isReady:d,error:P,browserInfo:U}=se({checkGoogleServices:!0,onError:o=>{const t=u(o,{userMessage:n("auth.fedcmNotSupported","Your browser does not support Google One Tap"),context:{operation:"fedcm_detection"},severity:"warning"});i?.(t)}}),{isLoading:V,isLoaded:b,error:q,isReady:z,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=u(o,{userMessage:n("auth.googleScriptLoadError","Failed to load Google Identity Services"),context:{operation:"google_script_load"},severity:"error"});i?.(t)}}),[D,$]=G(!1),[Y,A]=G(null),J=h(null),a=h(!1),c=h(null),M=h(0),[H,p]=G(!1),m="gsi_hide_until",w=600*1e3,O=B(()=>E&&!!s&&!l&&!I&&r&&(N?D:!0)&&!H,[E,s,l,I,r,N,D,H]),ee=B(()=>!r&&d?new Error(n("auth.fedcmRequired","Google One Tap requires a modern browser (Chrome 116+ or Edge 116+)")):q||P||Y,[q,P,Y,r,d,n]),f=j(async o=>{try{if(!o||typeof o!="string")throw new Error("Invalid credential format");await F(o),_(()=>{v?.(o)})}catch(t){const e=u(t,{userMessage:n("auth.googleOneTapError","Google One Tap authentication failed"),context:{operation:"google_one_tap_signin",credentialLength:o?.length||0},severity:"error"});throw _(()=>{A(e)}),i?.(e),e}},[F,v,i,n]),k=j(()=>{if(!ne()||!z||!s||!window.google?.accounts?.id||!r||a.current)return;const o=Date.now();if(!(o-M.current<w&&M.current>0))try{a.current=!0,M.current=o;const t={client_id:s,callback:async e=>{try{await f(e.credential)}catch(W){u(W,{userMessage:"Google One Tap credential handling failed",context:{operation:"google_one_tap_callback"},severity:"error"})}},auto_select:x,cancel_on_tap_outside:C,context:"signin",ux_mode:"popup",itp_support:!0,state:T?"dark":"light",use_fedcm_for_prompt:!0,allowed_parent_origins:R,csp_nonce:S,moment_callback:e=>{const W=e.getMomentType();if(e.isDisplayMoment?.()){if(!e.isDisplayed?.()&&e.getNotDisplayedReason){a.current=!1;try{const g=Date.now()+w;localStorage.setItem(m,String(g)),p(!0)}catch{}}}else if(e.isSkippedMoment?.()){a.current=!1;try{const g=Date.now()+w;localStorage.setItem(m,String(g)),p(!0)}catch{}}else if(e.isDismissedMoment?.()){a.current=!1;try{const g=Date.now()+w;localStorage.setItem(m,String(g)),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&&f(e.credential)}),c.current=null},100)}catch(t){const e=u(t,{userMessage:n("auth.googleOneTapInitError","Failed to initialize Google One Tap"),context:{operation:"google_one_tap_initialize",fedcmSupported:r},severity:"error"});_(()=>{A(e)}),i?.(e),a.current=!1}},[z,s,r,x,C,y,T,f,i,R,S,n]);return L(()=>{if(typeof window<"u"){_(()=>{$(!0)});try{const o=Number(localStorage.getItem(m)||0);p(o>Date.now())}catch{}}},[]),L(()=>{b&&!l&&O&&d&&k()},[b,l,O,d,k]),L(()=>()=>{c.current&&window.clearTimeout(c.current),a.current=!1},[]),{isLoaded:b,isLoading:V,error:ee,user:I,isDark:T,fedcmSupported:r,isHydrated:D,containerRef:J,initialize:k,handleCredential:f,shouldShow:O,browserInfo:U,triggerLoad:X,loadTriggered:Z}}export{ce as useGoogleOneTap};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as
|
|
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),c=()=>{if("connection"in navigator){const a=navigator.connection;f(a.effectiveType||"unknown")}};return window.addEventListener("online",i),window.addEventListener("offline",t),c(),()=>{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};
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useAuth as
|
|
1
|
+
import{useAuth as a}from"./useAuth";import{useDeleteAccount as t}from"./hooks/useDeleteAccount";import{getAuthState as e,subscribeToAuth as s}from"./authHelpers";import{AuthPartnerButton as o,ConfirmDeleteDialog as u,FeatureGuard as r,GoogleOneTap as A,LoginModal as l,MultipleAuthProviders as i,PasswordResetCallback as T,ReauthDialog as h}from"./components";import{getAuthMethod as g,PARTNER_STATE as m,EMAIL_VERIFICATION_STATUS as n}from"./constants";export{o as AuthPartnerButton,u as ConfirmDeleteDialog,n as EMAIL_VERIFICATION_STATUS,r as FeatureGuard,A as GoogleOneTap,l as LoginModal,i as MultipleAuthProviders,m as PARTNER_STATE,T as PasswordResetCallback,h as ReauthDialog,g as getAuthMethod,e as getAuthState,s as subscribeToAuth,a as useAuth,t as useDeleteAccount};
|