1import{R as V}from"./Route-COt318Xd.js";import{S as oe}from"./Switch-DmB6VzwQ.js";import{u as x,U as ie}from"./UserVerification-DuFTIZJp.js";import{w as ne}from"./CoreSessionContext-Cyg8p_kb.js";import{F as S}from"./Flow-DYcRxnR6.js";import{u as ae}from"./useFetch-CeEMHtWk.js";import{a as E}from"./LoadingCard-CoX17MQ-.js";import{aw as _,r as C,ag as t,H as g,au as d,ao as N,dn as ce}from"./index-DPTR8SUU.js";import{u as K}from"./RouteContext-DooD8wnV.js";import{u as se}from"./EnvironmentContext-CQboXQOe.js";import{l as i}from"./localizationKeys-L95TEc06.js";import{useCardState as F,withCardStateProvider as O}from"./index-O9HX6HaF.js";import{E as $,f as le,l as de,c as ue,H as he,u as fe}from"./lock-closed-CNCwSjz8.js";import{i as me,f as U,a as pe,b as ve,B as ke,u as ge,c as Ce,e as ye}from"./utils-D4EchzYI.js";import{e as we}from"./email-DVb4rXTM.js";import{o as be}from"./organization-BilMzskE.js";import{d as v}from"./makeCustomizable-D07FPO4y.js";import{F as D,C as A,u as G,b as Ae}from"./index-BeSwAJIs.js";import{C as l}from"./index-9SYFp_L9.js";import{H as m}from"./Header-B6g2MQOq.js";import{f as H}from"./IdentityPreview-OijIpuz5.js";import{A as W}from"./ArrowBlockButton-wLQT7qL6.js";import{h as L}from"./errorHandler-ViTaZyoV.js";import{F as y}from"./Form-B7mwjqJ4.js";import{a as q}from"./VerificationCodeCard-BCzuM-19.js";import"./useNavigateToFlowStart-Ckf-z2Mf.js";import"./url-DaPDWryr-BC7huNZB.js";import"./underscore-ClYSgvuy-PzdM3hke.js";import"./index-C5_Cokrr.js";import"./AppearanceContext-Dgqrkims.js";import"./OptionsContext-DGk3M2jG.js";import"./makeLocalizable-CaGNZFeC.js";import"./floating-ui.react-BqeiQk47.js";import"./CardAlert-Bds41LSP.js";import"./Alert-CmvIN3uU.js";import"./usePrefersReducedMotion-CHOIO4TQ.js";import"./IconButton-BwGv6XgB.js";import"./Modal-DzOx54AS.js";import"./useScrollLock-DtPRJxpD.js";import"./useLoadingStatus-Dsevz7VV.js";import"./sleep-BvINh1mj.js";import"./index-LRr-cCrn.js";import"./index-CV_5pF5X.js";import"./chevron-down-B8oWUdXo.js";import"./eye-DEdgHYtr.js";import"./check-uXtykPQa.js";const Se=()=>{const{level:e}=x();return C.useMemo(()=>({level:e||"second_factor"}),[e])},T=()=>{const{session:e}=_(),r=Se();return{...ae(e?e.startVerification:void 0,r,{throttleTime:300})}};function j(e){const r=s=>{const{isLoading:o,data:n}=T();return o||!n?t(E,{}):t(e,{...s})},a=e.displayName||e.name||"Component";return e.displayName=a,r.displayName=a,r}const Fe=(e,r)=>!e||!r?!1:e.strategy==="email_code"&&r.strategy==="email_code"?e.emailAddressId===r.emailAddressId:e.strategy==="phone_code"&&r.strategy==="phone_code"?e.phoneNumberId===r.phoneNumberId:e.strategy===r.strategy,Me=(e,r)=>!e||!r?!1:e.strategy==="phone_code"&&r.strategy==="phone_code"?e.phoneNumberId===r.phoneNumberId:e.strategy===r.strategy;function J({filterOutFactor:e,supportedFirstFactors:r}){const a=r?r.filter(n=>!me(n.strategy)):[],s=a&&a.length>0,o=C.useMemo(()=>r?r.filter(n=>!n.strategy.startsWith("oauth_")).filter(n=>U(n)).filter(n=>!Fe(n,e)).filter(n=>n.strategy==="passkey"?pe():!0).sort(ve):[],[r,e]);return{hasAnyStrategy:s,hasFirstParty:o&&o.length>0,firstPartyFactors:o}}const Q=e=>{const{onBackLinkClick:r}=e;return t($,{cardTitle:i("reverification.alternativeMethods.getHelp.title"),cardSubtitle:i("reverification.alternativeMethods.getHelp.content"),onBackLinkClick:r})},_e=(e,r)=>{const[a,s]=g.useState(!1),o=g.useCallback(()=>s(n=>!n),[s]);return a?t(Q,{onBackLinkClick:o}):t(e,{...r,onHavingTroubleClick:o})},Be=e=>_e(Te,{...e}),Te=e=>{const{onBackLinkClick:r,onHavingTroubleClick:a,onFactorSelected:s}=e,o=F(),{data:n}=T(),{firstPartyFactors:u,hasAnyStrategy:c}=J({filterOutFactor:e==null?void 0:e.currentFactor,supportedFirstFactors:n==null?void 0:n.supportedFirstFactors});return t(S.Part,{part:"alternativeMethods",children:d(l.Root,{children:[d(l.Content,{children:[d(m.Root,{children:[t(m.Title,{localizationKey:i("reverification.alternativeMethods.title")}),t(m.Subtitle,{localizationKey:i("reverification.alternativeMethods.subtitle")})]}),t(l.Alert,{children:o.error}),t(D,{direction:"col",elementDescriptor:v.main,gap:6,children:d(A,{gap:4,children:[c&&t(D,{elementDescriptor:v.alternativeMethods,direction:"col",gap:2,children:u.map((h,p)=>t(W,{leftIcon:Pe(h),textLocalizationKey:Le(h),elementDescriptor:v.alternativeMethodsBlockButton,textElementDescriptor:v.alternativeMethodsBlockButtonText,arrowElementDescriptor:v.alternativeMethodsBlockButtonArrow,textVariant:"buttonLarge",isDisabled:o.isLoading,onClick:()=>{o.setError(void 0),s(h)}},p))}),r&&t(ke,{boxElementDescriptor:v.backRow,linkElementDescriptor:v.backLink,onClick:r})]})})]}),t(l.Footer,{children:d(l.Action,{elementId:"havingTrouble",children:[t(l.ActionText,{localizationKey:i("reverification.alternativeMethods.actionText")}),t(l.ActionLink,{localizationKey:i("reverification.alternativeMethods.actionLink"),onClick:a})]})})]})})};function Le(e){switch(e.strategy){case"email_code":return i("reverification.alternativeMethods.blockButton__emailCode",{identifier:H(e.safeIdentifier)||""});case"phone_code":return i("reverification.alternativeMethods.blockButton__phoneCode",{identifier:H(e.safeIdentifier)||""});case"password":return i("reverification.alternativeMethods.blockButton__password");case"passkey":return i("reverification.alternativeMethods.blockButton__passkey");default:throw new Error(`Invalid sign in strategy: "${e.strategy}"`)}}function Pe(e){return{email_code:we,phone_code:ue,password:de,passkey:le,enterprise_sso:be}[e.strategy]}const P=()=>{const{afterVerification:e}=x(),r=ge(),{setActive:a}=N(),{setCache:s}=T(),{navigate:o}=K();return{handleVerificationResponse:C.useCallback(async n=>{switch(s({data:n,isLoading:!1,isValidating:!1,error:null,cachedAt:Date.now()}),n.status){case"complete":return await a({session:n.session.id}),e==null?void 0:e();case"needs_second_factor":return o("./factor-two");default:return console.error(ce(n.status,r))}},[o,a,r])}};function Ie(e){const{onShowAlternativeMethodsClick:r}=e,{session:a}=_(),{handleVerificationResponse:s}=P(),o=F(),[n,u]=g.useState(!1),c=g.useCallback(()=>u(f=>!f),[u]),h=G("password","",{type:"password",label:i("formFieldLabel__password"),placeholder:i("formFieldInputPlaceholder__password")}),p=async f=>(f.preventDefault(),a==null?void 0:a.attemptFirstFactorVerification({strategy:"password",password:h.value}).then(s).catch(M=>L(M,[h],o.setError)));return n?t(he,{onBackLinkClick:c}):t(S.Part,{part:"password",children:d(l.Root,{children:[d(l.Content,{children:[d(m.Root,{children:[t(m.Title,{localizationKey:i("reverification.password.title")}),t(m.Subtitle,{localizationKey:i("reverification.password.subtitle")})]}),t(l.Alert,{children:o.error}),d(A,{elementDescriptor:v.main,gap:4,children:[d(y.Root,{onSubmit:p,gap:8,children:[t(y.ControlRow,{elementId:h.id,children:t(y.PasswordInput,{...h.props,autoFocus:!0})}),t(y.SubmitButton,{hasArrow:!0})]}),t(l.Action,{elementId:r?"alternativeMethods":"havingTrouble",children:t(l.ActionLink,{localizationKey:i(r?"reverification.password.actionLink":"reverification.alternativeMethods.actionLink"),onClick:r||c})})]})]}),t(l.Footer,{})]})})}function X(e,r){return"primary"in e&&e.primary&&!("primary"in r&&r.primary)?-1:"primary"in r&&r.primary&&!("primary"in e&&e.primary)?1:0}const Y=e=>{var u;const{session:r}=_(),a=F(),{handleVerificationResponse:s}=P();g.useEffect(()=>{e.factorAlreadyPrepared||o()},[]);const o=()=>{r.prepareFirstFactorVerification(e.factor).then(()=>e.onFactorPrepare()).catch(c=>L(c,[],a.setError))},n=(c,h,p)=>{r.attemptFirstFactorVerification({strategy:e.factor.strategy,code:c}).then(async f=>(await h(),s(f))).catch(p)};return t(q,{cardTitle:e.cardTitle,cardSubtitle:e.cardSubtitle,inputLabel:e.inputLabel,resendButton:e.resendButton,onCodeEntryFinishedAction:n,onResendCodeClicked:o,safeIdentifier:e.factor.safeIdentifier,profileImageUrl:(u=r==null?void 0:r.user)==null?void 0:u.imageUrl,onShowAlternativeMethodsClicked:e.onShowAlternativeMethodsClicked,showAlternativeMethods:e.showAlternativeMethods,onBackLinkClicked:e.onBackLinkClicked})},Ee=e=>t(S.Part,{part:"emailCode",children:t(Y,{...e,cardTitle:i("reverification.emailCode.title"),cardSubtitle:i("reverification.emailCode.subtitle"),inputLabel:i("reverification.emailCode.formTitle"),resendButton:i("reverification.emailCode.resendButton")})}),Re=e=>{const{onShowAlternativeMethodsClicked:r}=e,{session:a}=_(),{__internal_isWebAuthnSupported:s}=N(),{handleVerificationResponse:o}=P(),n=F(),u=()=>{a==null||a.verifyWithPasskey().then(c=>o(c)).catch(c=>L(c,[],n.setError))};return d(l.Root,{children:[d(l.Content,{children:[d(m.Root,{children:[t(m.Title,{localizationKey:i("reverification.passkey.title")}),t(m.Subtitle,{localizationKey:i("reverification.passkey.subtitle")})]}),t(l.Alert,{children:n.error}),t(A,{elementDescriptor:v.main,gap:8,children:t(y.Root,{children:d(A,{gap:3,children:[t(Ae,{type:"button",onClick:c=>{c.preventDefault(),u()},localizationKey:i("reverification.passkey.blockButton__passkey"),hasArrow:!0}),t(l.Action,{elementId:"alternativeMethods",children:r&&t(l.ActionLink,{localizationKey:i("footerActionLink__useAnotherMethod"),onClick:r})})]})})})]}),t(l.Footer,{})]})},Ve=e=>t(S.Part,{part:"phoneCode",children:t(Y,{...e,cardTitle:i("reverification.phoneCode.title"),cardSubtitle:i("reverification.phoneCode.subtitle"),inputLabel:i("reverification.phoneCode.formTitle"),resendButton:i("reverification.phoneCode.resendButton"),showAlternativeMethods:e.showAlternativeMethods})}),R=e=>{if(!e)return"";let r=e.strategy;return"emailAddressId"in e&&(r+=e.emailAddressId),"phoneNumberId"in e&&(r+=e.phoneNumberId),r},Ue=["password","email_code","phone_code","passkey"];function He(){const{data:e}=T(),r=F(),{navigate:a}=K(),s=g.useRef(""),o=e,n=C.useMemo(()=>{var b,k;return((k=(b=o.supportedFirstFactors)==null?void 0:b.filter(z=>Ue.includes(z.strategy)))==null?void 0:k.sort(X))||null},[o.supportedFirstFactors]),{preferredSignInStrategy:u}=se().displayConfig,[{currentFactor:c},h]=g.useState(()=>({currentFactor:Ce(n,null,u),prevCurrentFactor:void 0})),{hasAnyStrategy:p,hasFirstParty:f}=J({filterOutFactor:c,supportedFirstFactors:n}
1),[M,B]=g.useState(()=>!c||!U(c)),w=p?()=>{r.setError(void 0),B(b=>!b)}:void 0,I=()=>{s.current=R(c)},te=b=>{h(k=>({currentFactor:b,prevCurrentFactor:k.currentFactor}))};if(C.useEffect(()=>{o.status==="needs_second_factor"&&a("factor-two")},[]),!c)return t($,{cardTitle:i("reverification.noAvailableMethods.title"),cardSubtitle:i("reverification.noAvailableMethods.subtitle"),message:i("reverification.noAvailableMethods.message"),shouldNavigateBack:!1});if(M){const b=U(c),k=w;return t(Be,{onBackLinkClick:b?()=>{r.setError(void 0),k==null||k()}:void 0,onFactorSelected:re=>{te(re),k==null||k()},currentFactor:c})}switch(c==null?void 0:c.strategy){case"password":return t(Ie,{onShowAlternativeMethodsClick:w});case"email_code":return t(Ee,{factorAlreadyPrepared:s.current===R(c),onFactorPrepare:I,onShowAlternativeMethodsClicked:w,factor:c,showAlternativeMethods:f});case"phone_code":return t(Ve,{factorAlreadyPrepared:s.current===R(c),onFactorPrepare:I,onShowAlternativeMethodsClicked:w,factor:c,showAlternativeMethods:f});case"passkey":return t(Re,{onShowAlternativeMethodsClicked:w});default:return t(E,{})}}const Ke=j(O(He)),Z=e=>{var u;const r=F(),{session:a}=_(),{handleVerificationResponse:s}=P();g.useEffect(()=>{e.factorAlreadyPrepared||o==null||o()},[]);const o=e.prepare?()=>{var c;return(c=e.prepare)==null?void 0:c.call(e).then(()=>e.onFactorPrepare()).catch(h=>L(h,[],r.setError))}:void 0,n=(c,h,p)=>{a.attemptSecondFactorVerification({strategy:e.factor.strategy,code:c}).then(async f=>(await h(),s(f))).catch(p)};return t(q,{cardTitle:e.cardTitle,cardSubtitle:e.cardSubtitle,resendButton:e.resendButton,inputLabel:e.inputLabel,onCodeEntryFinishedAction:n,onResendCodeClicked:o,safeIdentifier:"safeIdentifier"in e.factor?e.factor.safeIdentifier:void 0,profileImageUrl:(u=a==null?void 0:a.user)==null?void 0:u.imageUrl,onShowAlternativeMethodsClicked:e.onShowAlternativeMethodsClicked,showAlternativeMethods:e.showAlternativeMethods})};function ze(e){return t(S.Part,{part:"totp2Fa",children:t(Z,{...e,cardTitle:i("reverification.totpMfa.title"),cardSubtitle:i("reverification.totpMfa.subtitle"),inputLabel:i("reverification.totpMfa.formTitle"),showAlternativeMethods:e.showAlternativeMethods})})}const De=e=>{const[r,a]=g.useState(!1),s=g.useCallback(()=>a(o=>!o),[a]);return r?t(Q,{onBackLinkClick:s}):t(xe,{supportedSecondFactors:e.supportedSecondFactors,onBackLinkClick:e.onBackLinkClick,onFactorSelected:e.onFactorSelected,onHavingTroubleClick:s})},xe=e=>{const{supportedSecondFactors:r,onHavingTroubleClick:a,onFactorSelected:s,onBackLinkClick:o}=e,n=F();return t(S.Part,{part:"alternativeMethods",children:d(l.Root,{children:[d(l.Content,{children:[d(m.Root,{children:[t(m.Title,{localizationKey:i("reverification.alternativeMethods.title")}),t(m.Subtitle,{localizationKey:i("reverification.alternativeMethods.subtitle")})]}),t(l.Alert,{children:n.error}),d(A,{elementDescriptor:v.main,gap:3,children:[t(A,{gap:2,children:r==null?void 0:r.sort(ye).map((u,c)=>t(W,{textLocalizationKey:Ne(u),elementDescriptor:v.alternativeMethodsBlockButton,textElementDescriptor:v.alternativeMethodsBlockButtonText,arrowElementDescriptor:v.alternativeMethodsBlockButtonArrow,isDisabled:n.isLoading,onClick:()=>s(u)},c))}),t(l.Action,{elementId:"alternativeMethods",children:o&&t(l.ActionLink,{localizationKey:i("backButton"),onClick:e.onBackLinkClick})})]})]}),t(l.Footer,{children:d(l.Action,{elementId:"havingTrouble",children:[t(l.ActionText,{localizationKey:i("reverification.alternativeMethods.actionText")}),t(l.ActionLink,{localizationKey:i("reverification.alternativeMethods.actionLink"),onClick:a})]})})]})})};function Ne(e){switch(e.strategy){case"phone_code":return i("reverification.alternativeMethods.blockButton__phoneCode",{identifier:H(e.safeIdentifier)||""});case"totp":return i("reverification.alternativeMethods.blockButton__totp");case"backup_code":return i("reverification.alternativeMethods.blockButton__backupCode");default:throw new Error(`Invalid verification strategy: "${e.strategy}"`)}}const Oe=e=>{const{onShowAlternativeMethodsClicked:r}=e,{session:a}=_(),{handleVerificationResponse:s}=P(),o=F(),n=G("code","",{type:"text",label:i("formFieldLabel__backupCode"),isRequired:!0}),u=c=>(c.preventDefault(),a.attemptSecondFactorVerification({strategy:"backup_code",code:n.value}).then(s).catch(h=>L(h,[n],o.setError)));return d(l.Root,{children:[d(l.Content,{children:[d(m.Root,{children:[t(m.Title,{localizationKey:i("reverification.backupCodeMfa.title")}),t(m.Subtitle,{localizationKey:i("reverification.backupCodeMfa.subtitle")})]}),t(l.Alert,{children:o.error}),t(A,{elementDescriptor:v.main,gap:8,children:d(y.Root,{onSubmit:u,children:[t(y.ControlRow,{elementId:n.id,children:t(y.PlainInput,{...n.props,autoFocus:!0,onActionClicked:r})}),d(A,{gap:3,children:[t(y.SubmitButton,{hasArrow:!0}),t(l.Action,{elementId:"alternativeMethods",children:r&&t(l.ActionLink,{localizationKey:i("footerActionLink__useAnotherMethod"),onClick:r})})]})]})})]}),t(l.Footer,{})]})},$e=e=>{const{session:r}=_(),a=()=>{const{phoneNumberId:s,strategy:o}=e.factor;return r.prepareSecondFactorVerification({phoneNumberId:s,strategy:o})};return t(S.Part,{part:"phoneCode2Fa",children:t(Z,{...e,cardTitle:i("reverification.phoneCodeMfa.title"),cardSubtitle:i("reverification.phoneCodeMfa.subtitle"),inputLabel:i("reverification.phoneCodeMfa.formTitle"),resendButton:i("reverification.phoneCodeMfa.resendButton"),prepare:a})})},Ge=["phone_code","totp","backup_code"];function We(){const{navigate:e}=K(),{data:r}=T(),a=r,s=C.useMemo(()=>{var B,w;return((w=(B=a.supportedSecondFactors)==null?void 0:B.filter(I=>Ge.includes(I.strategy)))==null?void 0:w.sort(X))||null},[a.supportedSecondFactors]),{currentFactor:o,factorAlreadyPrepared:n,handleFactorPrepare:u,selectFactor:c,showAllStrategies:h,toggleAllStrategies:p}=fe(s),f=C.useMemo(()=>
1s==null?void 0:s.filter(B=>!Me(B,o)),[s,o]),M=C.useMemo(()=>f&&f.length>0||!1,[f]);if(C.useEffect(()=>{a.status==="needs_first_factor"&&e("../")},[]),!o)return t(E,{});if(h&&M)return t(De,{supportedSecondFactors:f||null,onBackLinkClick:p,onFactorSelected:c});switch(o==null?void 0:o.strategy){case"phone_code":return t($e,{factorAlreadyPrepared:n,onFactorPrepare:u,factor:o,onShowAlternativeMethodsClicked:p,showAlternativeMethods:M});case"totp":return t(ze,{factorAlreadyPrepared:n,onFactorPrepare:u,factor:o,onShowAlternativeMethodsClicked:p,showAlternativeMethods:M});case"backup_code":return t(Oe,{onShowAlternativeMethodsClicked:p});default:return t(E,{})}}const qe=j(O(We));function ee(){const{invalidate:e}=T();return C.useEffect(()=>()=>{e()},[]),t(S.Root,{flow:"userVerification",children:d(oe,{children:[t(V,{path:"factor-two",children:t(qe,{})}),t(V,{index:!0,children:t(Ke,{})})]})})}ee.displayName="UserVerification";const je=ne(ee),xt=e=>t(V,{path:"user-verification",children:t(ie.Provider,{value:{componentName:"UserVerification",...e,routing:"virtual"},children:t("div",{children:t(je,{...e,routing:"virtual"})})})});export{je as UserVerification,xt as UserVerificationModal};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.