PageSourceSearch

https://swap-box.com/assets/AuthResetPassword-DpUjTXyc.js

js swap-box.com collected 2026-10-05 22:58:12 UTC 9,373 bytes, 1 lines download raw bytes

1import{r as n,u as z,E as Y,s as x,j as e,B as f,I as F,S as W}from"./index-CPe-RtOb.js";import{C as R,a as b,b as _,c as A,d as B}from"./card-MfW-rXM9.js";import{L as I}from"./label-Bv11FUgq.js";import{B as $}from"./badge-DiwtLCWR.js";import{P as G}from"./progress-CzxizFlt.js";import{v as J,b as K}from"./auth-config-pKOjSLYM.js";import{P as Q}from"./PasswordResetDialog-BzAVUA_o.js";import{S as X}from"./shield-check-CX3fgNCA.js";import{C as D}from"./circle-alert-DdZBz7UI.js";import{R as Z}from"./refresh-cw-pR10IFtW.js";import{A as ee}from"./arrow-left-ZqeUxEhF.js";import{E as M}from"./eye-off-C2dUfe1h.js";import{E as q}from"./eye-fM9nq7R9.js";import{C as se}from"./circle-check-CyzLb2jC.js";import"./mail-DCeQOYJ3.js";import"./arrow-right-DLtaraCs.js";import"./key-round-DRdldMJ6.js";const te=()=>{const[d,p]=n.useState(""),[w,g]=n.useState(""),[N,P]=n.useState(!1),[u,i]=n.useState(null),[l,c]=n.useState(null),[j,k]=n.useState(!1),[S,h]=n.useState(null),v=z(),{toast:a}=Y(),{isValid:E,errors:T,strength:V}=J(d),y=E&&d===w&&!!d&&!!w&&!N,L=n.useCallback(async()=>{if(l){k(!0),h(null);try{try{await x.auth.signOut({scope:"local"})}catch{}console.log("[usePasswordReset] verifying token_hash (len)",l.length);const{data:s,error:r}=await x.auth.verifyOtp({type:"recovery",token_hash:l});if(r){console.error("[usePasswordReset] verifyOtp error",r);const t=r.message||"Unknown error";h(t),a({title:"Reset link could not be verified",description:t,variant:"destructive"}),i(!1),c(null);return}console.log("[usePasswordReset] verifyOtp success, session?",!!(s!=null&&s.session));const o=new URL(window.location.href);o.searchParams.delete("token_hash"),window.history.replaceState({},"",o.pathname+o.search+o.hash),c(null),i(!0)}catch(s){console.error("[usePasswordReset] verify exception",s);const r=(s==null?void 0:s.message)||"An unexpected error occurred.";h(r),a({title:"Password reset failed",description:r,variant:"destructive"}),i(!1),c(null)}finally{k(!1)}}},[l,a]);n.useEffect(()=>{const{data:{subscription:s}}=x.auth.onAuthStateChange(m=>{m==="PASSWORD_RECOVERY"&&i(!0)}),r=new URLSearchParams(window.location.search),o=r.get("token_hash");if(o)return c(o),()=>{s.unsubscribe()};const t=window.location.hash;if(t.includes("type=recovery")){const m=setTimeout(()=>{u===null&&i(!1)},5e3);return()=>{clearTimeout(m),s.unsubscribe()}}if(r.get("error_description"))i(!1);else if(!t.includes("type=recovery")){const m=setTimeout(()=>{u===null&&i(!1)},2e3);return()=>{clearTimeout(m),s.unsubscribe()}}return()=>s.unsubscribe()},[]);const O=n.useCallback(async s=>{var r,o;if(s.preventDefault(),!!y){P(!0);try{const{error:t}=await x.auth.updateUser({password:d});if(t)throw t;const{data:{user:U}}=await x.auth.getUser();let m="/";if(U){const{data:C}=await x.from("user_roles").select("role").eq("user_id",U.id).maybeSingle();C!=null&&C.role&&(m=K(C.role))}a({title:"Password Updated",description:"Your password has been changed successfully. Redirecting..."}),setTimeout(()=>v(m,{replace:!0}),1500)}catch(t){a({title:"Password Reset Failed",description:(t==null?void 0:t.message)||"An unexpected error occurred.",variant:"destructive"}),((r=t==null?void 0:t.message)!=null&&r.includes("expired")||(o=t==null?void 0:t.message)!=null&&o.includes("not found"))&&setTimeout(()=>i(!1),2e3)}finally{P(!1)}}},[y,d,v,a]);return{password:d,confirmPassword:w,loading:N,isValidSession:u,pendingTokenHash:l,verifying:j,verifyError:S,passwordErrors:T,passwordStrength:V,setPassword:p,setConfirmPassword:g,handlePasswordReset:O,verifyToken:L,canSubmit:y}},re=()=>e.jsx(W,{title:"Reset password | SwapBox",description:"Reset het wachtwoord van je SwapBox account veilig via de bevestigingslink en kies een nieuw, sterk wachtwoord om weer in te loggen.",noindex:!0}),ye=()=>{const d=z(),[p,w]=n.useState(!1),[g,N]=n.useState(!1),[P,u]=n.useState(!1),{password:i,confirmPassword:l,loading:c,isValidSession:j,pendingTokenHash:k,verifying:S,verifyError:h,passwordErrors:v,passwordStrength:a,setPassword:E,setConfirmPassword:T,handlePasswordReset:V,verifyToken:H,canSubmit:y}=te();if(k&&j===null)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-muted/50 p-4",children:[e.jsx(re,{}),e.jsx(R,{className:"w-full max-w-md",children:S?e.jsxs(b,{className:"p-6 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Verifying your reset link..."})]}):e.jsxs(e.Fragment,{children:[e.jsxs(_,{className:"text-center",children:[e.jsxs(A,{className:"flex items-center justify-center gap-2",children:[e.jsx(X,{className:"h-5 w-5 text-primary"}),"Verify Your Identity"]}),e.jsx(B,{children:"Click the button below to verify your password reset link and continue."})]}),e.jsx(b,{children:e.jsx(f,{onClick:H,className:"w-full",size:"lg",children:"Verify & Continue"})})]})})]});if(j===null)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/50",children:e.jsx(R,{className:"w-full max-w-md",children:e.jsxs(b,{className:"p-6 flex flex-col items-center gap-4",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Validating reset link..."})]})})});if(!j)return e.jsxs("div",{className:"min-h-screen flex items-center justify-center bg-muted/50 p-4",children:[e.jsxs(R,{className:"w-full max-w-md",children:[e.jsxs(_,{className:"text-center",children:[e.jsxs(A,{className:"text-destructive flex items-center justify-center gap-2",children:[e.jsx(D,{className:"h-5 w-5"}),"Invalid Reset Link"]}
1),e.jsx(B,{children:"This password reset link is invalid, expired, or has already been used."})]}),e.jsxs(b,{className:"space-y-3",children:[h&&e.jsxs("div",{className:"rounded-md border border-destructive/30 bg-destructive/5 p-3 text-xs text-destructive break-words",children:[e.jsx("div",{className:"font-medium mb-1",children:"Technical details"}),h]}),e.jsxs(f,{onClick:()=>u(!0),className:"w-full",children:[e.jsx(Z,{className:"w-4 h-4 mr-2"}),"Request New Reset Link"]}),e.jsxs(f,{variant:"outline",onClick:()=>d("/login"),className:"w-full",children:[e.jsx(ee,{className:"w-4 h-4 mr-2"}),"Back to Login"]})]})]}),e.jsx(Q,{isOpen:P,onClose:()=>u(!1)})]});const L=a==="strong"?100:a==="medium"?66:33,O=a==="strong"?"bg-green-500":a==="medium"?"bg-yellow-500":"bg-destructive";return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-muted/50 p-4",children:e.jsxs(R,{className:"w-full max-w-md relative",children:[c&&e.jsx("div",{className:"absolute inset-0 bg-background/80 backdrop-blur-sm rounded-lg flex items-center justify-center z-10",children:e.jsxs("div",{className:"flex flex-col items-center gap-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"}),e.jsx("p",{className:"text-sm font-medium",children:"Updating your password..."})]})}),e.jsxs(_,{className:"text-center",children:[e.jsx(A,{children:"Reset Your Password"}),e.jsx(B,{children:"Enter your new password below."})]}),e.jsx(b,{children:e.jsxs("form",{onSubmit:V,className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"password",children:"New Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(F,{id:"password",type:p?"text":"password",value:i,onChange:s=>E(s.target.value),placeholder:"Enter new password",className:"pr-10",disabled:c}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>w(!p),children:p?e.jsx(M,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(q,{className:"h-4 w-4 text-muted-foreground"})})]}),i&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:"Password strength"}),e.jsx($,{variant:"secondary",className:`${O} text-white`,children:a==="strong"?"Strong":a==="medium"?"Medium":"Weak"})]}),e.jsx(G,{value:L,className:"h-2"})]}),v.length>0&&e.jsx("ul",{className:"text-sm text-destructive space-y-1 list-disc pl-4",children:v.map((s,r)=>e.jsx("li",{children:s},r))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(I,{htmlFor:"confirmPassword",children:"Confirm Password"}),e.jsxs("div",{className:"relative",children:[e.jsx(F,{id:"confirmPassword",type:g?"text":"password",value:l,onChange:s=>T(s.target.value),placeholder:"Confirm new password",className:"pr-10",disabled:c}),e.jsx(f,{type:"button",variant:"ghost",size:"sm",className:"absolute right-0 top-0 h-full px-3 hover:bg-transparent",onClick:()=>N(!g),children:g?e.jsx(M,{className:"h-4 w-4 text-muted-foreground"}):e.jsx(q,{className:"h-4 w-4 text-muted-foreground"})})]}),l&&e.jsx("div",{className:"flex items-center gap-2 text-sm",children:i===l?e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"h-4 w-4 text-green-500"}),e.jsx("span",{className:"text-green-600",children:"Passwords match"})]}):e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"h-4 w-4 text-destructive"}),e.jsx("span",{className:"text-destructive",children:"Passwords do not match"})]})})]}),e.jsx(f,{type:"submit",className:"w-full",disabled:!y,children:c?"Updating Password...":"Update Password"})]})})]})})};export{ye 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.