@donotdev/auth 0.2.2 → 0.2.3

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.d.ts.map +1 -1
  2. package/dist/AuthStore.js +1 -1
  3. package/dist/components/AuthPartnerButton.d.ts.map +1 -1
  4. package/dist/components/EmailPasswordForm.d.ts +8 -18
  5. package/dist/components/EmailPasswordForm.d.ts.map +1 -1
  6. package/dist/components/EmailPasswordForm.js +1 -2
  7. package/dist/components/Feature.js +1 -1
  8. package/dist/components/MultipleAuthProviders.js +1 -1
  9. package/dist/components/PasswordResetCallback.d.ts.map +1 -1
  10. package/dist/components/PasswordResetCallback.js +1 -2
  11. package/dist/components/PasswordStrengthIndicator.d.ts.map +1 -1
  12. package/dist/components/PasswordStrengthIndicator.js +1 -1
  13. package/dist/constants.d.ts.map +1 -1
  14. package/dist/emailAuth/fields.d.ts +108 -0
  15. package/dist/emailAuth/fields.d.ts.map +1 -0
  16. package/dist/emailAuth/fields.js +1 -0
  17. package/dist/emailAuth/flows.d.ts +120 -0
  18. package/dist/emailAuth/flows.d.ts.map +1 -0
  19. package/dist/emailAuth/flows.js +1 -0
  20. package/dist/emailAuth/rules.d.ts +36 -0
  21. package/dist/emailAuth/rules.d.ts.map +1 -0
  22. package/dist/emailAuth/rules.js +2 -0
  23. package/dist/hooks/useAuthPartner.d.ts.map +1 -1
  24. package/dist/hooks/useAuthPartner.js +1 -1
  25. package/dist/hooks/useDeleteAccount.d.ts +15 -1
  26. package/dist/hooks/useDeleteAccount.d.ts.map +1 -1
  27. package/dist/hooks/useDeleteAccount.js +1 -1
  28. package/dist/hooks/useGoogleOneTap.d.ts +2 -1
  29. package/dist/hooks/useGoogleOneTap.d.ts.map +1 -1
  30. package/dist/hooks/useNetworkStatus.d.ts.map +1 -1
  31. package/dist/index.d.ts +6 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +1 -1
  34. package/dist/symbol-index.json +1 -1
  35. package/dist/tsconfig.tsbuildinfo +1 -1
  36. package/dist/useAuth.d.ts.map +1 -1
  37. package/dist/useAuth.js +1 -1
  38. package/guidelines/AUTH.md +14 -0
  39. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"file":"AuthStore.d.ts","sourceRoot":"","sources":["../src/AuthStore.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,WAAW,EAEjB,MAAM,gBAAgB,CAAC;AA2BxB,eAAO,MAAM,YAAY,iIAiMvB,CAAC"}
