1import{r as n,t as k,V as p,j as e,f as v,L as j,I as N,E as O,e as F}from"./index-D4jNfbJ2.js";import{a as L}from"./agora-sun.png.asset-BANnjqih.js";import{A as S}from"./arrow-right-D1NdOM45.js";const M=3e3;function H(){if(typeof window>"u")return{errorMessage:null,tokenHash:null,code:null,hasAccessToken:!1};const t=new URLSearchParams(window.location.search),i=window.location.hash.startsWith("#")?window.location.hash.slice(1):window.location.hash,r=new URLSearchParams(i),x=r.get("error_code")??t.get("error_code"),l=r.get("error_description")??t.get("error_description")??r.get("error")??t.get("error");return{errorMessage:_(x,l),tokenHash:t.get("token_hash")??r.get("token_hash"),code:t.get("code"),hasAccessToken:!!r.get("access_token")}}function _(t,i){if(!t&&!i)return null;const r=`${t??""} ${i??""}`;return/otp_expired|expired/i.test(r)?"This reset link has expired or was already used. Reset links only work once â request a new one below.":/access_denied|invalid/i.test(r)?"This reset link isn't valid. It may have already been used. Request a new one below.":i?i.replace(/\+/g," "):"This reset link didn't work. Request a new one below."}function Y(){const[t,i]=n.useState(""),[r,x]=n.useState(""),[l,R]=n.useState(!1),[g,f]=n.useState(""),[w,y]=n.useState(!1),[E,T]=n.useState(!1),[b,A]=n.useState(null),[P,C]=n.useState(!1),h=n.useRef(!1);n.useEffect(()=>{let s=!1;const o=setTimeout(()=>{c("We couldn't verify this reset link. It may have expired or already been used. Request a new one below.","timeout")},M);function m(){s||h.current||(h.current=!0,clearTimeout(o),T(!0))}function c(a,d){s||h.current||(h.current=!0,clearTimeout(o),k("password_reset_link_failed",{reason:d}),A(a))}const{data:{subscription:I}}=p.auth.onAuthStateChange((a,d)=>{(a==="PASSWORD_RECOVERY"||d)&&m()});return(async()=>{const a=H();if(a.errorMessage){c(a.errorMessage,"url_error");return}const{data:d}=await p.auth.getSession();if(!s){if(d.session){m();return}if(a.tokenHash){const{error:u}=await p.auth.verifyOtp({type:"recovery",token_hash:a.tokenHash});if(s)return;u?c(_(null,u.message)??u.message,"verify_otp_failed"):m();return}if(a.code){const{error:u}=await p.auth.exchangeCodeForSession(a.code);if(s)return;u?c("This reset link needs to be opened on the same device and browser you requested it from. Request a new one below.","code_exchange_failed"):m();return}a.hasAccessToken||c("This page needs a reset link from your email. Request one below.","no_token_in_url")}})(),()=>{s=!0,clearTimeout(o),I.unsubscribe()}},[]);const q=async s=>{if(s.preventDefault(),f(""),t.length<6){f("Password must be at least 6 characters.");return}if(t!==r){f("Passwords don't match.");return}y(!0);try{const{error:o}=await p.auth.updateUser({password:t});if(o)throw o;k("password_reset_completed"),C(!0)}catch(o){f(o instanceof Error?o.message:"Something went wrong. Please try again.")}finally{y(!1)}};return e.jsx("div",{className:"min-h-full flex flex-col items-center justify-center px-6 py-12 bg-paper paper-grain",children:e.jsxs("div",{className:"w-full max-w-sm space-y-8",children:[e.jsxs("div",{className:"text-center space-y-1 flex flex-col items-center",children:[e.jsx("img",{src:L.url,alt:"Agora sun",className:"w-20 h-20 mb-2"}),e.jsx("h1",{className:"display text-6xl text-ink",style:{fontFamily:'"Anton", system-ui, sans-serif'},children:"AGORA"}),e.jsx("p",{className:"text-sm text-muted-foreground font-sans",children:"Set a new password."})]}),e.jsxs("div",{className:"banner-card p-8 space-y-6",children:[e.jsx("h2",{className:"text-xl font-bold text-ink font-sans",children:"New password"}),P?e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-ink font-sans",children:"Password updated. You can now return to the Agora app and sign in with your new password."}),e.jsx("p",{className:"text-xs text-muted-foreground font-sans",children:"You can close this tab."})]}):b?e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-red bg-red/10 rounded-lg px-3 py-2 font-sans",children:b}),e.jsxs(v,{to:"/forgot-password",className:"agora-tap w-full rounded-2xl bg-ink py-4 text-[15px] font-bold uppercase tracking-[0.12em] text-paper flex items-center justify-center gap-2",style:{fontFamily:"var(--font-display)",border:"2px s
1olid var(--ink)",boxShadow:"0 3px 0 var(--ink)"},children:["Send a new link",e.jsx(S,{className:"w-4 h-4"})]}),e.jsx("p",{className:"text-center text-sm text-muted-foreground font-sans",children:e.jsx(v,{to:"/login",className:"font-semibold text-red hover:underline",children:"Back to sign in"})})]}):E?e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{htmlFor:"password",className:"text-ink font-sans",children:"New password"}),e.jsxs("div",{className:"relative",children:[e.jsx(N,{id:"password",type:l?"text":"password",placeholder:"At least 6 characters",value:t,onChange:s=>i(s.target.value),required:!0,autoComplete:"new-password",className:"bg-paper border-ink/25 text-ink placeholder:text-muted-foreground focus-visible:border-ink focus-visible:ring-ink/20 pr-10"}),e.jsx("button",{type:"button",onClick:()=>R(s=>!s),className:"absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-ink transition-colors",tabIndex:-1,children:l?e.jsx(O,{className:"w-4 h-4"}):e.jsx(F,{className:"w-4 h-4"})})]})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsx(j,{htmlFor:"confirm",className:"text-ink font-sans",children:"Confirm password"}),e.jsx(N,{id:"confirm",type:l?"text":"password",placeholder:"Re-enter your new password",value:r,onChange:s=>x(s.target.value),required:!0,autoComplete:"new-password",className:"bg-paper border-ink/25 text-ink placeholder:text-muted-foreground focus-visible:border-ink focus-visible:ring-ink/20"})]}),g&&e.jsx("p",{className:"text-sm text-red bg-red/10 rounded-lg px-3 py-2",children:g}),e.jsxs("button",{type:"submit",disabled:w,className:"agora-tap w-full rounded-2xl bg-ink py-4 text-[15px] font-bold uppercase tracking-[0.12em] text-paper disabled:opacity-40 flex items-center justify-center gap-2",style:{fontFamily:"var(--font-display)",border:"2px solid var(--ink)",boxShadow:"0 3px 0 var(--ink)"},children:[w?"Savingâ¦":"Set new password",!w&&e.jsx(S,{className:"w-4 h-4"})]})]}):e.jsx("p",{className:"text-sm text-muted-foreground font-sans",children:"Verifying your reset linkâ¦"})]})]})})}export{Y as component};
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.