@neuctra/authix 1.1.14 → 1.1.16

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.
@@ -6283,9 +6283,9 @@ const Ls = [
6283
6283
  `${l}/users/check-user/${E}?appId=${c}`,
6284
6284
  { headers: { "x-api-key": x } }
6285
6285
  );
6286
- (!V.success || !V.exists) && (console.warn("User not found, clearing session..."), localStorage.removeItem("userInfo"), w(null));
6286
+ V?.success === !0 && V?.exists === !1 && (console.warn("User does not exist on server. Clearing session..."), localStorage.removeItem("userInfo"), w(null));
6287
6287
  } catch (V) {
6288
- console.error("User check failed:", V), localStorage.removeItem("userInfo"), w(null);
6288
+ console.error("⚠️ User validation request failed:", V);
6289
6289
  }
6290
6290
  };
6291
6291
  ee(() => {
@@ -491,7 +491,7 @@ React keys must be passed directly to JSX without using spread:
491
491
  animation: none;
492
492
  }
493
493
  }
494
- `})]})},ds=({token:e,user:t=null,darkMode:n=!0,homeUrl:s,onLogout:o,onVerify:a,primaryColor:i="#00C212"})=>{const{baseUrl:l,apiKey:x,appId:d}=ue(),[u,b]=w.useState(null),[y,S]=w.useState(t),[c,j]=w.useState(!0),[m,A]=w.useState(!1),[P,$]=w.useState(!1),[T,M]=w.useState(!1),[g,O]=w.useState(!1),[v,U]=w.useState(!1),[q,F]=w.useState(!1),[Y,Z]=w.useState(!1),[I,X]=w.useState(!1),[K,_]=w.useState(null),[R,ne]=w.useState(!1),[J,f]=w.useState({email:"",otp:"",appId:d}),[k,N]=w.useState(!1),[h,E]=w.useState(!1);w.useEffect(()=>{if(typeof window<"u"){const C=()=>b(window.innerWidth);return C(),window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)}},[]);const z=(C,V)=>{_({type:C,message:V}),setTimeout(()=>_(null),3e3)},B=()=>{X(!0);const C=setTimeout(()=>{Z(!1),X(!1)},150);return()=>clearTimeout(C)};w.useEffect(()=>{const C=V=>{const G=document.querySelector(".dropdown-container");G&&!G.contains(V.target)&&B()};return Y&&document.addEventListener("mousedown",C),()=>{document.removeEventListener("mousedown",C)}},[Y]);const le=async()=>{if(!J.email||!/\S+@\S+\.\S+/.test(J.email)){z("error","Please enter a valid email");return}try{E(!0);const C=await W.post(`${l}/users/send-verify-otp/${y?.id}`,{email:J.email},{headers:{"x-api-key":x,"x-app-id":d}});C.data.success?(z("success",C.data.message||"OTP sent to email!"),N(!0)):z("error",C.data.message||"Failed to send OTP")}catch(C){z("error",C.response?.data?.message||"Server error")}finally{E(!1)}},pe=async C=>{if(C.preventDefault(),!J.email||!J.otp){z("error","Please fill in all fields");return}try{E(!0);const V=await W.post(`${l}/users/verify-email`,J);if(V.data.success){if(z("success",V.data.message||"Email verified!"),y){const G={...y,isVerified:!0};S(G),localStorage.setItem("userInfo",JSON.stringify({...G,token:e})),typeof a=="function"&&a(G)}f({email:"",otp:"",appId:d}),N(!1),F(!1)}else z("error",V.data.message||"Verification failed")}catch(V){z("error",V.response?.data?.message||"Something went wrong")}finally{E(!1)}},Oe=async C=>{if(!y)return!1;try{const V={...y,avatarUrl:C},{data:G}=await W.put(`${l}/users/update/${y.id}`,V,{headers:{"x-api-key":x}});return G.success?(S(V),localStorage.setItem("userInfo",JSON.stringify({...V,token:e})),z("success","Avatar updated successfully!"),!0):(z("error",G.message||"Failed to update avatar"),!1)}catch(V){return console.error("Avatar update error:",V),z("error","Failed to update avatar"),!1}},lt=async()=>{if(y){$(!0);try{const{data:C}=await W.put(`${l}/users/update/${y.id}`,y,{headers:{"x-api-key":x}});C.success?(S(C.user),A(!1),localStorage.setItem("userInfo",JSON.stringify({...C.user,token:e})),z("success","Profile updated successfully")):z("error",C.message)}catch(C){console.error(C),z("error","Update failed")}finally{$(!1)}}},or=async C=>{try{const{data:V}=await W.get(`${l}/users/check-user/${C}?appId=${d}`,{headers:{"x-api-key":x}});(!V.success||!V.exists)&&(console.warn("User not found, clearing session..."),localStorage.removeItem("userInfo"),S(null))}catch(V){console.error("User check failed:",V),localStorage.removeItem("userInfo"),S(null)}};w.useEffect(()=>{(()=>{if(t)S(t),j(!1),or(t.id);else{const V=localStorage.getItem("userInfo");if(V){const G=JSON.parse(V);S(G),j(!1),or(G.id)}else j(!1)}})()},[t]),w.useEffect(()=>{y?.email&&f(C=>({...C,email:y.email}))},[y?.email]);const ir=(C,V)=>{let G=parseInt(C.replace("#",""),16),ge=(G>>16)+V,dt=(G>>8&255)+V,ct=(G&255)+V;return ge=Math.min(255,Math.max(0,ge)),dt=Math.min(255,Math.max(0,dt)),ct=Math.min(255,Math.max(0,ct)),`#${(ct|dt<<8|ge<<16).toString(16).padStart(6,"0")}`},L=n?{background:"#000000",surface:"#09090b",surfaceLight:"#27272a",surfaceLighter:"#3f3f46",textPrimary:"#ffffff",textSecondary:"#d4d4d8",textTertiary:"#a1a1aa",accent:i,accentHover:ir(i,-15),success:"#10b981",error:"#ef4444",border:"#27272a",warning:"#f59e0b"}:{background:"#ffffff",surface:"#fafafa",surfaceLight:"#f4f4f5",surfaceLighter:"#e4e4e7",textPrimary:"#18181b",textSecondary:"#52525b",textTertiary:"#71717a",accent:i,accentHover:ir(i,-15),success:"#10b981",error:"#ef4444",border:"#e4e4e7",warning:"#d97706"};if(c)return r.jsx("div",{style:{width:"100%",minHeight:"400px",display:"flex",alignItems:"center",justifyContent:"center",color:L.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif"},children:r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"16px",textAlign:"center"},children:[r.jsx(oe,{size:40,color:L.accent,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}),r.jsx("p",{style:{color:L.textTertiary,margin:0},children:"Loading your profile..."})]})});if(!y)return r.jsx("div",{style:{width:"100%",minHeight:"400px",display:"flex",alignItems:"center",justifyContent:"center",color:L.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif"},children:r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",textAlign:"center"},children:[r.jsx(ae,{size:40,color:L.error,"aria-hidden":"true"}),r.jsx("p",{style:{color:L.textTertiary,margin:0},children:"No profile found. Please log in again."})]})});const ps=[{label:"Full Name",value:y.name,name:"name",type:"text",icon:Se},{label:"Email Address",value:y.email,name:"email",type:"email",icon:ce},{label:"Phone Number",value:y.phone||"Not set",name:"phone",type:"tel",icon:Jn},{label:"Address",value:y.address||"Not provided",name:"address",type:"text",icon:Yn}];return r.jsxs("div",{style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:L.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif",lineHeight:1.5,minHeight:"80vh"},children:[K&&r.jsxs("div",{style:{position:"fixed",top:"20px",right:"20px",padding:"12px 24px",borderRadius:"12px",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(8px)",border:"1px solid",zIndex:1e3,display:"flex",alignItems:"center",gap:"8px",fontSize:"12px",fontWeight:500,maxWidth:"400px",animation:"slideIn 0.3s ease-out",...K.type==="success"?{backgroundColor:n?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)",borderColor:n?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)",color:n?"#34d399":"#059669"}:{backgroundColor:n?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)",borderColor:n?"rgba(239, 68, 68, 0.3)":"rgba(239, 68, 68, 0.2)",color:n?"#f87171":"#dc2626"}},role:"alert","aria-live":"polite",children:[K.type==="success"?r.jsx(de,{size:20,"aria-hidden":"true"}):r.jsx(ae,{size:20,"aria-hidden":"true"}),K.message]}),r.jsx("div",{style:{maxWidth:"1200px",margin:"0 auto",width:"100%",boxSizing:"border-box"},children:r.jsxs("div",{style:{display:"grid",gap:"24px",gridTemplateColumns:"1fr",...u&&window.innerWidth>=1024&&{gridTemplateColumns:"1fr 2fr",gap:"10px"},...u&&window.innerWidth>=768&&u&&window.innerWidth<1024&&{gap:"10px"},...u&&window.innerWidth>=600&&u&&window.innerWidth<768&&{gap:"28px"}},children:[r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"6px",height:"100%"},children:[r.jsxs("section",{style:{backgroundColor:L.surface,borderRadius:"16px",position:"relative",padding:"24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",textAlign:"center",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",flex:1,minHeight:"300px"},children:[s&&r.jsx("a",{href:s||"/",target:"_self",rel:"noopener noreferrer",style:{position:"absolute",top:"18px",left:"18px"},children:r.jsx(qn,{size:20,style:{color:n?"#ffffff":"#000000"}})}),r.jsxs("div",{style:{position:"relative",display:"inline-block",marginBottom:"16px"},children:[r.jsx("img",{src:y.avatarUrl||`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(y.name)}`,alt:`Profile avatar of ${y.name}`,style:{width:"128px",height:"128px",borderRadius:"50%",objectFit:"cover",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.3)",border:`3px solid ${L.border}`},width:128,height:128,loading:"eager"}),r.jsx("button",{onClick:()=>M(!0),style:{position:"absolute",bottom:"8px",right:"8px",backgroundColor:L.accent,color:"white",padding:"8px",borderRadius:"50%",border:"none",cursor:"pointer",transition:"all 0.2s ease",display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px"},"aria-label":"Change profile picture",children:r.jsx(tt,{size:16,"aria-hidden":"true"})})]}),r.jsx("h2",{style:{fontSize:"24px",fontWeight:600,margin:"0 0 4px 0",color:L.textPrimary},children:y.name}),r.jsx("p",{style:{color:L.textTertiary,margin:"0 0 8px 0"},children:y.email}),r.jsxs("div",{style:{backgroundColor:y.isVerified?n?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)":n?"rgba(245, 158, 11, 0.1)":"rgba(245, 158, 11, 0.05)",color:y.isVerified?L.success:L.warning,border:`1px solid ${y.isVerified?n?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)":n?"rgba(245, 158, 11, 0.3)":"rgba(245, 158, 11, 0.2)"}`,padding:"6px 12px",borderRadius:"20px",fontSize:"12px",fontWeight:500,display:"inline-flex",alignItems:"center",gap:"6px",marginTop:"8px"},children:[y.isVerified?r.jsx(de,{size:16,"aria-hidden":"true"}):r.jsx(ae,{size:16,"aria-hidden":"true"}),y.isVerified?"Email Verified":"Not Verified"]})]}),r.jsx("nav",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:m?r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>A(!1),style:{backgroundColor:L.surfaceLight,border:`1px solid ${L.border}`,color:L.textPrimary,padding:"10px 20px",borderRadius:"6px",borderStyle:"solid",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:u&&window.innerWidth<1024?"1":"auto"},children:[r.jsx(Pe,{size:16,"aria-hidden":"true"}),"Cancel"]}),r.jsxs("button",{onClick:lt,disabled:P,style:{background:`linear-gradient(to right, ${L.accent}, ${L.accentHover})`,opacity:P?.7:1,color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:P?"not-allowed":"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:u&&window.innerWidth<1024?"1":"auto"},children:[P?r.jsx(oe,{size:16,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}):r.jsx(Xn,{size:16,"aria-hidden":"true"}),P?"Saving...":"Save Changes"]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>A(!0),style:{background:`linear-gradient(to right, ${L.accent}, ${L.accentHover})`,color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:u&&window.innerWidth<1024?"1":"auto"},children:[r.jsx(Kn,{size:16,"aria-hidden":"true"}),"Edit Profile"]}),!y.isVerified&&r.jsxs("button",{onClick:()=>F(!0),disabled:R,style:{background:"linear-gradient(to right, #fbbf24, #f59e0b)",color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:R?"not-allowed":"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",minHeight:"36px",opacity:R?.7:1,flex:u&&window.innerWidth<1024?"1":"auto"},children:[R?r.jsx(oe,{size:14,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}):r.jsx(at,{size:14,"aria-hidden":"true"}),R?"Sending...":"Verify Email"]}),r.jsxs("div",{style:{position:"relative"},children:[r.jsxs("button",{style:{backgroundColor:L.surfaceLight,color:L.textPrimary,padding:"10px 20px",borderRadius:"6px",border:"none",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",width:"100%",boxSizing:"border-box"},onClick:()=>Z(!Y),children:[r.jsx(Bn,{size:16,"aria-hidden":"true"}),"More Actions"]}),Y&&r.jsxs("div",{className:`dropdown-container ${I?"closing":""}`,style:{position:"absolute",bottom:"100%",left:0,right:0,backgroundColor:L.surface,border:`1px solid ${L.border}`,borderRadius:"12px 12px 0 0",boxShadow:"0 -8px 24px rgba(0, 0, 0, 0.25)",zIndex:200,marginBottom:"6px",overflow:"hidden",animation:`${I?"drawerSlideDown":"drawerSlideUp"} 0.25s ease-out forwards`},children:[r.jsxs("button",{onClick:()=>{O(!0),B()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:L.textPrimary,cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:C=>C.currentTarget.style.backgroundColor=L.surfaceLight,onMouseLeave:C=>C.currentTarget.style.backgroundColor="transparent",children:[r.jsx(ot,{size:14,"aria-hidden":"true"}),"Change Password"]}),o&&r.jsxs("button",{onClick:()=>{o(),B()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:n?"#fca5a5":"#dc2626",cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:C=>{C.currentTarget.style.backgroundColor=n?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)"},onMouseLeave:C=>C.currentTarget.style.backgroundColor="transparent",children:[r.jsx(it,{size:14,"aria-hidden":"true"}),"Logout"]}),r.jsxs("button",{onClick:()=>{U(!0),B()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:"#ef4444",cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:600,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:C=>{C.currentTarget.style.backgroundColor=n?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)"},onMouseLeave:C=>C.currentTarget.style.backgroundColor="transparent",children:[r.jsx(We,{size:14,"aria-hidden":"true"}),"Delete Account"]})]})]})]})})]}),r.jsxs("div",{style:{minWidth:0,display:"flex",flexDirection:"column",gap:"12px"},children:[r.jsxs("section",{style:{backgroundColor:L.surface,borderRadius:"16px",padding:"24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},children:[r.jsxs("h2",{style:{fontSize:"20px",fontWeight:600,margin:"0 0 24px 0",color:L.textSecondary,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(Se,{size:20,"aria-hidden":"true"}),"Personal Information"]}),r.jsx("div",{style:{display:"grid",gap:"20px",gridTemplateColumns:"1fr",...u&&window.innerWidth>=600&&{gridTemplateColumns:"1fr 1fr",gap:"20px"}},children:ps.map(C=>{const V=C.icon;return r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[r.jsxs("label",{style:{color:L.textTertiary,fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(V,{size:16,"aria-hidden":"true"}),C.label]}),m?r.jsx("input",{type:C.type,name:C.name,value:y[C.name],onChange:G=>S(ge=>ge&&{...ge,[G.target.name]:G.target.value}),style:{padding:"12px",borderRadius:"8px",border:`1px solid ${i}`,backgroundColor:"transparent",color:L.textPrimary,fontSize:"12px",outline:"none",transition:"border-color 0.2s ease",minHeight:"44px",width:"100%",boxSizing:"border-box"},placeholder:`Enter ${C.label.toLowerCase()}`,"aria-label":C.label}):r.jsx("div",{style:{padding:"12px",borderRadius:"8px",border:"1px solid transparent",fontSize:"12px",minHeight:"44px",display:"flex",alignItems:"center",boxSizing:"border-box",color:L.textPrimary,backgroundColor:n?"rgba(255,255,255,0.05)":"rgba(0,0,0,0.05)"},children:C.value})]},C.name)})})]}),r.jsxs("section",{style:{backgroundColor:L.surface,borderRadius:"16px",padding:"30px 24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},children:[r.jsxs("h2",{style:{fontSize:"20px",fontWeight:600,margin:"0 0 24px 0",color:L.textSecondary,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(nr,{size:20,"aria-hidden":"true"}),"Security Status"]}),r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",color:L.textSecondary},children:[r.jsx(ce,{size:16,"aria-hidden":"true"}),r.jsx("span",{children:"Email Verification"})]}),r.jsx("div",{style:{padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"6px",...y.isVerified?{backgroundColor:n?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)",color:L.success,border:`1px solid ${n?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)"}`}:{backgroundColor:n?"rgba(245, 158, 11, 0.1)":"rgba(245, 158, 11, 0.05)",color:L.warning,border:`1px solid ${n?"rgba(245, 158, 11, 0.3)":"rgba(245, 158, 11, 0.2)"}`}},children:y.isVerified?r.jsxs(r.Fragment,{children:[r.jsx(de,{size:16,"aria-hidden":"true"}),"Verified"]}):r.jsxs(r.Fragment,{children:[r.jsx(ae,{size:16,"aria-hidden":"true"}),"Not Verified"]})})]}),!y.isVerified&&r.jsx("div",{style:{padding:"12px",borderRadius:"8px",backgroundColor:n?"rgba(100, 100, 100, 0.1)":"rgba(0, 0, 0, 0.05)"},children:r.jsx("p",{style:{color:L.textTertiary,fontSize:"12px",margin:0},children:"Verify your email to unlock all features and enhance your account security."})})]})]})]})]})}),r.jsx(is,{isOpen:T,onClose:()=>{M(!1)},onUpdate:Oe,colors:L}),r.jsx(as,{baseUrl:l,apiKey:x,appId:d,userId:y.id,isOpen:g,onClose:()=>O(!1),onSuccess:C=>z("success",C),onError:C=>z("error",C),colors:L}),r.jsx(os,{baseUrl:l,apiKey:x,appId:d,userId:y.id,token:e,isOpen:v,onClose:()=>U(!1),onSuccess:C=>z("success",C),onError:C=>z("error",C),colors:L}),r.jsx(ls,{isOpen:q,onClose:()=>{F(!1),N(!1),f({email:y?.email||"",otp:"",appId:d})},onVerify:pe,onSendOTP:le,verifyFormData:J,setVerifyFormData:f,otpSent:k,verifying:h,user:y,colors:L,darkMode:n}),r.jsx("style",{children:`
494
+ `})]})},ds=({token:e,user:t=null,darkMode:n=!0,homeUrl:s,onLogout:o,onVerify:a,primaryColor:i="#00C212"})=>{const{baseUrl:l,apiKey:x,appId:d}=ue(),[u,b]=w.useState(null),[y,S]=w.useState(t),[c,j]=w.useState(!0),[m,A]=w.useState(!1),[P,$]=w.useState(!1),[T,M]=w.useState(!1),[g,O]=w.useState(!1),[v,U]=w.useState(!1),[q,F]=w.useState(!1),[Y,Z]=w.useState(!1),[I,X]=w.useState(!1),[K,_]=w.useState(null),[R,ne]=w.useState(!1),[J,f]=w.useState({email:"",otp:"",appId:d}),[k,N]=w.useState(!1),[h,E]=w.useState(!1);w.useEffect(()=>{if(typeof window<"u"){const C=()=>b(window.innerWidth);return C(),window.addEventListener("resize",C),()=>window.removeEventListener("resize",C)}},[]);const z=(C,V)=>{_({type:C,message:V}),setTimeout(()=>_(null),3e3)},B=()=>{X(!0);const C=setTimeout(()=>{Z(!1),X(!1)},150);return()=>clearTimeout(C)};w.useEffect(()=>{const C=V=>{const G=document.querySelector(".dropdown-container");G&&!G.contains(V.target)&&B()};return Y&&document.addEventListener("mousedown",C),()=>{document.removeEventListener("mousedown",C)}},[Y]);const le=async()=>{if(!J.email||!/\S+@\S+\.\S+/.test(J.email)){z("error","Please enter a valid email");return}try{E(!0);const C=await W.post(`${l}/users/send-verify-otp/${y?.id}`,{email:J.email},{headers:{"x-api-key":x,"x-app-id":d}});C.data.success?(z("success",C.data.message||"OTP sent to email!"),N(!0)):z("error",C.data.message||"Failed to send OTP")}catch(C){z("error",C.response?.data?.message||"Server error")}finally{E(!1)}},pe=async C=>{if(C.preventDefault(),!J.email||!J.otp){z("error","Please fill in all fields");return}try{E(!0);const V=await W.post(`${l}/users/verify-email`,J);if(V.data.success){if(z("success",V.data.message||"Email verified!"),y){const G={...y,isVerified:!0};S(G),localStorage.setItem("userInfo",JSON.stringify({...G,token:e})),typeof a=="function"&&a(G)}f({email:"",otp:"",appId:d}),N(!1),F(!1)}else z("error",V.data.message||"Verification failed")}catch(V){z("error",V.response?.data?.message||"Something went wrong")}finally{E(!1)}},Oe=async C=>{if(!y)return!1;try{const V={...y,avatarUrl:C},{data:G}=await W.put(`${l}/users/update/${y.id}`,V,{headers:{"x-api-key":x}});return G.success?(S(V),localStorage.setItem("userInfo",JSON.stringify({...V,token:e})),z("success","Avatar updated successfully!"),!0):(z("error",G.message||"Failed to update avatar"),!1)}catch(V){return console.error("Avatar update error:",V),z("error","Failed to update avatar"),!1}},lt=async()=>{if(y){$(!0);try{const{data:C}=await W.put(`${l}/users/update/${y.id}`,y,{headers:{"x-api-key":x}});C.success?(S(C.user),A(!1),localStorage.setItem("userInfo",JSON.stringify({...C.user,token:e})),z("success","Profile updated successfully")):z("error",C.message)}catch(C){console.error(C),z("error","Update failed")}finally{$(!1)}}},or=async C=>{try{const{data:V}=await W.get(`${l}/users/check-user/${C}?appId=${d}`,{headers:{"x-api-key":x}});V?.success===!0&&V?.exists===!1&&(console.warn("❌ User does not exist on server. Clearing session..."),localStorage.removeItem("userInfo"),S(null))}catch(V){console.error("⚠️ User validation request failed:",V)}};w.useEffect(()=>{(()=>{if(t)S(t),j(!1),or(t.id);else{const V=localStorage.getItem("userInfo");if(V){const G=JSON.parse(V);S(G),j(!1),or(G.id)}else j(!1)}})()},[t]),w.useEffect(()=>{y?.email&&f(C=>({...C,email:y.email}))},[y?.email]);const ir=(C,V)=>{let G=parseInt(C.replace("#",""),16),ge=(G>>16)+V,dt=(G>>8&255)+V,ct=(G&255)+V;return ge=Math.min(255,Math.max(0,ge)),dt=Math.min(255,Math.max(0,dt)),ct=Math.min(255,Math.max(0,ct)),`#${(ct|dt<<8|ge<<16).toString(16).padStart(6,"0")}`},L=n?{background:"#000000",surface:"#09090b",surfaceLight:"#27272a",surfaceLighter:"#3f3f46",textPrimary:"#ffffff",textSecondary:"#d4d4d8",textTertiary:"#a1a1aa",accent:i,accentHover:ir(i,-15),success:"#10b981",error:"#ef4444",border:"#27272a",warning:"#f59e0b"}:{background:"#ffffff",surface:"#fafafa",surfaceLight:"#f4f4f5",surfaceLighter:"#e4e4e7",textPrimary:"#18181b",textSecondary:"#52525b",textTertiary:"#71717a",accent:i,accentHover:ir(i,-15),success:"#10b981",error:"#ef4444",border:"#e4e4e7",warning:"#d97706"};if(c)return r.jsx("div",{style:{width:"100%",minHeight:"400px",display:"flex",alignItems:"center",justifyContent:"center",color:L.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif"},children:r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"16px",textAlign:"center"},children:[r.jsx(oe,{size:40,color:L.accent,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}),r.jsx("p",{style:{color:L.textTertiary,margin:0},children:"Loading your profile..."})]})});if(!y)return r.jsx("div",{style:{width:"100%",minHeight:"400px",display:"flex",alignItems:"center",justifyContent:"center",color:L.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif"},children:r.jsxs("div",{style:{display:"flex",flexDirection:"column",alignItems:"center",gap:"12px",textAlign:"center"},children:[r.jsx(ae,{size:40,color:L.error,"aria-hidden":"true"}),r.jsx("p",{style:{color:L.textTertiary,margin:0},children:"No profile found. Please log in again."})]})});const ps=[{label:"Full Name",value:y.name,name:"name",type:"text",icon:Se},{label:"Email Address",value:y.email,name:"email",type:"email",icon:ce},{label:"Phone Number",value:y.phone||"Not set",name:"phone",type:"tel",icon:Jn},{label:"Address",value:y.address||"Not provided",name:"address",type:"text",icon:Yn}];return r.jsxs("div",{style:{width:"100%",display:"flex",alignItems:"center",justifyContent:"center",color:L.textPrimary,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, sans-serif",lineHeight:1.5,minHeight:"80vh"},children:[K&&r.jsxs("div",{style:{position:"fixed",top:"20px",right:"20px",padding:"12px 24px",borderRadius:"12px",boxShadow:"0 25px 50px -12px rgba(0, 0, 0, 0.25)",backdropFilter:"blur(8px)",border:"1px solid",zIndex:1e3,display:"flex",alignItems:"center",gap:"8px",fontSize:"12px",fontWeight:500,maxWidth:"400px",animation:"slideIn 0.3s ease-out",...K.type==="success"?{backgroundColor:n?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)",borderColor:n?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)",color:n?"#34d399":"#059669"}:{backgroundColor:n?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)",borderColor:n?"rgba(239, 68, 68, 0.3)":"rgba(239, 68, 68, 0.2)",color:n?"#f87171":"#dc2626"}},role:"alert","aria-live":"polite",children:[K.type==="success"?r.jsx(de,{size:20,"aria-hidden":"true"}):r.jsx(ae,{size:20,"aria-hidden":"true"}),K.message]}),r.jsx("div",{style:{maxWidth:"1200px",margin:"0 auto",width:"100%",boxSizing:"border-box"},children:r.jsxs("div",{style:{display:"grid",gap:"24px",gridTemplateColumns:"1fr",...u&&window.innerWidth>=1024&&{gridTemplateColumns:"1fr 2fr",gap:"10px"},...u&&window.innerWidth>=768&&u&&window.innerWidth<1024&&{gap:"10px"},...u&&window.innerWidth>=600&&u&&window.innerWidth<768&&{gap:"28px"}},children:[r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"6px",height:"100%"},children:[r.jsxs("section",{style:{backgroundColor:L.surface,borderRadius:"16px",position:"relative",padding:"24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)",textAlign:"center",display:"flex",flexDirection:"column",justifyContent:"center",alignItems:"center",flex:1,minHeight:"300px"},children:[s&&r.jsx("a",{href:s||"/",target:"_self",rel:"noopener noreferrer",style:{position:"absolute",top:"18px",left:"18px"},children:r.jsx(qn,{size:20,style:{color:n?"#ffffff":"#000000"}})}),r.jsxs("div",{style:{position:"relative",display:"inline-block",marginBottom:"16px"},children:[r.jsx("img",{src:y.avatarUrl||`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(y.name)}`,alt:`Profile avatar of ${y.name}`,style:{width:"128px",height:"128px",borderRadius:"50%",objectFit:"cover",boxShadow:"0 10px 25px -5px rgba(0, 0, 0, 0.3)",border:`3px solid ${L.border}`},width:128,height:128,loading:"eager"}),r.jsx("button",{onClick:()=>M(!0),style:{position:"absolute",bottom:"8px",right:"8px",backgroundColor:L.accent,color:"white",padding:"8px",borderRadius:"50%",border:"none",cursor:"pointer",transition:"all 0.2s ease",display:"flex",alignItems:"center",justifyContent:"center",width:"32px",height:"32px"},"aria-label":"Change profile picture",children:r.jsx(tt,{size:16,"aria-hidden":"true"})})]}),r.jsx("h2",{style:{fontSize:"24px",fontWeight:600,margin:"0 0 4px 0",color:L.textPrimary},children:y.name}),r.jsx("p",{style:{color:L.textTertiary,margin:"0 0 8px 0"},children:y.email}),r.jsxs("div",{style:{backgroundColor:y.isVerified?n?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)":n?"rgba(245, 158, 11, 0.1)":"rgba(245, 158, 11, 0.05)",color:y.isVerified?L.success:L.warning,border:`1px solid ${y.isVerified?n?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)":n?"rgba(245, 158, 11, 0.3)":"rgba(245, 158, 11, 0.2)"}`,padding:"6px 12px",borderRadius:"20px",fontSize:"12px",fontWeight:500,display:"inline-flex",alignItems:"center",gap:"6px",marginTop:"8px"},children:[y.isVerified?r.jsx(de,{size:16,"aria-hidden":"true"}):r.jsx(ae,{size:16,"aria-hidden":"true"}),y.isVerified?"Email Verified":"Not Verified"]})]}),r.jsx("nav",{style:{display:"flex",flexDirection:"column",gap:"6px"},children:m?r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>A(!1),style:{backgroundColor:L.surfaceLight,border:`1px solid ${L.border}`,color:L.textPrimary,padding:"10px 20px",borderRadius:"6px",borderStyle:"solid",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:u&&window.innerWidth<1024?"1":"auto"},children:[r.jsx(Pe,{size:16,"aria-hidden":"true"}),"Cancel"]}),r.jsxs("button",{onClick:lt,disabled:P,style:{background:`linear-gradient(to right, ${L.accent}, ${L.accentHover})`,opacity:P?.7:1,color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:P?"not-allowed":"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:u&&window.innerWidth<1024?"1":"auto"},children:[P?r.jsx(oe,{size:16,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}):r.jsx(Xn,{size:16,"aria-hidden":"true"}),P?"Saving...":"Save Changes"]})]}):r.jsxs(r.Fragment,{children:[r.jsxs("button",{onClick:()=>A(!0),style:{background:`linear-gradient(to right, ${L.accent}, ${L.accentHover})`,color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",flex:u&&window.innerWidth<1024?"1":"auto"},children:[r.jsx(Kn,{size:16,"aria-hidden":"true"}),"Edit Profile"]}),!y.isVerified&&r.jsxs("button",{onClick:()=>F(!0),disabled:R,style:{background:"linear-gradient(to right, #fbbf24, #f59e0b)",color:"white",padding:"10px 20px",borderRadius:"6px",border:"none",cursor:R?"not-allowed":"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",minHeight:"36px",opacity:R?.7:1,flex:u&&window.innerWidth<1024?"1":"auto"},children:[R?r.jsx(oe,{size:14,style:{animation:"spin 1s linear infinite"},"aria-hidden":"true"}):r.jsx(at,{size:14,"aria-hidden":"true"}),R?"Sending...":"Verify Email"]}),r.jsxs("div",{style:{position:"relative"},children:[r.jsxs("button",{style:{backgroundColor:L.surfaceLight,color:L.textPrimary,padding:"10px 20px",borderRadius:"6px",border:"none",cursor:"pointer",transition:"all 0.2s ease",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",textDecoration:"none",minHeight:"36px",width:"100%",boxSizing:"border-box"},onClick:()=>Z(!Y),children:[r.jsx(Bn,{size:16,"aria-hidden":"true"}),"More Actions"]}),Y&&r.jsxs("div",{className:`dropdown-container ${I?"closing":""}`,style:{position:"absolute",bottom:"100%",left:0,right:0,backgroundColor:L.surface,border:`1px solid ${L.border}`,borderRadius:"12px 12px 0 0",boxShadow:"0 -8px 24px rgba(0, 0, 0, 0.25)",zIndex:200,marginBottom:"6px",overflow:"hidden",animation:`${I?"drawerSlideDown":"drawerSlideUp"} 0.25s ease-out forwards`},children:[r.jsxs("button",{onClick:()=>{O(!0),B()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:L.textPrimary,cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:C=>C.currentTarget.style.backgroundColor=L.surfaceLight,onMouseLeave:C=>C.currentTarget.style.backgroundColor="transparent",children:[r.jsx(ot,{size:14,"aria-hidden":"true"}),"Change Password"]}),o&&r.jsxs("button",{onClick:()=>{o(),B()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:n?"#fca5a5":"#dc2626",cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:C=>{C.currentTarget.style.backgroundColor=n?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)"},onMouseLeave:C=>C.currentTarget.style.backgroundColor="transparent",children:[r.jsx(it,{size:14,"aria-hidden":"true"}),"Logout"]}),r.jsxs("button",{onClick:()=>{U(!0),B()},style:{width:"100%",padding:"14px 18px",backgroundColor:"transparent",border:"none",color:"#ef4444",cursor:"pointer",transition:"all 0.2s ease",fontSize:"13px",fontWeight:600,display:"flex",alignItems:"center",gap:"8px",textAlign:"left"},onMouseEnter:C=>{C.currentTarget.style.backgroundColor=n?"rgba(239, 68, 68, 0.1)":"rgba(239, 68, 68, 0.05)"},onMouseLeave:C=>C.currentTarget.style.backgroundColor="transparent",children:[r.jsx(We,{size:14,"aria-hidden":"true"}),"Delete Account"]})]})]})]})})]}),r.jsxs("div",{style:{minWidth:0,display:"flex",flexDirection:"column",gap:"12px"},children:[r.jsxs("section",{style:{backgroundColor:L.surface,borderRadius:"16px",padding:"24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},children:[r.jsxs("h2",{style:{fontSize:"20px",fontWeight:600,margin:"0 0 24px 0",color:L.textSecondary,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(Se,{size:20,"aria-hidden":"true"}),"Personal Information"]}),r.jsx("div",{style:{display:"grid",gap:"20px",gridTemplateColumns:"1fr",...u&&window.innerWidth>=600&&{gridTemplateColumns:"1fr 1fr",gap:"20px"}},children:ps.map(C=>{const V=C.icon;return r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"8px"},children:[r.jsxs("label",{style:{color:L.textTertiary,fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(V,{size:16,"aria-hidden":"true"}),C.label]}),m?r.jsx("input",{type:C.type,name:C.name,value:y[C.name],onChange:G=>S(ge=>ge&&{...ge,[G.target.name]:G.target.value}),style:{padding:"12px",borderRadius:"8px",border:`1px solid ${i}`,backgroundColor:"transparent",color:L.textPrimary,fontSize:"12px",outline:"none",transition:"border-color 0.2s ease",minHeight:"44px",width:"100%",boxSizing:"border-box"},placeholder:`Enter ${C.label.toLowerCase()}`,"aria-label":C.label}):r.jsx("div",{style:{padding:"12px",borderRadius:"8px",border:"1px solid transparent",fontSize:"12px",minHeight:"44px",display:"flex",alignItems:"center",boxSizing:"border-box",color:L.textPrimary,backgroundColor:n?"rgba(255,255,255,0.05)":"rgba(0,0,0,0.05)"},children:C.value})]},C.name)})})]}),r.jsxs("section",{style:{backgroundColor:L.surface,borderRadius:"16px",padding:"30px 24px",boxShadow:"0 1px 3px rgba(0, 0, 0, 0.1)"},children:[r.jsxs("h2",{style:{fontSize:"20px",fontWeight:600,margin:"0 0 24px 0",color:L.textSecondary,display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(nr,{size:20,"aria-hidden":"true"}),"Security Status"]}),r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"16px"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",padding:"12px 0"},children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",color:L.textSecondary},children:[r.jsx(ce,{size:16,"aria-hidden":"true"}),r.jsx("span",{children:"Email Verification"})]}),r.jsx("div",{style:{padding:"6px 12px",borderRadius:"8px",fontSize:"12px",fontWeight:500,display:"flex",alignItems:"center",gap:"6px",...y.isVerified?{backgroundColor:n?"rgba(16, 185, 129, 0.1)":"rgba(16, 185, 129, 0.05)",color:L.success,border:`1px solid ${n?"rgba(16, 185, 129, 0.3)":"rgba(16, 185, 129, 0.2)"}`}:{backgroundColor:n?"rgba(245, 158, 11, 0.1)":"rgba(245, 158, 11, 0.05)",color:L.warning,border:`1px solid ${n?"rgba(245, 158, 11, 0.3)":"rgba(245, 158, 11, 0.2)"}`}},children:y.isVerified?r.jsxs(r.Fragment,{children:[r.jsx(de,{size:16,"aria-hidden":"true"}),"Verified"]}):r.jsxs(r.Fragment,{children:[r.jsx(ae,{size:16,"aria-hidden":"true"}),"Not Verified"]})})]}),!y.isVerified&&r.jsx("div",{style:{padding:"12px",borderRadius:"8px",backgroundColor:n?"rgba(100, 100, 100, 0.1)":"rgba(0, 0, 0, 0.05)"},children:r.jsx("p",{style:{color:L.textTertiary,fontSize:"12px",margin:0},children:"Verify your email to unlock all features and enhance your account security."})})]})]})]})]})}),r.jsx(is,{isOpen:T,onClose:()=>{M(!1)},onUpdate:Oe,colors:L}),r.jsx(as,{baseUrl:l,apiKey:x,appId:d,userId:y.id,isOpen:g,onClose:()=>O(!1),onSuccess:C=>z("success",C),onError:C=>z("error",C),colors:L}),r.jsx(os,{baseUrl:l,apiKey:x,appId:d,userId:y.id,token:e,isOpen:v,onClose:()=>U(!1),onSuccess:C=>z("success",C),onError:C=>z("error",C),colors:L}),r.jsx(ls,{isOpen:q,onClose:()=>{F(!1),N(!1),f({email:y?.email||"",otp:"",appId:d})},onVerify:pe,onSendOTP:le,verifyFormData:J,setVerifyFormData:f,otpSent:k,verifying:h,user:y,colors:L,darkMode:n}),r.jsx("style",{children:`
495
495
  @keyframes slideIn {
496
496
  from {
497
497
  transform: translateX(100%);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuctra/authix",
3
- "version": "1.1.14",
3
+ "version": "1.1.16",
4
4
  "description": "Universal authentication SDK and UI components for React (v16–v19) with TailwindCSS.",
5
5
  "author": "Taha Asif",
6
6
  "license": "MIT",