1
+ {"version":3,"file":"AuthStore.d.ts","sourceRoot":"","sources":["../src/AuthStore.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AAEH,OAAO,EAKL,KAAK,SAAS,EACd,KAAK,WAAW,EAEjB,MAAM,gBAAgB,CAAC;AA2BxB,eAAO,MAAM,YAAY,iIAwMvB,CAAC"}
package/dist/AuthStore.js CHANGED
@@ -1 +1 @@
1
- import{createDoNotDevStore as i,FEATURE_STATUS as l}from"@donotdev/core";import{PARTNER_STATE as n}from"./constants";const o={user:null,authenticated:!1,userId:null,loading:!1,error:null,userProfile:null,userSubscription:null,partnerStates:{},partnerError:null,authService:null,emailVerification:{status:"pending"},passwordResetPending:!1,status:l.INITIALIZING},c=i({name:"auth-store",createStore:(t,a)=>({...o,setStatus:r=>{t({status:r})},setPartnerState:(r,e,s)=>{t(u=>({partnerStates:{...u.partnerStates,[r]:e},partnerError:e==="error"&&s?{partnerId:r,error:s}:u.partnerError?.partnerId===r?null:u.partnerError}))},getPartnerState:r=>a().partnerStates[r]||n.IDLE,clearAllPartnerStates:()=>t(r=>({partnerStates:Object.keys(r.partnerStates).reduce((e,s)=>(e[s]=n.IDLE,e),{}),partnerError:null})),setAuthenticated:(r,e,s)=>{t({user:r,authenticated:!0,userId:r.id,loading:!1,error:null,status:l.READY,userSubscription:e,userProfile:s})},setUnauthenticated:()=>{t({user:null,authenticated:!1,userId:null,loading:!1,error:null,status:l.READY,userSubscription:null,userProfile:null})},setAuthLoading:r=>{t({loading:r})},setAuthError:r=>{t({error:r,loading:!1})},clearAuthError:()=>{t({error:null})},getCustomClaim:r=>a().getCustomClaimLocal(r),getCustomClaims:()=>a().getCustomClaimsLocal(),setAuthService:r=>t({authService:r}),getCustomClaimLocal:r=>{const e=a(),s=e.userProfile;return s?.claims&&typeof s.claims=="object"&&r in s.claims?s.claims[r]:s&&typeof s=="object"&&r in s?s[r]:e.user&&typeof e.user=="object"&&r in e.user?e.user[r]:null},getCustomClaimsLocal:()=>{const r=a(),e={};return r.userProfile?.claims&&Object.assign(e,r.userProfile.claims),Object.freeze({...e})},setPasswordResetPending:r=>t({passwordResetPending:r}),setEmailVerificationStatus:(r,e)=>t({emailVerification:{status:r,error:e}}),setUserProfile:r=>t({userProfile:r}),setUserSubscription:r=>t({userSubscription:r}),setLoading:r=>t({loading:r}),setError:r=>t({error:r}),clearError:()=>t({error:null}),reset:()=>t(o)})});export{c as useAuthStore};
1
+ import{createDoNotDevStore as c,FEATURE_STATUS as l,syncQueryCacheIdentity as o}from"@donotdev/core";import{PARTNER_STATE as u}from"./constants";const i={user:null,authenticated:!1,userId:null,loading:!1,error:null,userProfile:null,userSubscription:null,partnerStates:{},partnerError:null,authService:null,emailVerification:{status:"pending"},passwordResetPending:!1,status:l.INITIALIZING},d=c({name:"auth-store",createStore:(t,a)=>({...i,setStatus:r=>{t({status:r})},setPartnerState:(r,e,s)=>{t(n=>({partnerStates:{...n.partnerStates,[r]:e},partnerError:e==="error"&&s?{partnerId:r,error:s}:n.partnerError?.partnerId===r?null:n.partnerError}))},getPartnerState:r=>a().partnerStates[r]||u.IDLE,clearAllPartnerStates:()=>t(r=>({partnerStates:Object.keys(r.partnerStates).reduce((e,s)=>(e[s]=u.IDLE,e),{}),partnerError:null})),setAuthenticated:(r,e,s)=>{o(r.id),t({user:r,authenticated:!0,userId:r.id,loading:!1,error:null,status:l.READY,userSubscription:e,userProfile:s})},setUnauthenticated:()=>{o(null),t({user:null,authenticated:!1,userId:null,loading:!1,error:null,status:l.READY,userSubscription:null,userProfile:null})},setAuthLoading:r=>{t({loading:r})},setAuthError:r=>{t({error:r,loading:!1})},clearAuthError:()=>{t({error:null})},getCustomClaim:r=>a().getCustomClaimLocal(r),getCustomClaims:()=>a().getCustomClaimsLocal(),setAuthService:r=>t({authService:r}),getCustomClaimLocal:r=>{const e=a(),s=e.userProfile;return s?.claims&&typeof s.claims=="object"&&r in s.claims?s.claims[r]:s&&typeof s=="object"&&r in s?s[r]:e.user&&typeof e.user=="object"&&r in e.user?e.user[r]:null},getCustomClaimsLocal:()=>{const r=a(),e={};return r.userProfile?.claims&&Object.assign(e,r.userProfile.claims),Object.freeze({...e})},setPasswordResetPending:r=>t({passwordResetPending:r}),setEmailVerificationStatus:(r,e)=>t({emailVerification:{status:r,error:e}}),setUserProfile:r=>t({userProfile:r}),setUserSubscription:r=>t({userSubscription:r}),setLoading:r=>t({loading:r}),setError:r=>t({error:r}),clearError:()=>t({error:null}),reset:()=>t(i)})});export{d as useAuthStore};
@@ -1 +1 @@
1
- {"version":3,"file":"AuthPartnerButton.d.ts","sourceRoot":"","sources":["../../src/components/AuthPartnerButton.tsx"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,OAAO,CAAC;AAejE,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,cAAc,CAAC;AAGtB,UAAU,+BAAgC,SAAQ,sBAAsB;IACtE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,iBAAS,iBAAiB,CAAC,EACzB,SAAS,EACT,MAAM,EACN,SAAS,EACT,OAAO,EACP,SAAc,EACd,QAAQ,EACR,QAAgB,EAChB,OAAsB,EACtB,KAAK,EACL,GAAG,KAAK,EACT,EAAE,+BAA+B,GAChC,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC,+BAyIvE;AAED,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"AuthPartnerButton.d.ts","sourceRoot":"","sources":["../../src/components/AuthPartnerButton.tsx"],"names":[],"mappings":"AA6BA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,OAAO,CAAC;AAejE,OAAO,EAGL,KAAK,sBAAsB,EAC5B,MAAM,cAAc,CAAC;AAGtB,UAAU,+BAAgC,SAAQ,sBAAsB;IAEtE,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,CAAC;IAClC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;GASG;AACH,iBAAS,iBAAiB,CAAC,EACzB,SAAS,EACT,MAAM,EACN,SAAS,EACT,OAAO,EACP,SAAc,EACd,QAAQ,EACR,QAAgB,EAChB,OAAsB,EACtB,KAAK,EACL,GAAG,KAAK,EACT,EAAE,+BAA+B,GAChC,IAAI,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC,+BAyIvE;AAED,eAAe,iBAAiB,CAAC"}
@@ -1,25 +1,15 @@
1
1
  import type { EmailPasswordFormProps } from '../constants';
2
2
  /**
3
- * EmailPasswordForm Component
4
- *
5
- * Best-in-class email/password authentication form with:
6
- * - Real-time validation with react-hook-form
7
- * - Password strength indicator with inline requirements
8
- * - Breached password detection (NIST 800-63B / HaveIBeenPwned)
9
- * - Client-side rate limiting
10
- * - Anti-enumeration (signup + forgot password)
11
- * - CAPTCHA-ready (consumer passes token via prop)
12
- * - autoComplete hints for password managers
13
- * - Remember me persistence
14
- * - Forgot password flow
15
- * - Resend verification email
16
- * - Terms of Service / Privacy Policy consent (GDPR)
17
- * - Sign in / Sign up mode switching with form reset
18
- * - Full i18n support
19
- * - Accessible with proper ARIA
3
+ * Email/password form with three views: sign in (remember me, forgot password),
4
+ * sign up (password policy + strength, breached-password check, confirmation,
5
+ * consent) and forgot password. Success calls `onSuccess` at once; what the user must
6
+ * still do arrives as a toast that stays until dismissed.
20
7
  *
21
8
  * @component
22
- * @version 0.2.0
9
+ * @example
10
+ * ```tsx
11
+ * <EmailPasswordForm onSuccess={() => setOpen(false)} />
12
+ * ```
23
13
  */
24
14
  declare function EmailPasswordForm({ mode, onSuccess, onError, className, tos, privacy, captchaToken, }: EmailPasswordFormProps): import("react").JSX.Element;
25
15
  export default EmailPasswordForm;
@@ -1 +1 @@
1
- {"version":3,"file":"EmailPasswordForm.d.ts","sourceRoot":"","sources":["../../src/components/EmailPasswordForm.tsx"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EAAE,sBAAsB,EAAY,MAAM,cAAc,CAAC;AA8KrE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,iBAAS,iBAAiB,CAAC,EACzB,IAAe,EACf,SAAS,EACT,OAAO,EACP,SAAc,EACd,GAAG,EACH,OAAO,EACP,YAAY,GACb,EAAE,sBAAsB,+BA2qBxB;AAED,eAAe,iBAAiB,CAAC"}
1
+ {"version":3,"file":"EmailPasswordForm.d.ts","sourceRoot":"","sources":["../../src/components/EmailPasswordForm.tsx"],"names":[],"mappings":"AAqCA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAQ3D;;;;;;;;;;;GAWG;AACH,iBAAS,iBAAiB,CAAC,EACzB,IAAe,EACf,SAAS,EACT,OAAO,EACP,SAAS,EACT,GAAG,EACH,OAAO,EACP,YAAY,GACb,EAAE,sBAAsB,+BAiFxB;AAED,eAAe,iBAAiB,CAAC"}
@@ -1,2 +1 @@
1
- "use client";import{jsx as i,jsxs as n,Fragment as ne}from"react/jsx-runtime";import{useCallback as V,useEffect as Ue,useRef as Ke,useState as h}from"react";import{useForm as Me,Controller as W,useWatch as oe}from"react-hook-form";import{Alert as A,ALERT_VARIANT as E,Button as g,BUTTON_VARIANT as f,Checkbox as le,Dialog as de,Input as De,Label as ce,PasswordInput as ue,Stack as o,Text as b,cn as Oe}from"@donotdev/components";import{useTranslation as Ve,useAppConfig as We}from"@donotdev/core";import{useAuth as v}from"../useAuth";import{PasswordStrengthIndicator as je}from"./PasswordStrengthIndicator";const Fe=6e4,He=5,$e=3e4;function Ge(){const a=Ke([]),[t,m]=h(null),l=V(()=>!!(t&&Date.now()<t),[t]),y=V(()=>{const d=Date.now();a.current=a.current.filter(p=>d-p<Fe),a.current.push(d),a.current.length>=He&&(m(d+$e),a.current=[])},[]);return Ue(()=>{if(!t)return;const d=t-Date.now();if(d<=0){m(null);return}const p=setTimeout(()=>m(null),d);return()=>clearTimeout(p)},[t]),{isRateLimited:l,recordAttempt:y,cooldownUntil:t}}async function Be(a){try{const t=new TextEncoder().encode(a),m=await crypto.subtle.digest("SHA-1",t),l=Array.from(new Uint8Array(m)).map(e=>e.toString(16).padStart(2,"0")).join("").toUpperCase(),y=l.slice(0,5),d=l.slice(5),p=await fetch(`https://api.pwnedpasswords.com/range/${y}`,{headers:{"Add-Padding":"true"},credentials:"omit"});return p.ok?(await p.text()).split(`
2
- `).some(e=>{const[N]=e.split(":");return N?.trim()===d}):!1}catch{return!1}}const ze=[{test:a=>a.includes("429")||a.includes("rate")||a.includes("too_many_requests"),key:"errors.rate_limit",fallback:"Too many attempts. Please wait a moment and try again."},{test:a=>a.includes("email_not_confirmed")||a.includes("email not confirmed")||a.includes("auth/unverified-email"),key:"errors.email_not_confirmed",fallback:"Please verify your email before signing in."},{test:a=>a.includes("invalid_credentials")||a.includes("invalid login credentials")||a.includes("invalid-credential")||a.includes("auth/wrong-password")||a.includes("auth/user-not-found")||a.includes("invalid")&&a.includes("credential"),key:"errors.invalid_credentials",fallback:"Invalid email or password."},{test:a=>a.includes("already")||a.includes("exists")||a.includes("user_already_exists")||a.includes("user already registered")||a.includes("auth/email-already-in-use"),key:"signup.check_email",fallback:"Check your email to confirm your account."},{test:a=>a.includes("weak_password")||a.includes("weak password")||a.includes("auth/weak-password"),key:"errors.weak_password",fallback:"Password is too weak. Please choose a stronger password."},{test:a=>a.includes("network")||a.includes("fetch"),key:"networkError",fallback:"Network error. Please check your connection and try again."}];function Ze(a,t){const m=(a instanceof Error?a.message:String(a)).toLowerCase();for(const l of ze)if(l.test(m))return t(l.key,l.fallback);return t("errorGeneric","Authentication failed. Please try again.")}function Ye({mode:a="signin",onSuccess:t,onError:m,className:l="",tos:y,privacy:d,captchaToken:p}){const{t:e}=Ve("auth"),N=We("app"),me=v("signInWithEmail"),pe=v("createUserWithEmail"),we=v("sendPasswordResetEmail"),he=v("sendEmailVerification"),ge=v("setRememberMe"),fe=v("isAvailable"),j=v("status"),ve=v("loading"),ye=j==="degraded"||j==="error",[T,be]=h(a),w=T==="signup",[q,ke]=h(!1),[F,x]=h(!1),[k,H]=h(!1),[$,U]=h(!1),[K,G]=h(!1),[Pe,B]=h(!1),[_e,z]=h(!1),P=y!==void 0?y:N?.footer?.legalLinks?.find(r=>r.path.includes("terms"))?.path??"/legal/terms",_=d!==void 0?d:N?.footer?.legalLinks?.find(r=>r.path.includes("privacy"))?.path??"/legal/privacy",C=P!==!1,S=_!==!1,Z=C&&typeof P!="string",Y=S&&typeof _!="string",X=C&&typeof P=="string"?P:null,J=S&&typeof _=="string"?_:null,{isRateLimited:M,recordAttempt:Ce,cooldownUntil:Q}=Ge(),{control:R,handleSubmit:Se,getValues:Re,reset:ee,formState:{errors:s,isSubmitting:Ie},setError:D,clearErrors:ae}=Me({mode:"onChange",defaultValues:{email:"",password:"",confirmPassword:""}}),re=oe({control:R,name:"password"}),I=oe({control:R,name:"email"}),O=V(r=>{ee({email:I||"",password:"",confirmPassword:""}),ae(),U(!1),x(!1),G(!1),be(r)},[ee,ae,I]),Ae=async r=>{if(M()){D("root",{message:e("errors.rate_limit","Too many attempts. Please wait a moment and try again.")});return}Ce();try{T==="signin"?(q!==void 0&&await ge(q),await me(r.email,r.password),t?.(void 0)):(await pe(r.email,r.password,K?{gdpr_consent_at:new Date().toISOString()}:void 0),U(!0),t?.(void 0))}catch(u){const qe=T==="signup",te=u instanceof Error?u.message:String(u),L=te.toLowerCase();if(qe&&(L.includes("already")||L.includes("exists")||L.includes("user_already_exists")||L.includes("auth/email-already-in-use"))){U(!0);return}const xe=Ze(u,e);D("root",{message:xe}),m?.(u instanceof Error?u:new Error(te))}},Ee=async()=>{if(!I||!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(I)){D("email",{message:e("emailRequired","Email is required")});return}H(!0);try{await we(I)}catch{}finally{x(!0),H(!1)}},Ne=async()=>{try{await he()}catch{}};if(ye)return i(o,{className:l,children:i(A,{variant:E.WARNING,title:e("unavailable.title","Authentication Unavailable"),description:e("unavailable.description","Sign-in is temporarily unavailable. Please try again later.")})});const c=ve||Ie||!fe,ie=w&&(C||S),Le=p!==void 0&&!p,Te=c||M()||Le||ie&&!K,se=Q?Math.max(0,Math.ceil((Q-Date.now())/1e3)):0;return i("form",{onSubmit:Se(Ae),className:Oe("dndev-auth-form",l),noValidate:!0,children:n(o,{children:[s.root&&i(A,{variant:E.ERROR,description:s.root.message}),M()&&se>0&&i(A,{variant:E.WARNING,description:e("errors.rate_limit_cooldown",`Too many attempts. Please wait ${se} seconds.`)}),$&&n(o,{children:[i(A,{variant:E.SUCCESS,title:e("signup.success_title","Check your email"),description:e("signup.check_email","If an account was created, you will receive a confirmation email. Check your inbox and spam folder.")}),n(o,{direction:"row",gap:"tight",justify:"center",align:"center",children:[i(g,{type:"button",variant:f.GHOST,onClick:Ne,children:e("signup.resend_verification","Resend verification email")}),i(b,{as:"span",variant:"muted",children:"|"}),i(g,{type:"button",variant:f.LINK,onClick:()=>O("signin"),children:e("actions.sign_in_submit","Sign In")})]})]}),F&&n(o,{children:[i(A,{variant:E.SUCCESS,title:e("forgotPassword.sent","Password reset email sent"),description:e("forgotPassword.check_email_safe","If an account exists with this email, you will receive password reset instructions.")}),i(o,{align:"center",children:i(g,{type:"button",variant:f.LINK,onClick:()=>{x(!1)},children:e("back","Back")})})]}),!$&&!F&&n(o,{children:[i(W,{name:"email",control:R,rules:{required:e("emailRequired","Email is required"),pattern:{value:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,message:e("emailInvalid","Invalid email address")}},render:({field:r})=>n(o,{gap:"tight",children:[i(De,{...r,type:"email",label:e("email","Email"),placeholder:e("emailPlaceholder","Enter your email"),autoComplete:"username webauthn",disabled:c||k,"aria-invalid":!!s.email,"aria-describedby":s.email?"email-error":void 0,className:"dndev-w-full","data-variant":s.email?"destructive":void 0}),s.email&&i(b,{as:"span",level:"caption",variant:"destructive",id:"email-error",role:"alert",children:s.email.message})]})}),i(W,{name:"password",control:R,rules:{required:e("passwordRequired","Password is required"),minLength:{value:8,message:e("passwordMinLength","Password must be at least 8 characters")},validate:w?{uppercase:r=>r?/[A-Z]/.test(r)?!0:e("passwordRequirement.uppercase","Password must contain at least one uppercase letter"):!0,lowercase:r=>r?/[a-z]/.test(r)?!0:e("passwordRequirement.lowercase","Password must contain at least one lowercase letter"):!0,number:r=>r?/[0-9]/.test(r)?!0:e("passwordRequirement.number","Password must contain at least one number"):!0,special:r=>r?/[^a-zA-Z0-9]/.test(r)?!0:e("passwordRequirement.special","Password must contain at least one special character"):!0,breached:async r=>!r||r.length<8?!0:await Be(r)?e("errors.breached_password","This password has appeared in a data breach. Please choose a different password."):!0}:void 0},render:({field:r})=>{const u=`password-${r.name}`;return n(o,{gap:"tight",children:[i(ue,{...r,id:u,label:e("password","Password"),placeholder:e("passwordPlaceholder","Enter your password"),autoComplete:w?"new-password":"current-password",disabled:c||k,"aria-invalid":!!s.password,"aria-describedby":s.password?"password-error":void 0,className:"dndev-w-full","data-variant":s.password?"destructive":void 0}),s.password&&i(b,{as:"span",level:"caption",variant:"destructive",id:"password-error",role:"alert",children:s.password.message})]})}}),w&&i(W,{name:"confirmPassword",control:R,rules:{required:e("confirmPasswordRequired","Please confirm your password"),validate:r=>{const u=Re("password");return r!==u?e("confirmPasswordMismatch","Passwords do not match"):!0}},render:({field:r})=>n(o,{gap:"tight",children:[i(ue,{...r,label:e("confirmPassword","Confirm Password"),placeholder:e("confirmPasswordPlaceholder","Re-enter your password"),autoComplete:"new-password",disabled:c,"aria-invalid":!!s.confirmPassword,"aria-describedby":s.confirmPassword?"confirm-password-error":void 0,className:"dndev-w-full","data-variant":s.confirmPassword?"destructive":void 0}),s.confirmPassword&&i(b,{as:"span",level:"caption",variant:"destructive",id:"confirm-password-error",role:"alert",children:s.confirmPassword.message})]})}),w&&re&&i(je,{password:re,minLength:8,showRequirements:!0}),ie&&n(ne,{children:[n(o,{direction:"row",gap:"tight",align:"start",children:[i(le,{id:"tos-accept",checked:K,onCheckedChange:r=>G(r===!0),disabled:c}),i(ce,{htmlFor:"tos-accept",children:n(b,{as:"span",level:"caption",children:[e("terms.accept_prefix","I accept the")," ",C&&i(g,{type:"button",variant:f.LINK,onClick:()=>{Z?B(!0):X&&window.open(X,"_blank","noopener,noreferrer")},className:"dndev-p-0 dndev-h-auto",style:{minHeight:"auto",padding:0,display:"inline"},children:e("terms.tos","Terms of Service")}),C&&S&&n(ne,{children:[" ",e("terms.and","and")," "]}),S&&i(g,{type:"button",variant:f.LINK,onClick:()=>{Y?z(!0):J&&window.open(J,"_blank","noopener,noreferrer")},className:"dndev-p-0 dndev-h-auto",style:{minHeight:"auto",padding:0,display:"inline"},children:e("terms.privacy","Privacy Policy")})]})})]}),Z&&i(de,{open:Pe,onOpenChange:B,title:e("terms.tos","Terms of Service"),showClose:!0,children:P}),Y&&i(de,{open:_e,onOpenChange:z,title:e("terms.privacy","Privacy Policy"),showClose:!0,children:_})]}),!w&&n(o,{direction:"row",gap:"tight",align:"center",children:[i(le,{id:"remember-me",checked:q,onCheckedChange:r=>ke(r===!0),disabled:c||k}),i(ce,{htmlFor:"remember-me",children:e("rememberMe","Remember me")})]}),i(g,{type:"submit",variant:f.PRIMARY,disabled:Te,fullWidth:!0,children:c?e("loading","Loading..."):w?e("actions.sign_up_submit","Sign Up"):e("actions.sign_in_submit","Sign In")}),!w&&n(o,{direction:"row",gap:"tight",justify:"center",align:"center",children:[i(g,{type:"button",variant:f.LINK,disabled:c||k,onClick:Ee,children:k?e("loading","Loading..."):e("forgotPassword","Forgot password?")}),i(b,{as:"span",variant:"muted",children:"|"}),i(g,{type:"button",variant:f.LINK,disabled:c,onClick:()=>O("signup"),children:e("actions.sign_up_submit","Sign Up")})]}),w&&i(o,{align:"center",children:i(g,{type:"button",variant:f.LINK,disabled:c,onClick:()=>O("signin"),children:e("alreadyHaveAccount","Already have an account? Sign In")})})]})]})})}var Xe=Ye;export{Xe as default};
1
+ "use client";import{jsx as e,jsxs as n}from"react/jsx-runtime";import{useState as A}from"react";import{Button as x,BUTTON_VARIANT as B,Stack as m,Text as w}from"@donotdev/components";import{useTranslation as L}from"@donotdev/core";import{AuthConfirmPasswordField as R,AuthConsentField as U,AuthEmailField as d,AuthForm as h,AuthFormAlerts as p,AuthPasswordField as v,AuthRememberMeField as V,AuthSubmitButton as g}from"../emailAuth/fields";import{AUTH_FIELD as _,useEmailSignIn as j,useEmailSignUp as C,usePasswordResetRequest as H}from"../emailAuth/flows";const M=r=>{const s=r.currentTarget.form?.elements.namedItem(_.EMAIL);return s instanceof HTMLInputElement?s.value:""};function q({mode:r="signin",onSuccess:s,onError:F,className:o,tos:T,privacy:E,captchaToken:I}){const{t:a}=L("auth"),[f,S]=A(r),[i,k]=A(""),l={onSuccess:()=>s?.(void 0),onError:F,captchaToken:I},y=j(l),N=C(l),b=H(l),P=u=>c=>{k(M(c)),S(u)},t=(u,c)=>e(x,{type:"button",variant:B.LINK,onClick:P(c),children:u});return f==="reset"?n(h,{flow:b,className:o,children:[e(w,{variant:"muted",children:a("forgotPassword.intro","Enter your email and we will send you a reset link.")}),e(d,{defaultValue:i}),e(p,{}),e(g,{}),e(m,{align:"center",children:t(a("back","Back"),"signin")})]},"reset"):f==="signup"?n(h,{flow:N,className:o,children:[e(d,{defaultValue:i}),e(v,{}),e(R,{}),e(U,{tos:T,privacy:E}),e(p,{}),e(g,{}),e(m,{align:"center",children:t(a("alreadyHaveAccount","Already have an account? Sign In"),"signin")})]},"signup"):n(h,{flow:y,className:o,children:[e(d,{defaultValue:i}),e(v,{}),e(V,{}),e(p,{}),e(g,{}),n(m,{direction:"row",gap:"tight",justify:"center",align:"center",children:[t(a("forgotPassword","Forgot password?"),"reset"),e(w,{as:"span",variant:"muted",children:"|"}),t(a("actions.sign_up_submit","Sign Up"),"signup")]})]},"signin")}var D=q;export{D as default};
@@ -1 +1 @@
1
- "use client";import{Fragment as t,jsx as s}from"react/jsx-runtime";import{useImperativeHandle as o,forwardRef as i}from"react";import{hasTierAccess as f}from"@donotdev/core";import{useAuth as c}from"../useAuth";const p=i(({featureId:e,fallback:r=null,children:l},n)=>{const a=c("userSubscription")?.features?.includes(e)||!1;return o(n,()=>({enabled:a}),[a]),a?s(t,{children:l}):r?s(t,{children:r}):null}),m=i(({tier:e,fallback:r=null,children:l},n)=>{const a=c("userSubscription"),d=e||"pro",u=f(a?.tier,d);return o(n,()=>({enabled:u}),[u]),u?s(t,{children:l}):r?s(t,{children:r}):null}),h=i((e,r)=>s(m,{ref:r,tier:"pro",...e})),b=i((e,r)=>s(m,{ref:r,tier:"premium",...e}));export{p as Feature,b as PremiumFeature,h as ProFeature};
1
+ "use client";import{Fragment as t,jsx as s}from"react/jsx-runtime";import{useImperativeHandle as o,forwardRef as i}from"react";import{hasTierAccess as f}from"@donotdev/core";import{useAuth as c}from"../useAuth";const p=i(({featureId:e,fallback:r=null,children:n},l)=>{const a=c("userSubscription")?.features?.includes(e)||!1;return o(l,()=>({enabled:a}),[a]),a?s(t,{children:n}):r?s(t,{children:r}):null}),m=i(({tier:e,fallback:r=null,children:n},l)=>{const a=c("userSubscription"),d=e||"pro",u=f(a?.tier,d);return o(l,()=>({enabled:u}),[u]),u?s(t,{children:n}):r?s(t,{children:r}):null}),h=i((e,r)=>s(m,{ref:r,tier:"pro",...e})),b=i((e,r)=>s(m,{ref:r,tier:"premium",...e}));export{p as Feature,b as PremiumFeature,h as ProFeature};
@@ -1 +1 @@
1
- "use client";import{jsx as a,jsxs as k}from"react/jsx-runtime";import{Suspense as S,lazy as $,useId as y}from"react";import{Alert as E,ALERT_VARIANT as P,Stack as c,Grid as T}from"@donotdev/components";import{useTranslation as j,getEnabledAuthPartners as C}from"@donotdev/core";import{useAuth as m}from"../useAuth";import{withAuthFallback as G}from"./AuthFallback";import M from"./AuthPartnerButton";import{getAuthMethod as O}from"../constants";import{useAccountLinking as q}from"../hooks/useAccountLinking";const B=$(()=>import("./AccountLinking")),F=({providers:h,containerClassName:e="",providerClassName:p="",method:g,size:_="md",layout:r="vertical",showLabels:f=!0,spacing:o="medium",ariaLabel:v,id:A,fullWidth:b=!0,onSuccess:N})=>{const{t:s}=j("auth"),w=y(),n=A||w,{isRequired:R}=q(),l=m("error"),x=m("isAvailable"),z=O(g),i=h||C();if(!i||i.length===0)return a("div",{className:e,children:a("p",{children:"No authentication providers are configured"})});const I=()=>{const d=i.map((t,L)=>a(M,{partnerId:t,method:z,className:`${p} ${b?"dndev-w-full":""}`,tabIndex:L===0?0:void 0,id:`${n}-${t}-button`,onSuccess:N,children:f?void 0:null},t));return r==="grid"?a(T,{cols:2,gap:o,className:e,children:d}):a(c,{direction:r==="horizontal"?"row":"column",wrap:r==="horizontal"?"wrap":void 0,gap:o,align:r==="horizontal"?"center":"stretch",className:e,children:d})};return k(c,{className:"dndev-mx-auto",id:n,role:"region","aria-label":v||s("aria.signInOptions","Sign in options"),children:[I(),l&&x&&a(E,{variant:P.ERROR,description:l.message||s("errorGeneric","Authentication failed. Please try again.")}),R&&a(S,{fallback:null,children:a(B,{})})]})},u=G(F,{message:"Authentication providers are not configured",showLoginButton:!0});var V=u;export{u as MultipleAuthProviders,V as default};
1
+ "use client";import{jsx as a,jsxs as S}from"react/jsx-runtime";import{Suspense as $,lazy as k,useId as y}from"react";import{Alert as E,ALERT_VARIANT as P,Stack as c,Grid as T}from"@donotdev/components";import{useTranslation as j,getEnabledAuthPartners as C}from"@donotdev/core";import{useAuth as m}from"../useAuth";import{withAuthFallback as G}from"./AuthFallback";import M from"./AuthPartnerButton";import{getAuthMethod as O}from"../constants";import{useAccountLinking as q}from"../hooks/useAccountLinking";const B=k(()=>import("./AccountLinking")),F=({providers:h,containerClassName:e="",providerClassName:p="",method:g,size:_="md",layout:r="vertical",showLabels:f=!0,spacing:o="medium",ariaLabel:v,id:A,fullWidth:b=!0,onSuccess:N})=>{const{t:s}=j("auth"),w=y(),n=A||w,{isRequired:R}=q(),l=m("error"),x=m("isAvailable"),z=O(g),i=h||C();if(!i||i.length===0)return a("div",{className:e,children:a("p",{children:"No authentication providers are configured"})});const I=()=>{const d=i.map((t,L)=>a(M,{partnerId:t,method:z,className:`${p} ${b?"dndev-w-full":""}`,tabIndex:L===0?0:void 0,id:`${n}-${t}-button`,onSuccess:N,children:f?void 0:null},t));return r==="grid"?a(T,{cols:2,gap:o,className:e,children:d}):a(c,{direction:r==="horizontal"?"row":"column",wrap:r==="horizontal"?"wrap":void 0,gap:o,align:r==="horizontal"?"center":"stretch",className:e,children:d})};return S(c,{className:"dndev-mx-auto",id:n,role:"region","aria-label":v||s("aria.signInOptions","Sign in options"),children:[I(),l&&x&&a(E,{variant:P.ERROR,description:l.message||s("errorGeneric","Authentication failed. Please try again.")}),R&&a($,{fallback:null,children:a(B,{})})]})},u=G(F,{message:"Authentication providers are not configured",showLoginButton:!0});var V=u;export{u as MultipleAuthProviders,V as default};
@@ -1 +1 @@
1
- {"version":3,"file":"PasswordResetCallback.d.ts","sourceRoot":"","sources":["../../src/components/PasswordResetCallback.tsx"],"names":[],"mappings":"AAoJA;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,uCAgXpC"}
1
+ {"version":3,"file":"PasswordResetCallback.d.ts","sourceRoot":"","sources":["../../src/components/PasswordResetCallback.tsx"],"names":[],"mappings":"AAsHA;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,uCAgXpC"}
@@ -1,2 +1 @@
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{useAuthStore as V}from"../AuthStore";import{useAuth as f}from"../useAuth";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
+ "use client";import{jsx as s,jsxs as i}from"react/jsx-runtime";import{useCallback as L,useEffect as U,useState as m}from"react";import{useForm as j,Controller as N,useWatch as z}from"react-hook-form";import{Alert as R,ALERT_VARIANT as C,Button as S,BUTTON_VARIANT as _,Dialog as F,PasswordInput as V,Spinner as Z,Stack as l,Text as g}from"@donotdev/components";import{useTranslation as G}from"@donotdev/core";import{useAuthStore as O}from"../AuthStore";import{isBreachedPassword as X}from"../emailAuth/rules";import{useAuth as h}from"../useAuth";import{PasswordStrengthIndicator as $}from"./PasswordStrengthIndicator";function H(){if(typeof window>"u")return{type:null};const r=window.location.hash.slice(1);if(r){const n=new URLSearchParams(r),p=n.get("error_code");if(p){const f={type:"supabase_error",errorCode:p,errorDescription:n.get("error_description")?.replace(/\+/g," ")||void 0};return window.history.replaceState(null,"",window.location.pathname+window.location.search),f}if(n.get("type")==="recovery")return window.history.replaceState(null,"",window.location.pathname+window.location.search),{type:"supabase_recovery"}}const c=new URLSearchParams(window.location.search),w=c.get("oobCode");return w&&c.get("mode")==="resetPassword"?{type:"firebase",oobCode:w}:{type:null}}function J(){const{t:r}=G("auth"),c=h("passwordResetPending"),w=h("verifyPasswordResetCode"),n=h("confirmPasswordReset"),p=h("updatePassword"),f=h("signInWithEmail"),[a,t]=m("idle"),[u,x]=m(null),[v,A]=m(null),[q,W]=m(!1),[M,k]=m(null),{control:y,handleSubmit:Y,getValues:B,formState:{errors:o,isSubmitting:P},setError:E}=j({mode:"onChange",defaultValues:{password:"",confirmPassword:""}}),I=z({control:y,name:"password"});U(()=>{if(a!=="idle")return;const e=H();if(e.type==="supabase_error"){e.errorCode==="otp_expired"?t("expired"):(k(e.errorDescription||null),t("invalid"));return}if(e.type==="firebase"&&e.oobCode){W(!0),A(e.oobCode),t("loading"),w(e.oobCode).then(d=>{d?(x(d),t("ready")):t("expired")});return}c&&t("ready")},[c,a,w]);const D=L(async e=>{try{if(q&&v){if(await n(v,e.password),u)try{await f(u,e.password)}catch{}}else await p(e.password),O.getState().setPasswordResetPending(!1);t("idle")}catch(d){const T=d instanceof Error?d.message:String(d);T.includes("expired")||T.includes("EXPIRED")?t("expired"):E("root",{message:r("resetPassword.error","Failed to reset password. Please try again.")})}},[q,v,u,n,p,f,E,r]),b=L(()=>{t("idle"),x(null),A(null),k(null),O.getState().setPasswordResetPending(!1),typeof window<"u"&&window.history.replaceState(null,"",window.location.pathname)},[]);return a==="idle"?null:i(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"&&i(l,{align:"center",justify:"center",children:[s(Z,{}),s(g,{level:"body",variant:"muted",children:r("resetPassword.verifying","Verifying reset link...")})]}),(a==="expired"||a==="invalid")&&i(l,{children:[s(R,{variant:C.WARNING,description:a==="expired"?r("resetPassword.expired_description","This password reset link has expired. Please request a new one."):M||r("resetPassword.invalid_description","This password reset link is invalid. Please request a new one.")}),s(S,{variant:_.PRIMARY,onClick:b,fullWidth:!0,children:r("resetPassword.back_to_signin","Back to Sign In")})]}),a==="success"&&i(l,{children:[s(R,{variant:C.SUCCESS,description:r("resetPassword.success_description","Your password has been reset successfully. You are now signed in.")}),s(S,{variant:_.PRIMARY,onClick:b,fullWidth:!0,children:r("resetPassword.continue","Continue")})]}),a==="ready"&&s("form",{onSubmit:Y(D),noValidate:!0,children:i(l,{children:[u&&s(g,{level:"small",variant:"muted",children:r("resetPassword.for_email",`Enter a new password for ${u}`)}),o.root&&s(R,{variant:C.ERROR,description:o.root.message}),s(N,{name:"password",control:y,rules:{required:r("passwordRequired","Password is required"),minLength:{value:8,message:r("passwordMinLength",{defaultValue:"Password must be at least 8 characters",count:8})},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})=>i(l,{gap:"tight",children:[s(V,{...e,label:r("resetPassword.new_password","New password"),placeholder:r("passwordPlaceholder","Enter your password"),autoComplete:"new-password",disabled:P,"aria-invalid":!!o.password,"aria-describedby":o.password?"reset-password-error":void 0,className:"dndev-w-full","data-variant":o.password?"destructive":void 0}),o.password&&s(g,{as:"span",level:"caption",variant:"destructive",id:"reset-password-error",role:"alert",children:o.password.message})]})}),s(N,{name:"confirmPassword",control:y,rules:{required:r("confirmPasswordRequired","Please confirm your password"),validate:e=>e===B("password")||r("confirmPasswordMismatch","Passwords do not match")},render:({field:e})=>i(l,{gap:"tight",children:[s(V,{...e,label:r("confirmPassword","Confirm password"),placeholder:r("confirmPasswordPlaceholder","Re-enter your password"),autoComplete:"new-password",disabled:P,"aria-invalid":!!o.confirmPassword,"aria-describedby":o.confirmPassword?"reset-confirm-error":void 0,className:"dndev-w-full","data-variant":o.confirmPassword?"destructive":void 0}),o.confirmPassword&&s(g,{as:"span",level:"caption",variant:"destructive",id:"reset-confirm-error",role:"alert",children:o.confirmPassword.message})]})}),I&&s($,{password:I,minLength:8,showRequirements:!0}),s(S,{type:"submit",variant:_.PRIMARY,disabled:P,fullWidth:!0,children:P?r("loading","Loading..."):r("resetPassword.submit","Reset Password")})]})})]})}export{J as PasswordResetCallback};
@@ -1 +1 @@
1
- {"version":3,"file":"PasswordStrengthIndicator.d.ts","sourceRoot":"","sources":["../../src/components/PasswordStrengthIndicator.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,8BAA8B;IAC7C,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AAwFnE;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,QAAQ,EACR,SAAa,EACb,gBAAuB,EACvB,SAAS,GACV,EAAE,8BAA8B,+BAgFhC"}
1
+ {"version":3,"file":"PasswordStrengthIndicator.d.ts","sourceRoot":"","sources":["../../src/components/PasswordStrengthIndicator.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,8BAA8B;IAC7C,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,8BAA8B;IAC9B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6CAA6C;IAC7C,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,uBAAuB;IACvB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAC;AA6FnE;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,QAAQ,EACR,SAAa,EACb,gBAAuB,EACvB,SAAS,GACV,EAAE,8BAA8B,+BAkFhC"}
@@ -1 +1 @@
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 N={weak:25,fair:50,good:75,strong:100},g={weak:"destructive",fair:"warning",good:"accent",strong:"success"};function x({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:N[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{x as PasswordStrengthIndicator};
1
+ "use client";import{jsxs as r,jsx as i}from"react/jsx-runtime";import{Check as v,Circle as f}from"lucide-react";import{useMemo as m}from"react";import{Progress as b,Stack as o,Text as l,cn as q}from"@donotdev/components";import{useTranslation as k}from"@donotdev/core";function S(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 N(e,t,s){return[{label:s("passwordRequirement.length",`At least ${t} characters`,{count:t}),met:e.length>=t},{label:s("passwordRequirement.uppercase","One uppercase letter"),met:/[A-Z]/.test(e)},{label:s("passwordRequirement.lowercase","One lowercase letter"),met:/[a-z]/.test(e)},{label:s("passwordRequirement.number","One number"),met:/[0-9]/.test(e)},{label:s("passwordRequirement.special","One special character (!@#$%^&*)"),met:/[^a-zA-Z0-9]/.test(e)}]}const R={weak:25,fair:50,good:75,strong:100},g={weak:"destructive",fair:"warning",good:"accent",strong:"success"};function x({password:e,minLength:t=8,showRequirements:s=!0,className:p}){const{t:a}=k("auth"),d=m(()=>S(e),[e]),u=m(()=>N(e,t,(n,c,w)=>a(n,{defaultValue:c||"",...w})),[e,t,a]),h={weak:a("passwordStrength.weak","Weak"),fair:a("passwordStrength.fair","Fair"),good:a("passwordStrength.good","Good"),strong:a("passwordStrength.strong","Strong")};return r(o,{gap:"tight",className:q("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:[a("passwordStrength.label","Password strength"),":"]}),i(l,{as:"strong",level:"caption",variant:g[d],children:h[d]})]}),i(b,{value:R[d],variant:g[d],className:"dndev-password-strength-bar"})]}),s&&r(o,{gap:"tight",className:"dndev-password-requirements",children:[r(l,{as:"strong",level:"caption",variant:"muted",children:[a("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(v,{className:"dndev-size-xs","data-variant":"success"}):i(f,{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{x as PasswordStrengthIndicator};
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAGhE,OAAO,EAAE,aAAa,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,YAAY,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EACL,kBAAkB,IAAI,aAAa,EACnC,KAAK,gBAAgB,IAAI,YAAY,GACtC,MAAM,gBAAgB,CAAC;AAMxB;;;;;;GAMG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAC;AAExD;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,CAAC;AAE3C;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,CAAC;AAE1C;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,0CAA0C;IAC1C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,6BAA6B;IAC7B,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,4CAA4C;IAC5C,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,IAAI,C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B,wDAAwD;IACxD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,iEAAiE;IACjE,SAAS,CAAC,EAAE,aAAa,EAAE,CAAC;IAC5B,yCAAyC;IACzC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,108 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { EmailAuthFlow } from './flows';
3
+ /** Props of {@link AuthForm}. */
4
+ export interface AuthFormProps {
5
+ /** The flow this form runs (`useEmailSignIn()`, `useEmailSignUp()`, ...) */
6
+ flow: EmailAuthFlow;
7
+ /** Fields, app content, alerts, submit button */
8
+ children: ReactNode;
9
+ className?: string;
10
+ }
11
+ /**
12
+ * The `<form>` of an email auth flow. A real form, so password managers pair the
13
+ * fields and Enter submits. Shows an "unavailable" notice instead when the auth
14
+ * provider failed to start.
15
+ *
16
+ * @param props - AuthFormProps
17
+ * @returns The form
18
+ */
19
+ export declare function AuthForm({ flow, children, className }: AuthFormProps): import("react").JSX.Element;
20
+ /** Props shared by the text fields. */
21
+ export interface AuthTextFieldProps {
22
+ /** Label (default: translated "Email" / "Password") */
23
+ label?: string;
24
+ /** Placeholder (default: translated) */
25
+ placeholder?: string;
26
+ /** Initial value */
27
+ defaultValue?: string;
28
+ }
29
+ /**
30
+ * Email field (`name="email"`, `autocomplete="username"`: the identifier password
31
+ * managers pair with the password).
32
+ *
33
+ * @param props - AuthTextFieldProps
34
+ * @returns The field
35
+ */
36
+ export declare function AuthEmailField({ label, placeholder, defaultValue, }: AuthTextFieldProps): import("react").JSX.Element;
37
+ /**
38
+ * Password field. Sign-in: `current-password`. Sign-up: `new-password` and a strength
39
+ * meter with the policy requirements.
40
+ *
41
+ * @param props - AuthTextFieldProps
42
+ * @returns The field
43
+ */
44
+ export declare function AuthPasswordField({ label, placeholder }: AuthTextFieldProps): import("react").JSX.Element;
45
+ /**
46
+ * Second password entry (sign-up, `name="confirmPassword"`). Rendering it makes the
47
+ * flow require a match.
48
+ *
49
+ * @param props - AuthTextFieldProps
50
+ * @returns The field
51
+ */
52
+ export declare function AuthConfirmPasswordField({ label, placeholder, }: AuthTextFieldProps): import("react").JSX.Element;
53
+ /** Props of {@link AuthRememberMeField}. */
54
+ export interface AuthRememberMeFieldProps {
55
+ /** Label (default: translated "Remember me") */
56
+ label?: string;
57
+ /**
58
+ * Initial state.
59
+ * @default true (sessions persist unless the user opts out)
60
+ */
61
+ defaultChecked?: boolean;
62
+ }
63
+ /**
64
+ * "Remember me" (sign-in, `name="rememberMe"`). Rendered only when the auth provider
65
+ * can honour it; unticked = the session ends with the browser session.
66
+ *
67
+ * @param props - AuthRememberMeFieldProps
68
+ * @returns The checkbox, or nothing when the provider cannot do it
69
+ */
70
+ export declare function AuthRememberMeField({ label, defaultChecked, }: AuthRememberMeFieldProps): import("react").JSX.Element | null;
71
+ /** Legal document: a path (opened in a new tab) or content (shown in a dialog). */
72
+ export type AuthLegalDocument = string | ReactNode;
73
+ /** Props of {@link AuthConsentField}. */
74
+ export interface AuthConsentFieldProps {
75
+ /** Terms of Service. Omit: from app config legal links, else `/legal/terms`. `false`: none */
76
+ tos?: AuthLegalDocument | false;
77
+ /** Privacy policy. Omit: from app config legal links, else `/legal/privacy`. `false`: none */
78
+ privacy?: AuthLegalDocument | false;
79
+ }
80
+ /**
81
+ * Terms / privacy consent (sign-up, `name="consent"`, GDPR). Rendering it makes the
82
+ * flow require it and record `gdpr_consent_at`.
83
+ *
84
+ * @param props - AuthConsentFieldProps
85
+ * @returns The checkbox and links, or nothing when both documents are `false`
86
+ */
87
+ export declare function AuthConsentField({ tos, privacy }: AuthConsentFieldProps): import("react").JSX.Element | null;
88
+ /**
89
+ * Form-level messages: provider error / throttle, and a resend action when sign-in
90
+ * failed on an unconfirmed address.
91
+ *
92
+ * @returns The alerts, or nothing
93
+ */
94
+ export declare function AuthFormAlerts(): import("react").JSX.Element | null;
95
+ /** Props of {@link AuthSubmitButton}. */
96
+ export interface AuthSubmitButtonProps {
97
+ /** Label (default: translated per flow) */
98
+ children?: ReactNode;
99
+ }
100
+ /**
101
+ * Submit button: full width, loading while the flow runs, disabled until the provider
102
+ * is ready and while CAPTCHA / throttle block.
103
+ *
104
+ * @param props - AuthSubmitButtonProps
105
+ * @returns The button
106
+ */
107
+ export declare function AuthSubmitButton({ children }: AuthSubmitButtonProps): import("react").JSX.Element;
108
+ //# sourceMappingURL=fields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/emailAuth/fields.tsx"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAqBvC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAW7C,iCAAiC;AACjC,MAAM,WAAW,aAAa;IAC5B,4EAA4E;IAC5E,IAAI,EAAE,aAAa,CAAC;IACpB,iDAAiD;IACjD,QAAQ,EAAE,SAAS,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,aAAa,+BAyBpE;AAYD,uCAAuC;AACvC,MAAM,WAAW,kBAAkB;IACjC,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oBAAoB;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,EAC7B,KAAK,EACL,WAAW,EACX,YAAY,GACb,EAAE,kBAAkB,+BAyBpB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,kBAAkB,+BAuC3E;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,EACvC,KAAK,EACL,WAAW,GACZ,EAAE,kBAAkB,+BA0BpB;AAED,4CAA4C;AAC5C,MAAM,WAAW,wBAAwB;IACvC,gDAAgD;IAChD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,cAAqB,GACtB,EAAE,wBAAwB,sCAa1B;AASD,mFAAmF;AACnF,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,SAAS,CAAC;AAEnD,yCAAyC;AACzC,MAAM,WAAW,qBAAqB;IACpC,8FAA8F;IAC9F,GAAG,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC;IAChC,8FAA8F;IAC9F,OAAO,CAAC,EAAE,iBAAiB,GAAG,KAAK,CAAC;CACrC;AAmCD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,qBAAqB,sCA6CvE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,uCAmB7B;AAED,yCAAyC;AACzC,MAAM,WAAW,qBAAqB;IACpC,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,QAAQ,EAAE,EAAE,qBAAqB,+BAoBnE"}
@@ -0,0 +1 @@
1
+ "use client";import{jsx as n,jsxs as u,Fragment as A}from"react/jsx-runtime";import{createContext as L,use as M,useId as m,useState as R}from"react";import{Alert as E,ALERT_VARIANT as P,Button as w,BUTTON_VARIANT as y,Checkbox as C,Dialog as x,Input as O,Label as V,PasswordInput as I,Stack as h,Text as N,cn as B}from"@donotdev/components";import{useAppConfig as D,useTranslation as p}from"@donotdev/core";import{useAuth as U}from"../useAuth";import{PasswordStrengthIndicator as W}from"../components/PasswordStrengthIndicator";import{AUTH_FIELD as v}from"./flows";const S=L(null);function b(){const t=M(S);if(!t)throw new Error("Auth fields must be rendered inside <AuthForm>");return t}function j({flow:t,children:e,className:a}){const{t:i}=p("auth");return t.unavailable?n(E,{variant:P.WARNING,title:i("unavailable.title","Authentication Unavailable"),description:i("unavailable.description","Sign-in is temporarily unavailable. Please try again later.")}):n(S,{value:t,children:n("form",{noValidate:!0,onSubmit:t.onSubmit,className:B("dndev-auth-form",a),children:n(h,{children:e})})})}function g({id:t,message:e}){return e?n(N,{as:"span",level:"caption",variant:"destructive",id:t,role:"alert",children:e}):null}function H({label:t,placeholder:e,defaultValue:a}){const{t:i}=p("auth"),r=b(),l=m(),s=m(),o=r.fieldErrors.email;return u(h,{gap:"tight",children:[n(O,{id:l,name:v.EMAIL,type:"email",autoComplete:"username",label:t??i("email","Email"),placeholder:e??i("emailPlaceholder","Enter your email"),defaultValue:a,disabled:r.busy,"aria-invalid":!!o,"aria-describedby":o?s:void 0,"data-variant":o?"destructive":void 0,className:"dndev-w-full"}),n(g,{id:s,message:o})]})}function K({label:t,placeholder:e}){const{t:a}=p("auth"),i=b(),r=m(),l=m(),[s,o]=R(""),c=i.mode==="signup",d=i.fieldErrors.password;return u(h,{gap:"tight",children:[n(I,{id:r,name:v.PASSWORD,autoComplete:c?"new-password":"current-password",label:t??a("password","Password"),placeholder:e??a("passwordPlaceholder","Enter your password"),onInput:c?f=>o(f.target.value):void 0,disabled:i.busy,"aria-invalid":!!d,"aria-describedby":d?l:void 0,"data-variant":d?"destructive":void 0,className:"dndev-w-full"}),n(g,{id:l,message:d}),c&&s!==""&&n(W,{password:s,minLength:i.passwordMinLength,showRequirements:!0})]})}function q({label:t,placeholder:e}){const{t:a}=p("auth"),i=b(),r=m(),l=m(),s=i.fieldErrors.confirmPassword;return u(h,{gap:"tight",children:[n(I,{id:r,name:v.CONFIRM_PASSWORD,autoComplete:"new-password",label:t??a("confirmPassword","Confirm Password"),placeholder:e??a("confirmPasswordPlaceholder","Re-enter your password"),disabled:i.busy,"aria-invalid":!!s,"aria-describedby":s?l:void 0,"data-variant":s?"destructive":void 0,className:"dndev-w-full"}),n(g,{id:l,message:s})]})}function G({label:t,defaultChecked:e=!0}){const{t:a}=p("auth"),i=b(),r=U("canRememberMe");return!i.ready||!r()?null:n(C,{name:v.REMEMBER_ME,defaultChecked:e,disabled:i.busy,label:t??a("rememberMe","Remember me")})}const Y={minHeight:"auto",padding:0,display:"inline"};function F({label:t,document:e}){const[a,i]=R(!1),r=typeof e=="string";return u(A,{children:[n(w,{type:"button",variant:y.LINK,onClick:()=>r?window.open(e,"_blank","noopener,noreferrer"):i(!0),className:"dndev-p-0 dndev-h-auto",style:Y,children:t}),!r&&n(x,{open:a,onOpenChange:i,title:t,showClose:!0,children:e})]})}function Q({tos:t,privacy:e}){const{t:a}=p("auth"),i=b(),r=D("app"),l=m(),s=m(),o=(_,T)=>r?.footer?.legalLinks?.find(k=>k.path.includes(_))?.path??T,c=t===void 0?o("terms","/legal/terms"):t,d=e===void 0?o("privacy","/legal/privacy"):e;if(c===!1&&d===!1)return null;const f=i.fieldErrors.consent;return u(h,{gap:"tight",children:[u(h,{direction:"row",gap:"tight",align:"start",children:[n(C,{id:l,name:v.CONSENT,disabled:i.busy,"aria-invalid":!!f,"aria-describedby":f?s:void 0}),n(V,{htmlFor:l,children:u(N,{as:"span",level:"caption",children:[a("terms.accept_prefix","I accept the")," ",c!==!1&&n(F,{label:a("terms.tos","Terms of Service"),document:c}),c!==!1&&d!==!1&&u(A,{children:[" ",a("terms.and","and")," "]}),d!==!1&&n(F,{label:a("terms.privacy","Privacy Policy"),document:d})]})})]}),n(g,{id:s,message:f})]})}function X(){const{t}=p("auth"),e=b();if(!e.error)return null;const a=e.unconfirmedEmail;return u(h,{gap:"tight",children:[n(E,{variant:P.ERROR,description:e.error}),a&&n(w,{type:"button",variant:y.LINK,onClick:()=>{e.resendVerification(a)},children:t("signup.resend_verification","Resend verification email")})]})}function Z({children:t}){const{t:e}=p("auth"),a=b(),i=a.mode==="signup"?e("actions.sign_up_submit","Sign Up"):a.mode==="reset"?e("forgotPassword.submit","Send reset link"):e("actions.sign_in_submit","Sign In");return n(w,{type:"submit",variant:y.PRIMARY,fullWidth:!0,loading:a.busy,disabled:!a.ready||a.blocked,children:t??i})}export{q as AuthConfirmPasswordField,Q as AuthConsentField,H as AuthEmailField,j as AuthForm,X as AuthFormAlerts,K as AuthPasswordField,G as AuthRememberMeField,Z as AuthSubmitButton};
@@ -0,0 +1,120 @@
1
+ import type { FormEvent } from 'react';
2
+ import type { SignUpMetadata } from '@donotdev/core';
3
+ /** Field names the flows read from the submitted form. */
4
+ export declare const AUTH_FIELD: {
5
+ readonly EMAIL: "email";
6
+ readonly PASSWORD: "password";
7
+ readonly CONFIRM_PASSWORD: "confirmPassword";
8
+ readonly REMEMBER_ME: "rememberMe";
9
+ readonly CONSENT: "consent";
10
+ };
11
+ /** Which flow a form runs. */
12
+ export type EmailAuthMode = 'signin' | 'signup' | 'reset';
13
+ /** Per-field validation messages, keyed by field name. */
14
+ export interface AuthFieldErrors {
15
+ email?: string;
16
+ password?: string;
17
+ confirmPassword?: string;
18
+ consent?: string;
19
+ }
20
+ /** Options shared by every flow. */
21
+ export interface EmailAuthFlowOptions {
22
+ /** Called once the flow succeeded: close the dialog / sheet here */
23
+ onSuccess?: () => void;
24
+ /** Called with the provider error after a failed attempt */
25
+ onError?: (error: Error) => void;
26
+ /**
27
+ * CAPTCHA token. `undefined` = no CAPTCHA; while it is `null` / empty the submit is
28
+ * blocked. The app renders the widget.
29
+ */
30
+ captchaToken?: string | null;
31
+ }
32
+ /** Outcome of a successful sign-up. */
33
+ export interface EmailSignUpOutcome {
34
+ /**
35
+ * The address must be confirmed before the user can sign in (no session yet). The
36
+ * flow already showed the "check your email" toast with Resend.
37
+ */
38
+ awaitingConfirmation: boolean;
39
+ }
40
+ /** Options of {@link useEmailSignUp}. */
41
+ export interface EmailSignUpOptions extends Omit<EmailAuthFlowOptions, 'onSuccess'> {
42
+ /** Called once sign-up succeeded: close the dialog / sheet here */
43
+ onSuccess?: (outcome: EmailSignUpOutcome) => void;
44
+ /** Minimum length of the new password (default 8) */
45
+ passwordMinLength?: number;
46
+ /** Extra sign-up metadata stored with the user (consent metadata is added for you) */
47
+ metadata?: SignUpMetadata;
48
+ /** The app's wording of the "check your email" toast (default: framework text) */
49
+ checkEmailMessage?: {
50
+ title: string;
51
+ description?: string;
52
+ };
53
+ }
54
+ /** What a form needs from a flow: pass it to `AuthForm`. */
55
+ export interface EmailAuthFlow {
56
+ /** The flow this is */
57
+ mode: EmailAuthMode;
58
+ /** Form submit handler */
59
+ onSubmit: (event: FormEvent<HTMLFormElement>) => void;
60
+ /** A submit is in progress */
61
+ busy: boolean;
62
+ /** The provider is ready (submit disabled until then) */
63
+ ready: boolean;
64
+ /** The provider failed to start: show an "unavailable" notice instead of the form */
65
+ unavailable: boolean;
66
+ /** Submit is blocked (CAPTCHA token missing, throttled) */
67
+ blocked: boolean;
68
+ /** Form-level error (provider error, throttle) */
69
+ error: string | null;
70
+ /** Per-field validation errors */
71
+ fieldErrors: AuthFieldErrors;
72
+ /** Address whose sign-in failed because it was never confirmed (offer a resend) */
73
+ unconfirmedEmail: string | null;
74
+ /** Resend the confirmation email to `email` and confirm with a toast */
75
+ resendVerification: (email: string) => Promise<void>;
76
+ /** Minimum new-password length (sign-up) */
77
+ passwordMinLength: number;
78
+ }
79
+ /**
80
+ * Email + password sign-in. Remember me is applied when the form renders
81
+ * `AuthRememberMeField`; an unconfirmed address offers a resend.
82
+ *
83
+ * @param options - Callbacks and CAPTCHA token
84
+ * @returns The flow, for `AuthForm`
85
+ *
86
+ * @example
87
+ * ```tsx
88
+ * const flow = useEmailSignIn({ onSuccess: close });
89
+ * <AuthForm flow={flow}>
90
+ * <AuthEmailField />
91
+ * <AuthPasswordField />
92
+ * <AuthRememberMeField />
93
+ * <AuthFormAlerts />
94
+ * <AuthSubmitButton />
95
+ * </AuthForm>
96
+ * ```
97
+ */
98
+ export declare function useEmailSignIn(options?: EmailAuthFlowOptions): EmailAuthFlow;
99
+ /**
100
+ * Email + password sign-up. Password policy and breached-password check apply; the
101
+ * confirmation field and consent are required when the form renders them.
102
+ *
103
+ * Anti-enumeration: an address that already has an account ends exactly like a new
104
+ * one ("check your email"). When the provider asks for confirmation, `onSuccess` runs
105
+ * and a toast that stays until dismissed tells the user to confirm, with Resend.
106
+ *
107
+ * @param options - Callbacks, CAPTCHA token, password minimum, extra metadata
108
+ * @returns The flow, for `AuthForm`
109
+ */
110
+ export declare function useEmailSignUp(options?: EmailSignUpOptions): EmailAuthFlow;
111
+ /**
112
+ * Password-reset request. Anti-enumeration: the same outcome whether or not the address
113
+ * has an account; `onSuccess` runs and a toast that stays until dismissed says to check
114
+ * the inbox.
115
+ *
116
+ * @param options - Callbacks and CAPTCHA token
117
+ * @returns The flow, for `AuthForm`
118
+ */
119
+ export declare function usePasswordResetRequest(options?: EmailAuthFlowOptions): EmailAuthFlow;
120
+ //# sourceMappingURL=flows.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/emailAuth/flows.tsx"],"names":[],"mappings":"AA0BA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAgBrD,0DAA0D;AAC1D,eAAO,MAAM,UAAU;;;;;;CAMb,CAAC;AAEX,8BAA8B;AAC9B,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE1D,0DAA0D;AAC1D,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,oCAAoC;AACpC,MAAM,WAAW,oBAAoB;IACnC,oEAAoE;IACpE,SAAS,CAAC,EAA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AAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,4CAA4C;IAC5C,iBAAiB,EAAE,MAAM,CAAC;CAC3B;AAoLD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAC5B,OAAO,GAAE,oBAAyB,GACjC,aAAa,CA+Bf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,kBAAuB,GAAG,aAAa,CAoF9E;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,oBAAyB,GACjC,aAAa,CAiCf"}
@@ -0,0 +1 @@
1
+ "use client";import{jsx as C}from"react/jsx-runtime";import{useEffect as F,useRef as V,useState as g}from"react";import{Button as q,ToastAction as x,toast as R}from"@donotdev/components";import{useTranslation as U}from"@donotdev/core";import{useAuth as E}from"../useAuth";import{DEFAULT_PASSWORD_MIN_LENGTH as O,authErrorMessage as W,isAlreadyRegisteredError as j,isBreachedPassword as B,isEmail as H,isRateLimitError as G,isUnconfirmedError as $,newPasswordError as z}from"./rules";const a={EMAIL:"email",PASSWORD:"password",CONFIRM_PASSWORD:"confirmPassword",REMEMBER_ME:"rememberMe",CONSENT:"consent"},J=6e4,K=5,Q=3e4;function X(){const e=V([]),[t,r]=g(null);return F(()=>{if(t===null)return;const s=setTimeout(()=>r(null),Math.max(0,t-Date.now()));return()=>clearTimeout(s)},[t]),{attempt:()=>{const s=Date.now();return t!==null&&s<t?Math.ceil((t-s)/1e3):(e.current=e.current.filter(u=>s-u<J),e.current.push(s),e.current.length>=K&&(e.current=[],r(s+Q)),0)},throttled:t!==null}}const Y=e=>e instanceof Error?e:new Error(String(e)),l=(e,t)=>{const r=e.get(t);return typeof r=="string"?r:""},T=(e,t)=>{const r=e.elements.namedItem(t);return r instanceof HTMLInputElement?r:void 0};function Z(){const{t:e}=U("auth");return(t,r,s)=>e(t,{defaultValue:r,...s})}function b(e,t){const r=Z(),s=E("isAvailable"),u=E("status"),m=E("sendEmailVerification"),f=X(),[c,o]=g(!1),[n,i]=g(null),[d,h]=g({}),[w,S]=g(null),v=t.captchaToken!==void 0&&!t.captchaToken,L=async p=>{try{await m(p),R("success",r("verificationSent","Verification email sent."))}catch(M){R("error",W(M,r))}};return{t:r,submit:async(p,M,N)=>{if(p.preventDefault(),c||v||!s)return;const P=p.currentTarget,A=new FormData(P),k=M(P,A);if(h(k),S(null),Object.keys(k).length>0){i(null);return}const I=f.attempt();if(I>0){i(r("errors.rate_limit_cooldown",`Too many attempts. Please wait ${I} seconds.`,{seconds:I}));return}i(null),o(!0);try{await N(P,A)}catch(y){e==="signin"&&$(y)&&S(l(A,a.EMAIL).trim()),i(W(y,r)),t.onError?.(Y(y))}finally{o(!1)}},flow:(p,M)=>({mode:e,onSubmit:p,busy:c,ready:s,unavailable:u==="degraded"||u==="error",blocked:v||f.throttled,error:n,fieldErrors:d,unconfirmedEmail:w,resendVerification:L,passwordMinLength:M}),resendVerification:L,setFieldErrors:h}}const _=(e,t)=>{if(t==="")return e("emailRequired","Email is required");if(!H(t))return e("emailInvalid","Invalid email address")},D=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0));function ee(e={}){const t=b("signin",e),{t:r}=t,s=E("signInWithEmail"),u=E("setRememberMe"),m=E("canRememberMe"),f=c=>{t.submit(c,(o,n)=>D({email:_(r,l(n,a.EMAIL).trim()),password:l(n,a.PASSWORD)===""?r("passwordRequired","Password is required"):void 0}),async(o,n)=>{const i=T(o,a.REMEMBER_ME);i&&m()&&await u(i.checked);const d=await s(l(n,a.EMAIL).trim(),l(n,a.PASSWORD));if(!d?.success)throw new Error(d?.error??"Sign in failed");e.onSuccess?.()})};return t.flow(f,O)}function te(e={}){const t=b("signup",e),{t:r}=t,s=E("createUserWithEmail"),u=e.passwordMinLength??O,m=c=>{R({title:e.checkEmailMessage?.title??r("signup.success_title","Check your email"),description:e.checkEmailMessage?.description??r("signup.check_email","If an account was created, you will receive a confirmation email. Check your inbox and spam folder."),toastType:"success",duration:0,action:C(x,{asChild:!0,altText:r("resendEmail","Resend email"),children:C(q,{onClick:()=>{t.resendVerification(c)},children:r("resendEmail","Resend email")})})})},f=c=>{t.submit(c,(o,n)=>{const i=l(n,a.PASSWORD),d=o.elements.namedItem(a.CONFIRM_PASSWORD),h=T(o,a.CONSENT);return D({email:_(r,l(n,a.EMAIL).trim()),password:z(i,u,r)??void 0,confirmPassword:d&&l(n,a.CONFIRM_PASSWORD)!==i?r("confirmPasswordMismatch","Passwords do not match"):void 0,consent:h&&!h.checked?r("terms.required","Please accept the terms to continue"):void 0})},async(o,n)=>{const i=l(n,a.EMAIL).trim(),d=l(n,a.PASSWORD);if(await B(d)){t.setFieldErrors({password:r("errors.breached_password","This password has appeared in a data breach. Please choose a different password.")});return}const h=T(o,a.CONSENT)?.checked?{...e.metadata,gdpr_consent_at:new Date().toISOString()}:e.metadata;try{const w=await s(i,d,h);if(!w?.success)throw new Error(w?.error??"Sign up failed");const S=!w.user?.emailVerified;e.onSuccess?.({awaitingConfirmation:S}),S&&m(i)}catch(w){if(!j(w))throw w;e.onSuccess?.({awaitingConfirmation:!0}),m(i)}})};return t.flow(f,u)}function re(e={}){const t=b("reset",e),{t:r}=t,s=E("sendPasswordResetEmail"),u=m=>{t.submit(m,(f,c)=>D({email:_(r,l(c,a.EMAIL).trim())}),async(f,c)=>{try{await s(l(c,a.EMAIL).trim())}catch(o){if(G(o))throw o}e.onSuccess?.(),R({title:r("forgotPassword.sent","Password reset email sent"),description:r("forgotPassword.check_email_safe","If an account exists with this email, you will receive password reset instructions."),toastType:"success",duration:0})})};return t.flow(u,O)}export{a as AUTH_FIELD,ee as useEmailSignIn,te as useEmailSignUp,re as usePasswordResetRequest};
@@ -0,0 +1,36 @@
1
+ /**
2
+ * @fileoverview Email auth rules
3
+ * @description The rules every email/password flow shares, framework form or app form:
4
+ * provider error -> user message, email format, new-password policy, breached-password
5
+ * check (HaveIBeenPwned k-anonymity, NIST 800-63B).
6
+ *
7
+ * @version 0.1.0
8
+ * @since 0.2.3
9
+ * @author AMBROISE PARK Consulting
10
+ */
11
+ /** Translate function of the `auth` namespace (key, fallback, interpolation). */
12
+ export type AuthT = (key: string, fallback: string, values?: Record<string, unknown>) => string;
13
+ /** Default minimum length of a new password. */
14
+ export declare const DEFAULT_PASSWORD_MIN_LENGTH = 8;
15
+ /** Whether `email` looks like an address (the provider validates for real). */
16
+ export declare function isEmail(email: string): boolean;
17
+ /** Provider error: too many requests (provider-side rate limit). */
18
+ export declare function isRateLimitError(error: unknown): boolean;
19
+ /** Provider error: the address exists but was never confirmed. */
20
+ export declare function isUnconfirmedError(error: unknown): boolean;
21
+ /** Provider error: sign-up with an address that already has an account. */
22
+ export declare function isAlreadyRegisteredError(error: unknown): boolean;
23
+ /** User-facing message for a provider error (rate limit, credentials, network...). */
24
+ export declare function authErrorMessage(error: unknown, t: AuthT): string;
25
+ /**
26
+ * First rule a new password breaks, or `null`. Policy: minimum length (8 by default),
27
+ * one uppercase letter, one lowercase letter, one digit, one special character.
28
+ */
29
+ export declare function newPasswordError(password: string, minLength: number, t: AuthT): string | null;
30
+ /**
31
+ * Whether the password appears in a known breach (HaveIBeenPwned range API: only the
32
+ * first 5 hex chars of the SHA-1 leave the browser). Fails open: an unreachable API
33
+ * never blocks a sign-up.
34
+ */
35
+ export declare function isBreachedPassword(password: string): Promise<boolean>;
36
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/emailAuth/rules.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AAEH,iFAAiF;AACjF,MAAM,MAAM,KAAK,GAAG,CAClB,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,MAAM,CAAC;AAEZ,gDAAgD;AAChD,eAAO,MAAM,2BAA2B,IAAI,CAAC;AAI7C,+EAA+E;AAC/E,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE9C;AAKD,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOxD;AAED,kEAAkE;AAClE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAO1D;AAED,2EAA2E;AAC3E,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAQhE;AA8CD,sFAAsF;AACtF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,MAAM,CAMjE;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,CAAC,EAAE,KAAK,GACP,MAAM,GAAG,IAAI,CAkCf;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAsB3E"}
@@ -0,0 +1,2 @@
1
+ const l=8,d=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function u(e){return d.test(e)}const r=e=>(e instanceof Error?e.message:String(e)).toLowerCase();function o(e){const s=r(e);return s.includes("429")||s.includes("rate")||s.includes("too_many_requests")}function w(e){const s=r(e);return s.includes("email_not_confirmed")||s.includes("email not confirmed")||s.includes("auth/unverified-email")}function m(e){const s=r(e);return s.includes("already")||s.includes("exists")||s.includes("user_already_exists")||s.includes("auth/email-already-in-use")}const f=[{test:o,key:"errors.rate_limit",fallback:"Too many attempts. Please wait a moment and try again."},{test:e=>e.includes("email_not_confirmed")||e.includes("email not confirmed")||e.includes("auth/unverified-email"),key:"errors.email_not_confirmed",fallback:"Please verify your email before signing in."},{test:e=>e.includes("invalid_credentials")||e.includes("invalid login credentials")||e.includes("invalid-credential")||e.includes("auth/wrong-password")||e.includes("auth/user-not-found")||e.includes("invalid")&&e.includes("credential"),key:"errors.invalid_credentials",fallback:"Invalid email or password."},{test:e=>e.includes("weak_password")||e.includes("weak password")||e.includes("auth/weak-password"),key:"errors.weak_password",fallback:"Password is too weak. Please choose a stronger password."},{test:e=>e.includes("network")||e.includes("fetch"),key:"networkError",fallback:"Network error. Please check your connection and try again."}];function p(e,s){const a=r(e);for(const t of f)if(t.test(a))return s(t.key,t.fallback);return s("errorGeneric","Authentication failed. Please try again.")}function y(e,s,a){return e===""?a("passwordRequired","Password is required"):e.length<s?a("passwordMinLength",`Password must be at least ${s} characters`,{count:s}):/[A-Z]/.test(e)?/[a-z]/.test(e)?/[0-9]/.test(e)?/[^a-zA-Z0-9]/.test(e)?null:a("passwordRequirement.special","Password must contain at least one special character"):a("passwordRequirement.number","Password must contain at least one number"):a("passwordRequirement.lowercase","Password must contain at least one lowercase letter"):a("passwordRequirement.uppercase","Password must contain at least one uppercase letter")}async function k(e){try{const s=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),a=Array.from(new Uint8Array(s)).map(n=>n.toString(16).padStart(2,"0")).join("").toUpperCase(),t=a.slice(0,5),c=a.slice(5),i=await fetch(`https://api.pwnedpasswords.com/range/${t}`,{headers:{"Add-Padding":"true"},credentials:"omit"});return i.ok?(await i.text()).split(`
2
+ `).some(n=>n.split(":")[0]?.trim()===c):!1}catch{return!1}}export{l as DEFAULT_PASSWORD_MIN_LENGTH,p as authErrorMessage,m as isAlreadyRegisteredError,k as isBreachedPassword,u as isEmail,o as isRateLimitError,w as isUnconfirmedError,y as newPasswordError};
@@ -1 +1 @@
1
- {"version":3,"file":"useAuthPartner.d.ts","sourceRoot":"","sources":["../../src/hooks/useAuthPartner.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEhE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAG/C,UAAU,qBAAqB;IAC7B,SAAS,CAAC,EAAE,CAAC,MAA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K,OAAO,CAAC,IAAI,CAAC,CAAC;IACpD,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,aAAa,EACxB,OAAO,GAAE,qBAA0B,GAClC,oBAAoB,CA+FtB"}
@@ -1 +1 @@
1
- "use client";import{useCallback as a}from"react";import{useAuth as o}from"../useAuth";function P(t,h={}){const g=o("getPartnerState"),e=o("setPartnerState"),d=o("signInWithPartner"),i=o("partnerError"),{onSuccess:s,onError:l}=h,u=g(t),p=u==="authenticated",E=u==="loading",r=i?.partnerId===t,S=r&&i?.error?new Error(i.error):null,c=a(()=>{r&&e(t,"idle")},[r,t,e]),f=a(()=>{e(t,"loading")},[t,e]),m=a(()=>{e(t,"idle")},[t,e]),A=a(async I=>{r&&c();try{e(t,"loading");const n=await d(t,I);if(n===null){e(t,"idle");return}n&&s&&s(n)}catch(n){e(t,"error",n),l&&l(n)}},[t,r,c,e,d,s,l]);return{partnerState:u,isAuthenticated:p,isAuthenticating:E,hasError:r,error:S,handleSignIn:A,clearError:c,setLoading:f,setIdle:m}}export{P as useAuthPartner};
1
+ "use client";import{useCallback as a}from"react";import{useAuth as o}from"../useAuth";function w(t,g={}){const p=o("getPartnerState"),e=o("setPartnerState"),d=o("signInWithPartner"),i=o("partnerError"),{onSuccess:s,onError:l}=g,c=p(t),E=c==="authenticated",S=c==="loading",r=i?.partnerId===t,f=r&&i?.error?new Error(i.error):null,u=a(()=>{r&&e(t,"idle")},[r,t,e]),m=a(()=>{e(t,"loading")},[t,e]),A=a(()=>{e(t,"idle")},[t,e]),P=a(async I=>{r&&u();try{e(t,"loading");const n=await d(t,I);if(n===null){e(t,"idle");return}n&&s&&s(n)}catch(n){const h=n;e(t,"error",h),l&&l(h)}},[t,r,u,e,d,s,l]);return{partnerState:c,isAuthenticated:E,isAuthenticating:S,hasError:r,error:f,handleSignIn:P,clearError:u,setLoading:m,setIdle:A}}export{w as useAuthPartner};
@@ -34,6 +34,20 @@ export interface DeleteAccountState {
34
34
  * - OAuth providers: Automatically triggers popup
35
35
  * - Password providers: Requires password parameter
36
36
  *
37
+ * **Server refusals**: when the server refuses the deletion (e.g. a
38
+ * `createDeleteAccount({ beforeDelete })` that throws `open_orders`), `error` is the
39
+ * translation of `deleteAccount.errors.<code>` in the `auth` namespace when that key
40
+ * exists. The code is looked up as the server's `code`, then its `error` message, then
41
+ * the client error message; only `[A-Za-z0-9_-]+` values are tried. Without a matching
42
+ * key, `error` is the raw error message (unchanged behaviour). Consumers add the keys
43
+ * in their `auth` locale override, e.g. `src/locales/auth_fr.json`:
44
+ *
45
+ * ```json
46
+ * { "deleteAccount": { "errors": {
47
+ * "open_orders": "Vous avez une commande en cours. Réessayez après sa livraison."
48
+ * } } }
49
+ * ```
50
+ *
37
51
  * @example
38
52
  * ```tsx
39
53
  * const deletion = useDeleteAccount();
@@ -54,7 +68,7 @@ export interface DeleteAccountState {
54
68
  * />
55
69
  * ```
56
70
  *
57
- * @version 0.1.0
71
+ * @version 0.2.0
58
72
  * @since 0.0.1
59
73
  * @author AMBROISE PARK Consulting
60
74
  * @returns Account deletion state and actions
@@ -1 +1 @@
1
- {"version":3,"file":"useDeleteAccount.d.ts","sourceRoot":"","sources":["../../src/hooks/useDeleteAccount.tsx"],"names":[],"mappings":"AAgBA;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IACjC,6CAA6C;IAC7C,iBAAiB,EAAE,OAAO,CAAC;IAE3B,8CAA8C;IAC9C,UAAU,EAAE,OAAO,CAAC;IAEpB,2DAA2D;IAC3D,kBAAkB,EAAE,OAAO,CAAC;IAE5B,2BAA2B;IAC3B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAErB,0DAA0D;IAC1D,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B,uFAAuF;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