1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index.esm-CGPC5mrz.js","assets/index-BmL_6VIn.js","assets/index-C2Akg_n8.css","assets/Select-eYQAyc21.js"])))=>i.map(i=>d[i]); 2import{h as we,r as s,bJ as w,bF as F,p,j as e,S as j,M as I,T as u,B as ve,aj as je,O as z,b as v,I as M,U as Z,Y as be,W as _e}from"./index-BmL_6VIn.js";import{getVerificationStatus as Pe,sendPhoneOtp as ke,verifyPhoneOtp as Se}from"./verification-CbYSW_W6.js";import{D as Ve,C as Ce,d as Ae}from"./country-codes-D4NXic_U.js";import{T as $}from"./index.esm-CGPC5mrz.js";import"./Select-eYQAyc21.js";function Ie({length:g=6,value:m,onChange:k,disabled:E}){const T=(l,i)=>{if(!/^\d?$/.test(i))return;const h=m.split("");h[l]=i;const C=h.join("").slice(0,g);if(k(C),i&&l<g-1){const V=document.getElementById(`otp-${l+1}`);V==null||V.focus()}},f=(l,i)=>{if(i.key==="Backspace"&&!m[l]&&l>0){const h=document.getElementById(`otp-${l-1}`);h==null||h.focus()}},c=l=>{const i=l.clipboardData.getData("text").replace(/\D/g,"").slice(0,g);i&&(k(i),l.preventDefault())};return e.jsx(j,{direction:"row",spacing:1,justifyContent:"center",children:Array.from({length:g}).map((l,i)=>e.jsx($,{id:`otp-${i}`,value:m[i]||"",onChange:h=>T(i,h.target.value),onKeyDown:h=>f(i,h),onPaste:c,disabled:E,inputProps:{maxLength:1,style:{textAlign:"center",fontSize:24,fontWeight:700,width:44,height:44,padding:"4px"},inputMode:"numeric"},autoFocus:i===0,sx:{width:56}},i))})}function Ee(){const g=we(),[m,k]=s.useState("email"),[E,T]=s.useState(!0),[f,c]=s.useState(!1),[l,i]=s.useState(""),[h,C]=s.useState(""),[V,W]=s.useState(!1),[B,ee]=s.useState(""),[te,ie]=s.useState(!1),[P,H]=s.useState(""),[D,ne]=s.useState(Ve),[ae,re]=s.useState(""),[A,J]=s.useState(""),[N,Y]=s.useState(!1),[se,oe]=s.useState(!1),[ce,le]=s.useState(!1),[b,q]=s.useState(0),K=s.useCallback(async()=>{try{const{getAuth:r}=await w(async()=>{const{getAuth:o}=await import("./index.esm-CGPC5mrz.js").then(d=>d.i);return{getAuth:o}},__vite__mapDeps([0,1,2,3])),t=r().currentUser;if(!t)return null;const n=await t.getIdToken(!0),a=await F(n);return a!=null&&a.needsVerification?(sessionStorage.setItem("verificationStep",a.step||"email"),"verification"):a!=null&&a.csrfToken?"complete":null}catch{return null}},[]);s.useEffect(()=>{const r=async(t=!0)=>{var n;try{const a=await Pe();if(k(a.step),ee(a.emailHint||""),a.step==="complete"){window.location.href=p.dashboard.welcome;return}if(a.step==="blocked"){g.push(p.auth.firebase.blocked);return}if(a.step==="email")try{const{getAuth:o,sendEmailVerification:d}=await w(async()=>{const{getAuth:S,sendEmailVerification:_}=await import("./index.esm-CGPC5mrz.js").then(x=>x.i);return{getAuth:S,sendEmailVerification:_}},__vite__mapDeps([0,1,2,3])),y=o().currentUser;y&&!y.emailVerified&&(await d(y),ie(!0),O())}catch{}}catch(a){if(((n=a==null?void 0:a.response)==null?void 0:n.status)===401){const o=t&&await K();if(o==="verification"){r(!1);return}if(o==="complete"){window.location.href=p.dashboard.welcome;return}g.push(p.auth.firebase.login);return}i("Failed to load verification status")}T(!1)};r()},[K]);const O=s.useCallback(()=>{q(60)},[]);s.useEffect(()=>{if(b<=0)return;const r=setTimeout(()=>q(t=>t-1),1e3);return()=>clearTimeout(r)},[b]),s.useEffect(()=>{if(m!=="email")return;const r=setInterval(async()=>{try{const{getAuth:t}=await w(async()=>{const{getAuth:a}=await import("./index.esm-CGPC5mrz.js").then(o=>o.i);return{getAuth:a}},__vite__mapDeps([0,1,2,3])),n=t().currentUser;if(!n)return;await n.reload(),n.emailVerified&&(clearInterval(r),G())}catch{}},5e3);return()=>clearInterval(r)},[m]);const G=async()=>{i(""),c(!0);try{const{getAuth:r}=await w(async()=>{const{getAuth:o}=await import("./index.esm-CGPC5mrz.js").then(d=>d.i);return{getAuth:o}},__vite__mapDeps([0,1,2,3])),t=r().currentUser;if(!t){i("Session expired. Please sign in again."),c(!1);return}if(await t.reload(),!t.emailVerified){i("Email not yet verified. Please click the link in the email we sent you."),c(!1);return}const n=await t.getIdToken(!0),a=await F(n);a!=null&&a.needsVerification&&a.step==="phone"?k("phone"):a!=null&&a.needsVerification?i("We could not confirm your email verification yet. Please wait a moment and try again."):window.location.href=p.dashboard.welcome}catch{i("Could not verify email status. Please try again.")}c(!1)},de=async()=>{i(""),c(!0);try{const{getAuth:r,sendEmailVerification:t}=await w(async()=>{const{getAuth:a,sendEmailVerification:o}=await import("./index.esm-CGPC5mrz.js").then(d=>d.i);return{getAuth:a,sendEmailVerification:o}},__vite__mapDeps([0,1,2,3])),n=r().currentUser;n?(await t(n),C("Verification email sent! Check your inbox."),O(),setTimeout(()=>C(""),3e3)):i("Session expired. Please sign in again.")}catch(r){(r==null?void 0:r.code)==="auth/too-many-requests"?i("Too many attempts. Please wait a few minutes and try again."):i("Failed to send verification email. Please try again.")}c(!1)},[Q,ue]=s.useState(null),he=async()=>{c(!0),i("");try{const{getAuth:r}=await w(async()=>{const{getAuth:o}=await import("./index.esm-CGPC5mrz.js").then(d=>d.i);return{getAuth:o}},__vite__mapDeps([0,1,2,3])),t=r().currentUser;if(!t){i("Session expired. Please sign in again."),c(!1);return}const n=await t.getIdToken(!0),a=await F(n);if(a!=null&&a.needsVerification&&a.step==="email"){k("email"),c(!1);return}window.location.href=p.dashboard.welcome}catch{i("Could not continue. Please try again."),c(!1)}},X=async()=>{var r,t;if(P){i(""),c(!0);try{const n=Ae(D),a=await ke(P,n);if(a.regionRestricted){oe(!0),c(!1);return}re(a.phoneHint);const{getAuth:o,PhoneAuthProvider:d,RecaptchaVerifier:y}=await w(async()=>{const{getAuth:L,PhoneAuthProvider:U,RecaptchaVerifier:ye}=await import("./index.esm-CGPC5mrz.js").then(xe=>xe.i);return{getAuth:L,PhoneAuthProvider:U,RecaptchaVerifier:ye}},__vite__mapDeps([0,1,2,3])),S=o();window._recaptchaVerifier||(window._recaptchaVerifier=new y(S,"recaptcha-container",{size:"invisible"}));const _=P.startsWith("+")?P:`+${n}${P.replace(/^0+/,"")}`,R=await new d(S).verifyPhoneNumber(_,window._recaptchaVerifier);ue(R),Y(!0),O()}catch(n){if(window._recaptchaVerifier){try{window._recaptchaVerifier.clear()}catch{}window._recaptchaVerifier=null}console.error("Phone send error:",n),(t=(r=n==null?void 0:n.response)==null?void 0:r.data)!=null&&t.error?i(n.response.data.error):(n==null?void 0:n.code)==="auth/too-many-requests"?i("Too many attempts. Please try again later."):(n==null?void 0:n.code)==="auth/invalid-phone-number"?i("Invalid phone number. Please check and try again."):i("Failed to send verification code. Please try again.")}c(!1)}},fe=async()=>{try{const{default:r}=await w(async()=>{const{default:t}=await import("./index-BmL_6VIn.js").then(n=>n.fb);return{default:t}},__vite__mapDeps([1,2]));
2await r.post("/auth/waitlist",{email:B,country:D})}catch{i("Could not join the waitlist. Please try again.");return}le(!0)},me=async()=>{var r;if(!(A.length<6||!Q)){i(""),W(!1),c(!0);try{const{PhoneAuthProvider:t,linkWithCredential:n,getAuth:a}=await w(async()=>{const{PhoneAuthProvider:x,linkWithCredential:R,getAuth:L}=await import("./index.esm-CGPC5mrz.js").then(U=>U.i);return{PhoneAuthProvider:x,linkWithCredential:R,getAuth:L}},__vite__mapDeps([0,1,2,3])),o=t.credential(Q,A),d=a(),y=d.currentUser;if(y)try{await n(y,o)}catch(x){if((x==null?void 0:x.code)!=="auth/provider-already-linked")throw x}const S=await(y||d.currentUser).getIdToken(!0),_=await Se(S);_.verified?(_.csrfToken&&sessionStorage.setItem("csrfToken",_.csrfToken),_.nextStep==="login"?window.location.href=p.auth.firebase.login:window.location.href=p.dashboard.welcome):i("Phone verification failed. Please check the code and try again.")}catch(t){console.error("Phone verify error:",t);const n=(r=t==null?void 0:t.response)==null?void 0:r.data;if((n==null?void 0:n.error)==="ACCOUNT_BLOCKED"){g.push(p.auth.firebase.blocked);return}(t==null?void 0:t.code)==="auth/account-exists-with-different-credential"||(t==null?void 0:t.code)==="auth/credential-already-in-use"?(W(!0),i("Oops â it looks like this phone number is already registered under a different account. Please log in instead.")):(t==null?void 0:t.code)==="auth/invalid-verification-code"?i("Invalid verification code. Please try again."):(t==null?void 0:t.code)==="auth/code-expired"?i("Verification code expired. Please request a new one."):i((n==null?void 0:n.error)||"Verification failed. Please try again.")}c(!1)}};if(E)return e.jsxs(j,{alignItems:"center",spacing:3,sx:{py:5},children:[e.jsx(I,{}),e.jsx(u,{variant:"body2",color:"text.secondary",children:"Loading verification status..."})]});const pe=m==="email"?25:m==="phone"?75:100,ge=m==="email"?"Step 1 of 2 â Verify Email":"Step 2 of 2 â Verify Phone";return e.jsxs(j,{spacing:3,sx:{maxWidth:440,mx:"auto"},children:[e.jsxs(ve,{children:[e.jsx(u,{variant:"caption",color:"text.secondary",sx:{mb:.5,display:"block"},children:ge}),e.jsx(je,{variant:"determinate",value:pe,sx:{height:6,borderRadius:3}})]}),!!l&&e.jsx(z,{severity:"error",onClose:()=>{i(""),W(!1)},action:V?e.jsx(v,{color:"inherit",size:"small",onClick:()=>g.push(p.auth.firebase.login),children:"Log in"}):void 0,children:l}),!!h&&e.jsx(z,{severity:"success",children:h}),m==="email"&&e.jsxs(j,{spacing:2.5,alignItems:"center",children:[e.jsx(M,{icon:"mdi:email-check-outline",width:64,sx:{color:"primary.main"}}),e.jsx(u,{variant:"h5",textAlign:"center",children:"Verify your email"}),e.jsx(u,{variant:"body2",color:"text.secondary",textAlign:"center",children:te?e.jsxs(e.Fragment,{children:["We sent a verification link to ",e.jsx("strong",{children:B}),". Click the link to verify your account."]}):"We need to verify your email address"}),e.jsx(v,{fullWidth:!0,variant:"contained",size:"large",onClick:G,disabled:f,children:f?e.jsx(I,{size:22}):"I've verified my email"}),e.jsxs(j,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(v,{size:"small",disabled:b>0||f,onClick:de,children:b>0?`Resend in ${b}s`:"Resend verification email"}),e.jsx(u,{variant:"caption",color:"text.secondary",children:"|"}),e.jsx(Z,{href:p.auth.firebase.register,variant:"caption",underline:"hover",children:"Wrong email?"})]}),e.jsx(u,{variant:"caption",color:"text.secondary",textAlign:"center",children:"Don't see the email? Check your spam folder."})]}),m==="phone"&&e.jsxs(j,{spacing:2.5,alignItems:"center",children:[e.jsx(M,{icon:"mdi:cellphone-check",width:64,sx:{color:"primary.main"}}),e.jsx(u,{variant:"h5",textAlign:"center",children:"Verify your phone number"}),se?e.jsxs(j,{spacing:2.5,alignItems:"center",sx:{width:"100%"},children:[e.jsx(M,{icon:"mdi:earth",width:56,sx:{color:"primary.main"}}),e.jsx(u,{variant:"h6",textAlign:"center",children:"We're expanding â your region is next"}),e.jsx(u,{variant:"body2",color:"text.secondary",textAlign:"center",sx:{maxWidth:360},children:"Swifi isn't available in your area just yet, but we're working on it. Join the waitlist and we'll let you know the moment we go live in your region."}),ce?e.jsxs(z,{severity:"success",sx:{width:"100%"},children:[e.jsx(u,{variant:"subtitle2",children:"You're on the list!"}),e.jsx(u,{variant:"body2",children:"We'll email you as soon as Swifi is available in your region."})]}):e.jsx(v,{fullWidth:!0,variant:"contained",size:"large",onClick:fe,children:"Notify Me When Available"})]}):e.jsxs(e.Fragment,{children:[e.jsx(u,{variant:"body2",color:"text.secondary",textAlign:"center",children:N?e.jsxs(e.Fragment,{children:["We sent a 6-digit code to ",e.jsx("strong",{children:ae})]}):"Enter your mobile phone number to receive an SMS verification code"}),N?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{value:A,onChange:J,disabled:f}),e.jsx(v,{fullWidth:!0,variant:"contained",size:"large",onClick:me,disabled:A.length<6||f,children:f?e.jsx(I,{size:22}):"Verify & Continue"}),e.jsxs(j,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(v,{size:"small",disabled:b>0||f,onClick:X,children:b>0?`Resend in ${b}s`:"Resend code"}),e.jsx(u,{variant:"caption",color:"text.secondary",children:"|"}),e.jsx(v,{size:"small",onClick:()=>{Y(!1),J(""),H("")},children:"Use different number"})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs(j,{direction:"row",spacing:1,sx:{width:"100%"},children:[e.jsx($,{select:!0,value:D,onChange:r=>ne(r.target.value),sx:{width:120},size:"small",children:Ce.map(r=>e.jsx(be,{value:r.code,children:r.label},r.code))}),e.jsx($,{fullWidth:!0,placeholder:"Phone number",value:P,onChange:r=>H(r.target.value.replace(/[^\d\s\-()]/g,"")),inputProps:{inputMode:"tel"},size:"small"})]}),e.jsx(v,{fullWidth:!0,variant:"contained",size:"large",onClick:X,disabled:!P||f,children:f?e.jsx(I,{size:22}):"Send Code"}),e.jsx(v,{fullWidth:!0,variant:"text",onClick:he,disabled:f,sx:{textTransform:"none"},children:"Skip for now"})]})]})]}),e.jsxs(u,{variant:"caption",color:"text.secondary",textAlign:"center",sx:{mt:2},children:["Having trouble?"," ",e.jsx(Z,{component:"button",type:"button",onClick:()=>g.push("/"),underline:"hover",children:"Try a different way to register"})]}),e.jsx("div",{id:"recaptcha-container"})]})}function Le(){return e.jsxs(e.Fragment,{children:[e.jsx(_e,{children:e.jsx("title",{children:"Verify Identity | Swifi"})}),e.jsx(Ee,{})]})}
2export{Le as default};
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.