@donotdev/auth 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/EmailLinkForm.d.ts.map +1 -1
- package/dist/components/EmailLinkForm.js +1 -1
- package/dist/components/EmailPasswordForm.d.ts +1 -1
- package/dist/components/EmailPasswordForm.d.ts.map +1 -1
- package/dist/components/EmailPasswordForm.js +1 -1
- package/dist/components/FeaturePlaceholder.d.ts +3 -3
- package/dist/components/PasswordStrengthIndicator.d.ts +8 -2
- package/dist/components/PasswordStrengthIndicator.d.ts.map +1 -1
- package/dist/components/PasswordStrengthIndicator.js +1 -1
- package/dist/constants.d.ts +0 -6
- package/dist/constants.d.ts.map +1 -1
- package/dist/emailAuth/captcha.d.ts +9 -0
- package/dist/emailAuth/captcha.d.ts.map +1 -0
- package/dist/emailAuth/captcha.js +1 -0
- package/dist/emailAuth/fields.d.ts +10 -3
- package/dist/emailAuth/fields.d.ts.map +1 -1
- package/dist/emailAuth/fields.js +1 -1
- package/dist/emailAuth/flows.d.ts +19 -10
- package/dist/emailAuth/flows.d.ts.map +1 -1
- package/dist/emailAuth/flows.js +1 -1
- package/dist/emailAuth/rules.d.ts +12 -4
- package/dist/emailAuth/rules.d.ts.map +1 -1
- package/dist/emailAuth/rules.js +2 -2
- package/dist/emailAuth/signUpFlow.d.ts +78 -0
- package/dist/emailAuth/signUpFlow.d.ts.map +1 -0
- package/dist/emailAuth/signUpFlow.js +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/symbol-index.json +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/useAuth.js +1 -1
- package/guidelines/AUTH.md +53 -0
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailLinkForm.d.ts","sourceRoot":"","sources":["../../src/components/EmailLinkForm.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EmailLinkForm.d.ts","sourceRoot":"","sources":["../../src/components/EmailLinkForm.tsx"],"names":[],"mappings":"AA6BA,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,kBAAkB,CAAC,EAAE;QACnB,GAAG,EAAE,MAAM,CAAC;QACZ,eAAe,EAAE,OAAO,CAAC;KAC1B,CAAC;CACH;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,aAAa,CAAC,EAC5B,SAAc,EACd,SAAS,EACT,OAAO,EACP,kBAAkB,GACnB,EAAE,kBAAkB,+BA2FpB;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e,jsxs as l}from"react/jsx-runtime";import{Mail as
|
|
1
|
+
"use client";import{jsx as e,jsxs as l}from"react/jsx-runtime";import{Mail as d,CheckCircle as N}from"lucide-react";import{Button as c,BUTTON_VARIANT as f,Input as C,Alert as T,ALERT_VARIANT as b,Spinner as A,Stack as n,Text as s}from"@donotdev/components";import{useTranslation as R}from"@donotdev/core";import{AuthCaptcha as x}from"../emailAuth/captcha";import{useEmailLinkForm as y}from"../hooks/useEmailLinkForm";function m({className:r="",onSuccess:u,onError:h,actionCodeSettings:k}){const{t:i}=R("auth"),{email:t,setEmail:L,isLoading:a,isSent:p,error:o,handleSendLink:v,handleResend:g,canSubmit:E}=y({onSuccess:u,onError:h,actionCodeSettings:k});return p?l(n,{className:r,children:[l(n,{align:"center",children:[e(N,{className:"dndev-size-touch"}),e(s,{as:"h3",level:"h3",children:i("emailLink.checkEmail","Check Your Email")}),e(s,{level:"small",variant:"muted",className:"dndev-text-center",children:i("emailLink.sentMessage",`We've sent a sign-in link to ${t}. Click the link in your email to complete sign-in.`)})]}),e(n,{direction:"row",justify:"center",children:e(c,{variant:f.OUTLINE,onClick:g,icon:d,iconEnd:!1,children:i("emailLink.resend","Resend Link")})})]}):e("form",{onSubmit:v,className:r,children:l(n,{children:[e(C,{type:"email",label:i("emailLink.emailLabel","Email Address"),value:t,onChange:S=>L(S.target.value),placeholder:i("emailLink.emailPlaceholder","Enter your email address"),required:!0,disabled:a,className:"dndev-w-full"}),o&&e(T,{variant:b.ERROR,description:o}),e(x,{}),e(c,{type:"submit",disabled:!E,icon:a?e(A,{"aria-label":"Loading"}):d,iconEnd:!1,className:"dndev-w-full",children:a?i("emailLink.sending","Sending Link..."):i("emailLink.sendLink","Send Sign-In Link")}),e(s,{level:"small",variant:"muted",className:"dndev-text-center",children:i("emailLink.helpText","We'll send you a secure link to sign in without a password.")})]})})}var w=m;export{m as EmailLinkForm,w as default};
|
|
@@ -13,6 +13,6 @@ import type { EmailPasswordFormProps } from '../constants';
|
|
|
13
13
|
* <EmailPasswordForm onSuccess={() => setOpen(false)} />
|
|
14
14
|
* ```
|
|
15
15
|
*/
|
|
16
|
-
declare function EmailPasswordForm({ mode, onSuccess, onError, className, tos, privacy,
|
|
16
|
+
declare function EmailPasswordForm({ mode, onSuccess, onError, className, tos, privacy, confirmation, }: EmailPasswordFormProps): import("react").JSX.Element;
|
|
17
17
|
export default EmailPasswordForm;
|
|
18
18
|
//# sourceMappingURL=EmailPasswordForm.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EmailPasswordForm.d.ts","sourceRoot":"","sources":["../../src/components/EmailPasswordForm.tsx"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAQ3D;;;;;;;;;;;;;GAaG;AACH,iBAAS,iBAAiB,CAAC,EACzB,IAAe,EACf,SAAS,EACT,OAAO,EACP,SAAS,EACT,GAAG,EACH,OAAO,EACP,
|
|
1
|
+
{"version":3,"file":"EmailPasswordForm.d.ts","sourceRoot":"","sources":["../../src/components/EmailPasswordForm.tsx"],"names":[],"mappings":"AAsCA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAQ3D;;;;;;;;;;;;;GAaG;AACH,iBAAS,iBAAiB,CAAC,EACzB,IAAe,EACf,SAAS,EACT,OAAO,EACP,SAAS,EACT,GAAG,EACH,OAAO,EACP,YAAsB,GACvB,EAAE,sBAAsB,+BAyGxB;AAED,eAAe,iBAAiB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as e,jsxs as
|
|
1
|
+
"use client";import{jsx as e,jsxs as o}from"react/jsx-runtime";import{useState as g}from"react";import{Button as B,BUTTON_VARIANT as L,Stack as r,Text as F}from"@donotdev/components";import{useTranslation as R}from"@donotdev/core";import{AuthCodeStep as V,AuthConfirmPasswordField as _,AuthConsentField as j,AuthEmailField as p,AuthForm as A,AuthFormAlerts as w,AuthPasswordField as C,AuthRememberMeField as H,AuthSubmitButton as v}from"../emailAuth/fields";import{AUTH_FIELD as M,useEmailSignIn as U,useEmailSignUp as q,usePasswordResetRequest as D}from"../emailAuth/flows";const K=l=>{const a=l.currentTarget.form?.elements.namedItem(M.EMAIL);return a instanceof HTMLInputElement?a.value:""};function O({mode:l="signin",onSuccess:a,onError:N,className:s,tos:y,privacy:I,confirmation:c="toast"}){const{t}=R("auth"),[S,T]=g(l),[u,E]=g(""),[m,d]=g(null),f={onSuccess:()=>a?.(void 0),onError:N},b=U({...f,confirmation:c,onCodeSent:d}),k=q({...f,confirmation:c,onSuccess:n=>{c==="code"&&n.awaitingConfirmation?d(n.email):a?.(void 0)}}),P=D(f);if(m!==null)return e(r,{className:s,children:e(V,{email:m,onSuccess:()=>a?.(void 0),onChangeEmail:()=>{E(m),d(null)}})});const x=n=>h=>{E(K(h)),T(n)},i=(n,h)=>e(B,{type:"button",variant:L.LINK,onClick:x(h),children:n});return S==="reset"?o(A,{flow:P,className:s,children:[e(F,{variant:"muted",children:t("forgotPassword.intro","Enter your email and we will send you a reset link.")}),e(p,{defaultValue:u}),e(w,{}),e(v,{}),e(r,{align:"center",children:i(t("back","Back"),"signin")})]},"reset"):S==="signup"?o(A,{flow:k,className:s,children:[e(p,{defaultValue:u}),e(C,{}),e(_,{}),e(j,{tos:y,privacy:I}),e(w,{}),e(v,{}),e(r,{align:"center",children:i(t("alreadyHaveAccount","Already have an account? Sign In"),"signin")})]},"signup"):o(A,{flow:b,className:s,children:[e(p,{defaultValue:u}),e(C,{}),e(H,{}),e(w,{}),e(v,{}),o(r,{direction:"row",gap:"tight",justify:"center",align:"center",children:[i(t("forgotPassword","Forgot password?"),"reset"),e(F,{as:"span",variant:"muted",children:"|"}),i(t("actions.sign_up_submit","Create account"),"signup")]})]},"signin")}var Y=O;export{Y as default};
|
|
@@ -47,7 +47,7 @@ interface TierPlaceholderProps {
|
|
|
47
47
|
* @since 0.0.1
|
|
48
48
|
* @author AMBROISE PARK Consulting
|
|
49
49
|
*/
|
|
50
|
-
export declare function FeaturePlaceholder({ featureId, featureName, className, children, }: FeaturePlaceholderProps): string | number | bigint | true |
|
|
50
|
+
export declare function FeaturePlaceholder({ featureId, featureName, className, children, }: FeaturePlaceholderProps): string | number | bigint | true | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null;
|
|
51
51
|
/**
|
|
52
52
|
* Placeholder for Pro tier features
|
|
53
53
|
*
|
|
@@ -55,7 +55,7 @@ export declare function FeaturePlaceholder({ featureId, featureName, className,
|
|
|
55
55
|
* @since 0.0.1
|
|
56
56
|
* @author AMBROISE PARK Consulting
|
|
57
57
|
*/
|
|
58
|
-
export declare const ProFeaturePlaceholder: ({ featureName, className, children, }: TierPlaceholderProps) => string | number | bigint | true |
|
|
58
|
+
export declare const ProFeaturePlaceholder: ({ featureName, className, children, }: TierPlaceholderProps) => string | number | bigint | true | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null;
|
|
59
59
|
/**
|
|
60
60
|
* Placeholder for Premium tier features
|
|
61
61
|
*
|
|
@@ -63,6 +63,6 @@ export declare const ProFeaturePlaceholder: ({ featureName, className, children,
|
|
|
63
63
|
* @since 0.0.1
|
|
64
64
|
* @author AMBROISE PARK Consulting
|
|
65
65
|
*/
|
|
66
|
-
export declare const PremiumFeaturePlaceholder: ({ featureName, className, children, }: TierPlaceholderProps) => string | number | bigint | true |
|
|
66
|
+
export declare const PremiumFeaturePlaceholder: ({ featureName, className, children, }: TierPlaceholderProps) => string | number | bigint | true | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element | null;
|
|
67
67
|
export {};
|
|
68
68
|
//# sourceMappingURL=FeaturePlaceholder.d.ts.map
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
export interface PasswordStrengthIndicatorProps {
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Current password value. Empty: idle state (empty bar, muted placeholder label,
|
|
4
|
+
* unmet checklist) with exactly the layout of the typed state, so the slot can stay
|
|
5
|
+
* mounted before the first keystroke without shifting the form when typing starts.
|
|
6
|
+
*/
|
|
3
7
|
password: string;
|
|
4
8
|
/** Minimum password length */
|
|
5
9
|
minLength?: number;
|
|
@@ -13,7 +17,9 @@ export type PasswordStrength = 'weak' | 'fair' | 'good' | 'strong';
|
|
|
13
17
|
* PasswordStrengthIndicator Component
|
|
14
18
|
*
|
|
15
19
|
* Displays visual password strength indicator and optional requirements checklist.
|
|
16
|
-
* Uses Progress component for the strength bar and Text for labels.
|
|
20
|
+
* Uses Progress component for the strength bar and Text for labels. The bar is named
|
|
21
|
+
* after its visible label and announces the strength in words (`aria-valuetext`), not
|
|
22
|
+
* a bare percentage.
|
|
17
23
|
*
|
|
18
24
|
* @component
|
|
19
25
|
* @version 0.1.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PasswordStrengthIndicator.d.ts","sourceRoot":"","sources":["../../src/components/PasswordStrengthIndicator.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,8BAA8B;IAC7C
|
|
1
|
+
{"version":3,"file":"PasswordStrengthIndicator.d.ts","sourceRoot":"","sources":["../../src/components/PasswordStrengthIndicator.tsx"],"names":[],"mappings":"AAmBA,MAAM,WAAW,8BAA8B;IAC7C;;;;OAIG;IACH,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;;;;;;;;;;GAUG;AACH,wBAAgB,yBAAyB,CAAC,EACxC,QAAQ,EACR,SAAa,EACb,gBAAuB,EACvB,SAAS,GACV,EAAE,8BAA8B,+BAsFhC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsxs as r,jsx as i}from"react/jsx-runtime";import{Check as
|
|
1
|
+
"use client";import{jsxs as r,jsx as i}from"react/jsx-runtime";import{Check as f,Circle as b}from"lucide-react";import{useMemo as p}from"react";import{Progress as q,Stack as o,Text as c,cn as k}from"@donotdev/components";import{useTranslation as S}from"@donotdev/core";function x(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},u={weak:"destructive",fair:"warning",good:"accent",strong:"success"};function z({password:e,minLength:t=8,showRequirements:s=!0,className:h}){const{t:a}=S("auth"),d=p(()=>x(e),[e]),w=p(()=>N(e,t,(n,m,v)=>a(n,{defaultValue:m||"",...v})),[e,t,a]),l=e==="",g={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:k("dndev-password-strength",h),children:[r(o,{gap:"tight",children:[r(o,{direction:"row",align:"center",justify:"between",gap:"tight",children:[r(c,{as:"span",level:"caption",variant:"muted",children:[a("passwordStrength.label","Password strength"),":"]}),i(c,{as:"strong",level:"caption",variant:l?"muted":u[d],children:l?"\u2013":g[d]})]}),i(q,{"aria-label":a("passwordStrength.label","Password strength"),"aria-valuetext":l?void 0:g[d],value:l?0:R[d],variant:l?"default":u[d],className:"dndev-password-strength-bar"})]}),s&&r(o,{gap:"tight",className:"dndev-password-requirements",children:[r(c,{as:"strong",level:"caption",variant:"muted",children:[a("passwordRequirements","Password requirements"),":"]}),i(o,{gap:"tight","data-inset":"true",children:w.map((n,m)=>r(o,{direction:"row",align:"center",gap:"tight",className:"dndev-password-requirement-item",children:[n.met?i(f,{className:"dndev-size-xs","data-variant":"success"}):i(b,{className:"dndev-size-xs","data-variant":"muted"}),i(c,{as:"span",level:"caption",variant:n.met?"success":"muted","data-opacity":n.met?void 0:"70",children:n.label})]},m))})]})]})}export{z as PasswordStrengthIndicator};
|
package/dist/constants.d.ts
CHANGED
|
@@ -143,12 +143,6 @@ export interface EmailPasswordFormProps extends BaseComponentProps, AuthCallback
|
|
|
143
143
|
* - `false`: explicitly disable Privacy requirement
|
|
144
144
|
*/
|
|
145
145
|
privacy?: string | React.ReactNode | false;
|
|
146
|
-
/**
|
|
147
|
-
* CAPTCHA token to include with auth requests.
|
|
148
|
-
* Consumer is responsible for rendering the CAPTCHA widget (e.g. Turnstile)
|
|
149
|
-
* and passing the token here. When provided, submit is blocked until token is truthy.
|
|
150
|
-
*/
|
|
151
|
-
captchaToken?: string;
|
|
152
146
|
/**
|
|
153
147
|
* How a sign-up (or a sign-in of an unconfirmed address) confirms the email
|
|
154
148
|
* (default `'toast'`: the "check your email" toast with Resend). `'code'`: the form
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -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,WAA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jB,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,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Turnstile widget (theme `auto`, the app's language, full width). Hidden until
|
|
3
|
+
* Cloudflare asks the visitor to interact (Managed widget); an Invisible widget never
|
|
4
|
+
* shows. Renders nothing without `TURNSTILE_SITE_KEY`.
|
|
5
|
+
*
|
|
6
|
+
* @returns The widget container, or nothing
|
|
7
|
+
*/
|
|
8
|
+
export declare function AuthCaptcha(): import("react").JSX.Element | null;
|
|
9
|
+
//# sourceMappingURL=captcha.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"captcha.d.ts","sourceRoot":"","sources":["../../src/emailAuth/captcha.tsx"],"names":[],"mappings":"AA0BA;;;;;;GAMG;AACH,wBAAgB,WAAW,uCAc1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";import{jsx as n}from"react/jsx-runtime";import{useEffect as u,useRef as s}from"react";import{Stack as o}from"@donotdev/components";import{getCaptchaSiteKey as c,mountCaptchaWidget as i,useTranslation as l}from"@donotdev/core";function f(){const{language:r}=l("auth"),t=s(null),e=c();return u(()=>{if(!e||!t.current)return;const a=i(t.current,{language:r});return()=>a.remove()},[e,r]),e?n(o,{ref:t,children:null}):null}export{f as AuthCaptcha};
|
|
@@ -52,7 +52,9 @@ export declare function AuthNameField({ label, placeholder, defaultValue, info,
|
|
|
52
52
|
/**
|
|
53
53
|
* Password field. Sign-in: `current-password`. Sign-up: `new-password` and a strength
|
|
54
54
|
* meter, with the policy requirements unless the flow's `passwordComposition` is
|
|
55
|
-
* `false`.
|
|
55
|
+
* `false`. The meter's slot is always mounted (idle until the first keystroke), so
|
|
56
|
+
* typing never shifts the layout. It also reports each change to
|
|
57
|
+
* `flow.watchPassword`, which runs the breached-password pre-check.
|
|
56
58
|
*
|
|
57
59
|
* @param props - AuthTextFieldProps
|
|
58
60
|
* @returns The field
|
|
@@ -114,8 +116,11 @@ export interface AuthSubmitButtonProps {
|
|
|
114
116
|
children?: ReactNode;
|
|
115
117
|
}
|
|
116
118
|
/**
|
|
117
|
-
* Submit button: full width, loading while the flow runs
|
|
118
|
-
* is ready and while
|
|
119
|
+
* Submit button: full width, loading while the flow runs (including the wait for a
|
|
120
|
+
* CAPTCHA token), disabled until the provider is ready and while throttled. With the
|
|
121
|
+
* env var `TURNSTILE_SITE_KEY` set, the CAPTCHA widget renders just above it (hidden
|
|
122
|
+
* unless Cloudflare asks the visitor to interact); every flow call of the form takes its
|
|
123
|
+
* token there.
|
|
119
124
|
*
|
|
120
125
|
* @param props - AuthSubmitButtonProps
|
|
121
126
|
* @returns The button
|
|
@@ -133,6 +138,8 @@ export interface AuthCodeFieldProps {
|
|
|
133
138
|
* paste of the whole code), submitted as soon as the last character is typed, the
|
|
134
139
|
* error under it, "A new code has been sent." under it after a resend (no toast), and
|
|
135
140
|
* a Resend button with its countdown; after a resend the code input has focus again.
|
|
141
|
+
* With `TURNSTILE_SITE_KEY` set, the CAPTCHA widget renders above Resend (a resend is a
|
|
142
|
+
* gated call).
|
|
136
143
|
* Render it outside the
|
|
137
144
|
* sign-up `AuthForm` (it is not a form field).
|
|
138
145
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/emailAuth/fields.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../../src/emailAuth/fields.tsx"],"names":[],"mappings":"AAyBA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAkBvC,OAAO,KAAK,EAAE,QAAQ,EAAE,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ED;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,MAAM,EACN,SAAS,EACT,aAAa,GACd,EAAE,iBAAiB,+BAmBnB"}
|
package/dist/emailAuth/fields.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as t,jsxs as c,Fragment as E}from"react/jsx-runtime";import{createContext as x,use as D,useId as p,useRef as B,useState as N}from"react";import{Alert as P,ALERT_VARIANT as I,Button as v,BUTTON_VARIANT as w,Checkbox as S,Dialog as K,Input as V,Label as W,PasswordInput as F,PinInput as $,Stack as h,Text as A,cn as H}from"@donotdev/components";import{useAppConfig as U,useTranslation as m}from"@donotdev/core";import{useAuth as j}from"../useAuth";import{PasswordStrengthIndicator as Y}from"../components/PasswordStrengthIndicator";import{AuthCaptcha as L}from"./captcha";import{AUTH_FIELD as b,useEmailCodeConfirmation as q}from"./flows";const _=x(null);function f(){const e=D(_);if(!e)throw new Error("Auth fields must be rendered inside <AuthForm>");return e}function G({flow:e,children:n,className:a}){const{t:i}=m("auth");return e.unavailable?t(P,{variant:I.WARNING,title:i("unavailable.title","Authentication Unavailable"),description:i("unavailable.description","Sign-in is temporarily unavailable. Please try again later.")}):t(_,{value:e,children:t("form",{noValidate:!0,onSubmit:e.onSubmit,className:H("dndev-auth-form",a),children:t(h,{children:n})})})}function y({id:e,message:n}){return n?t(A,{as:"span",level:"caption",variant:"destructive",id:e,role:"alert",children:n}):null}function z({label:e,placeholder:n,defaultValue:a}){const{t:i}=m("auth"),r=f(),o=p(),l=p(),s=r.fieldErrors.email;return c(h,{gap:"tight",children:[t(V,{id:o,name:b.EMAIL,type:"email",autoComplete:"username",label:e??i("email","Email"),placeholder:n??i("emailPlaceholder","Enter your email"),defaultValue:a,readOnly:r.busy,"aria-invalid":!!s,"aria-describedby":s?l:void 0,"data-variant":s?"destructive":void 0,className:"dndev-w-full"}),t(y,{id:l,message:s})]})}function J({label:e,placeholder:n,defaultValue:a,info:i}){const{t:r}=m("auth"),o=f();return t(V,{name:b.DISPLAY_NAME,type:"text",autoComplete:"name",label:e??r("name","Name"),placeholder:n,defaultValue:a,info:i,readOnly:o.busy,className:"dndev-w-full"})}function k(){const{t:e}=m("auth");return{show:e("passwordToggle.show",{defaultValue:"Show password"}),hide:e("passwordToggle.hide",{defaultValue:"Hide password"})}}function Q({label:e,placeholder:n}){const{t:a}=m("auth"),i=f(),r=p(),o=p(),[l,s]=N(""),d=i.mode==="signup",u=i.fieldErrors.password,g=k();return c(h,{gap:"tight",children:[t(F,{id:r,name:b.PASSWORD,autoComplete:d?"new-password":"current-password",revealAriaLabel:g,label:e??a("password","Password"),placeholder:n??a("passwordPlaceholder","Enter your password"),onInput:d?R=>{const C=R.target.value;s(C),i.watchPassword?.(C)}:void 0,readOnly:i.busy,"aria-invalid":!!u,"aria-describedby":u?o:void 0,"data-variant":u?"destructive":void 0,className:"dndev-w-full"}),t(y,{id:o,message:u}),d&&t(Y,{password:l,minLength:i.passwordMinLength,showRequirements:i.passwordComposition!==!1})]})}function X({label:e,placeholder:n}){const{t:a}=m("auth"),i=f(),r=p(),o=p(),l=i.fieldErrors.confirmPassword,s=k();return c(h,{gap:"tight",children:[t(F,{id:r,name:b.CONFIRM_PASSWORD,autoComplete:"new-password",revealAriaLabel:s,label:e??a("confirmPassword","Confirm Password"),placeholder:n??a("confirmPasswordPlaceholder","Re-enter your password"),readOnly:i.busy,"aria-invalid":!!l,"aria-describedby":l?o:void 0,"data-variant":l?"destructive":void 0,className:"dndev-w-full"}),t(y,{id:o,message:l})]})}function Z({label:e,defaultChecked:n=!0}){const{t:a}=m("auth"),i=f(),r=j("canRememberMe");return!i.ready||!r()?null:t(S,{name:b.REMEMBER_ME,defaultChecked:n,label:e??a("rememberMe","Remember me")})}const ee={minHeight:"auto",padding:0,display:"inline"};function T({label:e,document:n}){const[a,i]=N(!1),r=typeof n=="string";return c(E,{children:[t(v,{type:"button",variant:w.LINK,onClick:()=>r?window.open(n,"_blank","noopener,noreferrer"):i(!0),className:"dndev-p-0 dndev-h-auto",style:ee,children:e}),!r&&t(K,{open:a,onOpenChange:i,title:e,showClose:!0,children:n})]})}function ae({tos:e,privacy:n}){const{t:a}=m("auth"),i=f(),r=U("app"),o=p(),l=p(),s=(R,C)=>r?.footer?.legalLinks?.find(O=>O.path.includes(R))?.path??C,d=e===void 0?s("terms","/legal/terms"):e,u=n===void 0?s("privacy","/legal/privacy"):n;if(d===!1&&u===!1)return null;const g=i.fieldErrors.consent;return c(h,{gap:"tight",children:[c(h,{direction:"row",gap:"tight",align:"start",children:[t(S,{id:o,name:b.CONSENT,"aria-invalid":!!g,"aria-describedby":g?l:void 0}),t(W,{htmlFor:o,children:c(A,{as:"span",level:"caption",children:[a("terms.accept_prefix","I accept the")," ",d!==!1&&t(T,{label:a("terms.tos","Terms of Service"),document:d}),d!==!1&&u!==!1&&c(E,{children:[" ",a("terms.and","and")," "]}),u!==!1&&t(T,{label:a("terms.privacy","Privacy Policy"),document:u})]})})]}),t(y,{id:l,message:g})]})}function ne(){const{t:e}=m("auth"),n=f();if(!n.error)return null;const a=n.unconfirmedEmail;return c(h,{gap:"tight",children:[t(P,{variant:I.ERROR,description:n.error}),a&&t(v,{type:"button",variant:w.LINK,onClick:()=>{n.resendVerification(a)},children:e("signup.resend_verification","Resend verification email")})]})}function te({children:e}){const{t:n}=m("auth"),a=f(),i=a.mode==="signup"?n("actions.sign_up_submit","Create account"):a.mode==="reset"?n("forgotPassword.submit","Send reset link"):n("actions.sign_in_submit","Sign In");return c(h,{gap:"tight",children:[t(L,{}),t(v,{type:"submit",variant:w.PRIMARY,fullWidth:!0,loading:a.busy,disabled:!a.ready||a.blocked,children:e??i})]})}function M({confirmation:e,label:n}){const{t:a}=m("auth"),i=p(),r=B(null),{error:o,resent:l,resendIn:s}=e;return c(h,{gap:"tight",children:[t($,{ref:r,value:e.code,onChange:e.setCode,onComplete:d=>{e.submit(d)},length:e.length,mask:!1,autoFocus:!0,label:n??a("codeConfirmation.label",{defaultValue:"Confirmation code"}),disabled:e.busy||!e.ready,digitAriaLabel:(d,u)=>a("codeConfirmation.digit",{defaultValue:`Digit ${d} of ${u}`,index:d,length:u}),"aria-invalid":!!o,"aria-describedby":o?i:void 0}),t(y,{id:i,message:o??void 0}),l&&t(A,{as:"span",level:"caption",variant:"success",role:"status",children:a("codeConfirmation.sent",{defaultValue:"A new code has been sent."})}),t(L,{}),t(v,{type:"button",variant:w.LINK,loading:e.resending,disabled:s>0||!e.ready,onClick:()=>{e.resend().then(()=>r.current?.focus())},children:s>0?a("codeConfirmation.resend_in",{defaultValue:`Resend code in ${s} s`,seconds:s}):a("codeConfirmation.resend",{defaultValue:"Resend code"})})]})}function ie({email:e,length:n,onSuccess:a,onChangeEmail:i}){const{t:r}=m("auth"),o=q({email:e,length:n,onSuccess:a});return c(h,{children:[t(A,{variant:"muted",children:r("codeConfirmation.intro",{defaultValue:`Enter the code sent to ${e}`,email:e})}),t(M,{confirmation:o}),i&&t(v,{type:"button",variant:w.LINK,onClick:i,children:r("codeConfirmation.change_email",{defaultValue:"Change address"})})]})}export{M as AuthCodeField,ie as AuthCodeStep,X as AuthConfirmPasswordField,ae as AuthConsentField,z as AuthEmailField,G as AuthForm,ne as AuthFormAlerts,J as AuthNameField,Q as AuthPasswordField,Z as AuthRememberMeField,te as AuthSubmitButton};
|
|
@@ -10,6 +10,11 @@ export declare const AUTH_FIELD: {
|
|
|
10
10
|
readonly CONSENT: "consent";
|
|
11
11
|
readonly DISPLAY_NAME: "displayName";
|
|
12
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Sign-up: quiet time (ms) after the last keystroke before the breached-password
|
|
15
|
+
* pre-check starts, so it never fires per keystroke.
|
|
16
|
+
*/
|
|
17
|
+
export declare const BREACH_PRECHECK_DEBOUNCE_MS = 600;
|
|
13
18
|
/** Which flow a form runs. */
|
|
14
19
|
export type EmailAuthMode = 'signin' | 'signup' | 'reset';
|
|
15
20
|
/** Per-field validation messages, keyed by field name. */
|
|
@@ -25,11 +30,6 @@ export interface EmailAuthFlowOptions {
|
|
|
25
30
|
onSuccess?: () => void;
|
|
26
31
|
/** Called with the provider error after a failed attempt */
|
|
27
32
|
onError?: (error: Error) => void;
|
|
28
|
-
/**
|
|
29
|
-
* CAPTCHA token. `undefined` = no CAPTCHA; while it is `null` / empty the submit is
|
|
30
|
-
* blocked. The app renders the widget.
|
|
31
|
-
*/
|
|
32
|
-
captchaToken?: string | null;
|
|
33
33
|
}
|
|
34
34
|
/** Options of {@link useEmailSignIn}. */
|
|
35
35
|
export interface EmailSignInOptions extends EmailAuthFlowOptions {
|
|
@@ -105,7 +105,7 @@ export interface EmailAuthFlow {
|
|
|
105
105
|
ready: boolean;
|
|
106
106
|
/** The provider failed to start: show an "unavailable" notice instead of the form */
|
|
107
107
|
unavailable: boolean;
|
|
108
|
-
/** Submit is blocked (
|
|
108
|
+
/** Submit is blocked (client-side throttle cooldown) */
|
|
109
109
|
blocked: boolean;
|
|
110
110
|
/** Form-level error (provider error, throttle) */
|
|
111
111
|
error: string | null;
|
|
@@ -122,6 +122,14 @@ export interface EmailAuthFlow {
|
|
|
122
122
|
* `AuthPasswordField` shows the requirements checklist only then.
|
|
123
123
|
*/
|
|
124
124
|
passwordComposition?: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* Sign-up only: tell the flow the new password changed. Once typing has stopped
|
|
127
|
+
* ({@link BREACH_PRECHECK_DEBOUNCE_MS}) and the password meets the strength rules,
|
|
128
|
+
* the flow runs the breached-password check in the background and shows the
|
|
129
|
+
* breached error on the password field at once; submit reuses that result.
|
|
130
|
+
* Absent in the other flows.
|
|
131
|
+
*/
|
|
132
|
+
watchPassword?: (password: string) => void;
|
|
125
133
|
}
|
|
126
134
|
/**
|
|
127
135
|
* The email check of every flow: the translated "required" / "invalid" message, or
|
|
@@ -137,7 +145,7 @@ export declare const validateEmail: (t: AuthT, email: string) => string | undefi
|
|
|
137
145
|
* `AuthRememberMeField`. An unconfirmed address offers a resend, or with
|
|
138
146
|
* `confirmation: 'code'` gets a fresh code and `onCodeSent(email)` (show `AuthCodeStep`).
|
|
139
147
|
*
|
|
140
|
-
* @param options - Callbacks,
|
|
148
|
+
* @param options - Callbacks, confirmation mode
|
|
141
149
|
* @returns The flow, for `AuthForm`
|
|
142
150
|
*
|
|
143
151
|
* @example
|
|
@@ -171,7 +179,7 @@ export declare function useEmailSignIn(options?: EmailSignInOptions): EmailAuthF
|
|
|
171
179
|
* A project that does not require confirmation signs the user in at once:
|
|
172
180
|
* `awaitingConfirmation: false`.
|
|
173
181
|
*
|
|
174
|
-
* @param options - Callbacks,
|
|
182
|
+
* @param options - Callbacks, password policy, extra metadata,
|
|
175
183
|
* confirmation mode
|
|
176
184
|
* @returns The flow, for `AuthForm`
|
|
177
185
|
*
|
|
@@ -206,9 +214,10 @@ export interface PasswordResetRequestFlow extends EmailAuthFlow {
|
|
|
206
214
|
* Password-reset request. Anti-enumeration: the same outcome whether or not the address
|
|
207
215
|
* has an account; `sent` turns `true`, `onSuccess` runs and a toast that stays until
|
|
208
216
|
* dismissed says to check the inbox (`toast: false`: no toast, the app shows the
|
|
209
|
-
* message inline from `sent`).
|
|
217
|
+
* message inline from `sent`). Throttling and a CAPTCHA failure are the form error
|
|
218
|
+
* (the request did not go out); any other provider error is hidden.
|
|
210
219
|
*
|
|
211
|
-
* @param options - Callbacks,
|
|
220
|
+
* @param options - Callbacks, toast opt-out
|
|
212
221
|
* @returns The flow, for `AuthForm`
|
|
213
222
|
*/
|
|
214
223
|
export declare function usePasswordResetRequest(options?: PasswordResetRequestOptions): PasswordResetRequestFlow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/emailAuth/flows.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"flows.d.ts","sourceRoot":"","sources":["../../src/emailAuth/flows.tsx"],"names":[],"mappings":"AAwCA,OAAO,KAAK,EAAE,SA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I,CAAC;IAChC;;;OAGG;IACH,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC,oCAAoC;IACpC,IAAI,EAAE,OAAO,CAAC;IACd,2GAA2G;IAC3G,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB;;;OAGG;IACH,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,4FAA4F;IAC5F,MAAM,EAAE,OAAO,CAAC;IAChB,8BAA8B;IAC9B,SAAS,EAAE,OAAO,CAAC;IACnB,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,4BAA4B,GACpC,qBAAqB,CA8FvB"}
|
package/dist/emailAuth/flows.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsx as
|
|
1
|
+
"use client";import{jsx as x}from"react/jsx-runtime";import{useEffect as v,useRef as b,useState as R}from"react";import{Button as z,ToastAction as J,toast as L}from"@donotdev/components";import{useTranslation as Q}from"@donotdev/core";import{useAuth as h}from"../useAuth";import{DEFAULT_CONFIRMATION_CODE_LENGTH as X,DEFAULT_PASSWORD_MIN_LENGTH as k,DEFAULT_RESEND_COOLDOWN_SECONDS as Z,authErrorMessage as q,codeErrorMessage as B,isAlreadyRegisteredError as ee,isBreachedPassword as te,isCaptchaError as re,isEmail as se,isRateLimitError as H,isUnconfirmedError as j,newPasswordError as $}from"./rules";const l={EMAIL:"email",PASSWORD:"password",CONFIRM_PASSWORD:"confirmPassword",REMEMBER_ME:"rememberMe",CONSENT:"consent",DISPLAY_NAME:"displayName"},ne="full_name",G=600,ae=6e4,ie=5,oe=3e4;function Y(){const e=b([]),[t,r]=R(null);return v(()=>{if(t===null)return;const a=setTimeout(()=>r(null),Math.max(0,t-Date.now()));return()=>clearTimeout(a)},[t]),{attempt:()=>{const a=Date.now();return t!==null&&a<t?Math.ceil((t-a)/1e3):(e.current=e.current.filter(S=>a-S<ae),e.current.push(a),e.current.length>=ie&&(e.current=[],r(a+oe)),0)},throttled:t!==null}}const F=e=>e instanceof Error?e:new Error(String(e)),p=(e,t)=>{const r=e.get(t);return typeof r=="string"?r:""},W=(e,t)=>{const r=e.elements.namedItem(t);return r instanceof HTMLInputElement?r:void 0};function K(){const{t:e}=Q("auth");return(t,r,a)=>e(t,{defaultValue:r,...a})}function V(e,t){const r=K(),a=h("isAvailable"),S=h("status"),g=h("sendEmailVerification"),d=Y(),[y,C]=R(!1),[u,o]=R(null),[M,f]=R({}),[E,I]=R(null),_=async w=>{try{await g(w),L("success",r("verificationSent","Verification email sent."))}catch(s){L("error",q(s,r))}};return{t:r,submit:async(w,s,i)=>{if(w.preventDefault(),y||!a)return;const n=w.currentTarget,c=new FormData(n),O=s(n,c);if(f(O),I(null),Object.keys(O).length>0){o(null);return}const P=d.attempt();if(P>0){o(r("errors.rate_limit_cooldown",`Too many attempts. Please wait ${P} seconds.`,{seconds:P}));return}o(null),C(!0);try{await i(n,c)}catch(m){e==="signin"&&j(m)&&I(p(c,l.EMAIL).trim()),o(q(m,r)),t.onError?.(F(m))}finally{C(!1)}},flow:(w,s,i,n)=>({mode:e,onSubmit:w,busy:y,ready:a,unavailable:S==="degraded"||S==="error",blocked:d.throttled,error:u,fieldErrors:M,unconfirmedEmail:E,resendVerification:_,passwordMinLength:s,...i===void 0?{}:{passwordComposition:i},...n?{watchPassword:n}:{}}),resendVerification:_,setFieldErrors:f}}const N=(e,t)=>{if(t==="")return e("emailRequired","Email is required");if(!se(t))return e("emailInvalid","Invalid email address")},U=e=>Object.fromEntries(Object.entries(e).filter(([,t])=>t!==void 0));function ce(e={}){const t=V("signin",e),{t:r}=t,a=h("signInWithEmail"),S=h("sendEmailVerification"),g=h("setRememberMe"),d=h("canRememberMe"),y=C=>{t.submit(C,(u,o)=>U({email:N(r,p(o,l.EMAIL).trim()),password:p(o,l.PASSWORD)===""?r("passwordRequired","Password is required"):void 0}),async(u,o)=>{const M=W(u,l.REMEMBER_ME);M&&d()&&await g(M.checked);const f=p(o,l.EMAIL).trim();try{const E=await a(f,p(o,l.PASSWORD));if(!E?.success)throw new Error(E?.error??"Sign in failed")}catch(E){if(e.confirmation!=="code"||!j(E))throw E;try{await S(f)}catch(I){if(!H(I))throw I}e.onCodeSent?.(f);return}e.onSuccess?.()})};return t.flow(y,k)}function le(e={}){const t=V("signup",e),{t:r}=t,a=h("createUserWithEmail"),S=h("sendPasswordResetEmail"),g=e.passwordMinLength??k,d=e.confirmation??"toast",y=e.passwordComposition??!0,C=s=>{(async()=>{try{await S(s)}catch{}})()},u=b(null),o=b(""),M=b(void 0);v(()=>()=>clearTimeout(M.current),[]);const f=r("errors.breached_password","This password has appeared in a data breach. Please choose a different password."),E=s=>{if(u.current?.password===s)return u.current.breached;const i=te(s);return u.current={password:s,breached:i},i},I=s=>{o.current=s,clearTimeout(M.current),t.setFieldErrors(i=>{if(i.password!==f)return i;const{password:n,...c}=i;return c}),$(s,g,r,y)===null&&(M.current=setTimeout(()=>{E(s).then(i=>{!i||o.current!==s||t.setFieldErrors(n=>({...n,password:f}))})},G))},_=s=>{L({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:x(J,{asChild:!0,altText:r("resendEmail","Resend email"),children:x(z,{onClick:()=>{t.resendVerification(s)},children:r("resendEmail","Resend email")})})})},w=s=>{t.submit(s,(i,n)=>{const c=p(n,l.PASSWORD),O=i.elements.namedItem(l.CONFIRM_PASSWORD),P=W(i,l.CONSENT);return U({email:N(r,p(n,l.EMAIL).trim()),password:$(c,g,r,y)??void 0,confirmPassword:O&&p(n,l.CONFIRM_PASSWORD)!==c?r("confirmPasswordMismatch","Passwords do not match"):void 0,consent:P&&!P.checked?r("terms.required","Please accept the terms to continue"):void 0})},async(i,n)=>{const c=p(n,l.EMAIL).trim(),O=p(n,l.PASSWORD);if(clearTimeout(M.current),await E(O)){t.setFieldErrors({password:f});return}const P=W(i,l.CONSENT),m=p(n,l.DISPLAY_NAME).trim(),D=P?.checked||m?{...e.metadata,...P?.checked?{gdpr_consent_at:new Date().toISOString()}:{},...m?{[ne]:m}:{}}:e.metadata;try{const A=await a(c,O,D);if(!A?.success)throw new Error(A?.error??"Sign up failed");const T=!A.user?.emailVerified;e.onSuccess?.({awaitingConfirmation:T,email:c}),T&&d==="toast"&&_(c)}catch(A){if(!ee(A))throw A;e.onSuccess?.({awaitingConfirmation:!0,email:c}),d==="toast"?_(c):C(c)}})};return t.flow(w,g,e.passwordComposition,I)}function ue(e={}){const t=V("reset",e),{t:r}=t,a=h("sendPasswordResetEmail"),[S,g]=R(!1),d=y=>{g(!1),t.submit(y,(C,u)=>U({email:N(r,p(u,l.EMAIL).trim())}),async(C,u)=>{try{await a(p(u,l.EMAIL).trim())}catch(o){if(H(o)||re(o))throw o}g(!0),e.onSuccess?.(),e.toast!==!1&&L({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(d,k),sent:S}}function de(e){const t=K(),r=h("isAvailable"),a=h("verifyEmailCode"),S=h("sendEmailVerification"),g=Y(),d=e.length??X,y=e.resendCooldownSeconds??Z,[C,u]=R(""),[o,M]=R(!1),[f,E]=R(!1),[I,_]=R(null),[w,s]=R(y),[i,n]=R(!1),c=b(!1);v(()=>{if(w<=0)return;const m=setTimeout(()=>s(D=>Math.max(0,D-1)),1e3);return()=>clearTimeout(m)},[w]);const O=async m=>{const D=(m??C).trim();if(c.current||!r)return;if(n(!1),D.length!==d){_(t("codeConfirmation.incomplete",`Enter the ${d}-digit code.`,{length:d}));return}const A=g.attempt();if(A>0){_(t("errors.rate_limit_cooldown",`Too many attempts. Please wait ${A} seconds.`,{seconds:A}));return}c.current=!0,_(null),M(!0);try{const T=await a(e.email,D);e.onSuccess?.(T)}catch(T){_(B(T,t)),u(""),e.onError?.(F(T))}finally{c.current=!1,M(!1)}},P=async()=>{if(!(w>0||f||!r)){E(!0),n(!1),_(null);try{await S(e.email),s(y),n(!0)}catch(m){_(B(m,t)),e.onError?.(F(m))}finally{E(!1)}}};return{email:e.email,length:d,code:C,setCode:u,submit:O,busy:o,error:I,resend:P,resending:f,resent:i,resendIn:w,ready:r}}export{l as AUTH_FIELD,G as BREACH_PRECHECK_DEBOUNCE_MS,de as useEmailCodeConfirmation,ce as useEmailSignIn,le as useEmailSignUp,ue as usePasswordResetRequest,N as validateEmail};
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* @fileoverview Email auth rules
|
|
3
3
|
* @description The rules every email/password flow shares, framework form or app form:
|
|
4
4
|
* provider error -> user message, email format, new-password policy, breached-password
|
|
5
|
-
* check (HaveIBeenPwned k-anonymity, NIST 800-63B), confirmation-code errors
|
|
5
|
+
* check (HaveIBeenPwned k-anonymity, NIST 800-63B), confirmation-code errors, CAPTCHA
|
|
6
|
+
* failures.
|
|
6
7
|
*
|
|
7
8
|
* Provider errors are recognised by their structured code first (the error's `code`,
|
|
8
9
|
* or the provider code `wrapAuthError` keeps in `details.originalCode`), then by
|
|
@@ -28,7 +29,13 @@ export declare function isUnconfirmedError(error: unknown): boolean;
|
|
|
28
29
|
* a fake user, which the provider turns into an "already exists" message).
|
|
29
30
|
*/
|
|
30
31
|
export declare function isAlreadyRegisteredError(error: unknown): boolean;
|
|
31
|
-
/**
|
|
32
|
+
/**
|
|
33
|
+
* CAPTCHA failure: the auth server refused the token, or no token could be obtained
|
|
34
|
+
* (Turnstile script blocked, widget error, no answer in time). Structured code only:
|
|
35
|
+
* the wrapped message carries the email address, which may contain "captcha".
|
|
36
|
+
*/
|
|
37
|
+
export declare function isCaptchaError(error: unknown): boolean;
|
|
38
|
+
/** User-facing message for a provider error (CAPTCHA, rate limit, credentials, network...). */
|
|
32
39
|
export declare function authErrorMessage(error: unknown, t: AuthT): string;
|
|
33
40
|
/** Default number of characters of an emailed confirmation code. */
|
|
34
41
|
export declare const DEFAULT_CONFIRMATION_CODE_LENGTH = 6;
|
|
@@ -39,8 +46,9 @@ export declare function isCodeExpiredError(error: unknown): boolean;
|
|
|
39
46
|
/** Provider error: the confirmation code is wrong (or wrong or expired, see `otp_expired`). */
|
|
40
47
|
export declare function isInvalidCodeError(error: unknown): boolean;
|
|
41
48
|
/**
|
|
42
|
-
* User-facing message for a failed code confirmation or code resend:
|
|
43
|
-
* wrong code, rate limit (structured codes included), else
|
|
49
|
+
* User-facing message for a failed code confirmation or code resend: CAPTCHA failure
|
|
50
|
+
* (resend), expired code, wrong code, rate limit (structured codes included), else
|
|
51
|
+
* `authErrorMessage`.
|
|
44
52
|
*/
|
|
45
53
|
export declare function codeErrorMessage(error: unknown, t: AuthT): string;
|
|
46
54
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/emailAuth/rules.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/emailAuth/rules.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;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;AAwBD,oEAAoE;AACpE,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOxD;AAED,kEAAkE;AAClE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAO1D;AASD;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAShE;AAOD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAEtD;AA8CD,+FAA+F;AAC/F,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,MAAM,CAYjE;AAMD,oEAAoE;AACpE,eAAO,MAAM,gCAAgC,IAAI,CAAC;AAElD,oEAAoE;AACpE,eAAO,MAAM,+BAA+B,KAAK,CAAC;AAqBlD,sEAAsE;AACtE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAK1D;AAED,+FAA+F;AAC/F,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAQ1D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC,EAAE,KAAK,GAAG,MAAM,CAkBjE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,CAAC,EAAE,KAAK,EACR,WAAW,UAAO,GACjB,MAAM,GAAG,IAAI,CAmCf;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAsB3E"}
|
package/dist/emailAuth/rules.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const
|
|
2
|
-
`).some(n=>n.split(":")[0]?.trim()===
|
|
1
|
+
const w=8,h=/^[^\s@]+@[^\s@]+\.[^\s@]+$/;function _(e){return h.test(e)}const a=e=>(e instanceof Error?e.message:String(e)).toLowerCase();function y(e){if(typeof e!="object"||e===null)return[];const r=[];if("code"in e&&typeof e.code=="string"&&r.push(e.code),"details"in e&&typeof e.details=="object"&&e.details){const t=e.details.originalCode;typeof t=="string"&&r.push(t)}return r}const i=(e,r)=>y(e).some(t=>r.has(t));function l(e){const r=a(e);return r.includes("429")||r.includes("rate")||r.includes("too_many_requests")}function k(e){const r=a(e);return r.includes("email_not_confirmed")||r.includes("email not confirmed")||r.includes("auth/unverified-email")}const g=new Set(["user_already_exists","email_exists","auth/email-already-in-use","already-exists"]);function E(e){if(i(e,g))return!0;const r=a(e);return r.includes("already")||r.includes("exists")||r.includes("user_already_exists")||r.includes("auth/email-already-in-use")}const v=new Set(["captcha_failed","auth/captcha-check-failed"]);function o(e){return i(e,v)}const P=[{test:l,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 c(e,r){if(o(e))return r("errors.captcha_failed","The security check failed. Please try again.");const t=a(e);for(const s of P)if(s.test(t))return r(s.key,s.fallback);return r("errorGeneric","Authentication failed. Please try again.")}const x=6,S=60,b=new Set(["auth/expired-action-code"]),u=new Set(["otp_expired","auth/invalid-action-code","auth/invalid-verification-code"]),A=new Set(["over_request_rate_limit","over_email_send_rate_limit","auth/too-many-requests","rate-limit-exceeded"]);function m(e){if(i(e,b))return!0;if(i(e,u))return!1;const r=a(e);return r.includes("expired")&&!r.includes("invalid")}function f(e){if(i(e,u))return!0;const r=a(e);return r.includes("expired or is invalid")||r.includes("invalid")&&(r.includes("code")||r.includes("token")||r.includes("otp"))}function T(e,r){return o(e)?c(e,r):m(e)?r("errors.code_expired","This code has expired. Request a new code."):f(e)?r("errors.invalid_code","This code is incorrect or has expired. Check the email or request a new code."):i(e,A)?r("errors.rate_limit","Too many attempts. Please wait a moment and try again."):c(e,r)}function C(e,r,t,s=!0){return e===""?t("passwordRequired","Password is required"):e.length<r?t("passwordMinLength",`Password must be at least ${r} characters`,{count:r}):s?/[A-Z]/.test(e)?/[a-z]/.test(e)?/[0-9]/.test(e)?/[^a-zA-Z0-9]/.test(e)?null:t("passwordRequirement.special","Password must contain at least one special character"):t("passwordRequirement.number","Password must contain at least one number"):t("passwordRequirement.lowercase","Password must contain at least one lowercase letter"):t("passwordRequirement.uppercase","Password must contain at least one uppercase letter"):null}async function R(e){try{const r=await crypto.subtle.digest("SHA-1",new TextEncoder().encode(e)),t=Array.from(new Uint8Array(r)).map(n=>n.toString(16).padStart(2,"0")).join("").toUpperCase(),s=t.slice(0,5),p=t.slice(5),d=await fetch(`https://api.pwnedpasswords.com/range/${s}`,{headers:{"Add-Padding":"true"},credentials:"omit"});return d.ok?(await d.text()).split(`
|
|
2
|
+
`).some(n=>n.split(":")[0]?.trim()===p):!1}catch{return!1}}export{x as DEFAULT_CONFIRMATION_CODE_LENGTH,w as DEFAULT_PASSWORD_MIN_LENGTH,S as DEFAULT_RESEND_COOLDOWN_SECONDS,c as authErrorMessage,T as codeErrorMessage,E as isAlreadyRegisteredError,R as isBreachedPassword,o as isCaptchaError,m as isCodeExpiredError,_ as isEmail,f as isInvalidCodeError,l as isRateLimitError,k as isUnconfirmedError,C as newPasswordError};
|