@neuctra/authix 1.1.22 → 1.1.23

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.
@@ -8065,6 +8065,8 @@ const Ls = [
8065
8065
  {
8066
8066
  onSubmit: A,
8067
8067
  style: {
8068
+ width: "100%",
8069
+ height: "100%",
8068
8070
  display: "flex",
8069
8071
  flexDirection: "column",
8070
8072
  gap: 16,
@@ -579,4 +579,4 @@ React keys must be passed directly to JSX without using spread:
579
579
  transition-duration: 0.01ms !important;
580
580
  }
581
581
  }
582
- `})]})},ds=({darkMode:e=!0,primaryColor:t="#3b82f6",onLogout:n,varient:s="classic",propUser:o,className:a="",profileUrl:i,settingsUrl:l,showProfileMenuItem:h=!0,showSettingsMenuItem:d=!0,showViewProfileMenuItem:u=!0,profileLabel:b="My Profile",settingsLabel:y="Settings",viewProfileLabel:S="View Profile",logoutLabel:c="Sign Out"})=>{const{baseUrl:j,apiKey:m,appId:A}=ue(),[P,_]=w.useState(!1),[T,M]=w.useState(null),[g,O]=w.useState(!0),[v,U]=w.useState(null),B=w.useRef(null),F=w.useRef(null),[V,Z]=w.useState(!1),[I,J]=w.useState(!1);w.useEffect(()=>{if(typeof window>"u")return;const x=()=>{J(window.innerWidth<768)};return x(),window.addEventListener("resize",x),()=>window.removeEventListener("resize",x)},[]),w.useEffect(()=>{(async()=>{try{if(O(!0),U(null),o){if(!o.id||!o.name||!o.email)throw new Error("Invalid user data provided");M(o)}else if(typeof window<"u"){const E=localStorage.getItem("userInfo");if(E)try{const $=JSON.parse(E);if(!$.id||!$.name||!$.email)throw new Error("Invalid stored user data");M($)}catch($){console.error("Failed to parse stored user data:",$),localStorage.removeItem("userInfo"),U("Invalid user data")}}}catch(E){console.error("User initialization failed:",E),U(E.message||"Failed to load user")}finally{O(!1)}})()},[o]),w.useEffect(()=>{if(typeof window>"u")return;const x=()=>{if(!P||!F.current)return;const E=F.current.getBoundingClientRect(),$=window.innerWidth,N=window.innerHeight,Y=280,ie=$-E.right,he=E.left;N-E.bottom;const Oe=ie>=Y||ie>he;Z(Oe)};return x(),window.addEventListener("resize",x),()=>window.removeEventListener("resize",x)},[P]),w.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const x=N=>{B.current&&!B.current.contains(N.target)&&!F.current?.contains(N.target)&&_(!1)},E=N=>{N.key==="Escape"&&_(!1)},$=()=>{P&&_(!1)};return P&&(document.addEventListener("mousedown",x),document.addEventListener("keydown",E),window.addEventListener("scroll",$)),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",E),window.removeEventListener("scroll",$)}},[P]);const z=e?{surface:"#000000",surfaceElevated:"#000000",surfaceHover:"#262626",border:"#262626",borderLight:"#404040",textPrimary:"#ffffff",textSecondary:"#a3a3a3",textTertiary:"#737373",accent:t,accentHover:`${t}e6`,error:"#ef4444"}:{surface:"#ffffff",surfaceElevated:"#fafafa",surfaceHover:"#f5f5f5",border:"#e5e5e5",borderLight:"#f0f0f0",textPrimary:"#171717",textSecondary:"#525252",textTertiary:"#a3a3a3",accent:t,accentHover:`${t}e6`,error:"#ef4444"},R={wrapper:{position:"relative",display:"inline-block"},avatarButton:{display:"flex",alignItems:"center",gap:I?"6px":"8px",padding:I?"6px 10px 6px 6px":"8px 12px 8px 8px",borderRadius:"24px",backgroundColor:z.surface,cursor:"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",minWidth:I?"auto":"140px",maxWidth:I?"200px":"none",outline:"none"},avatarImage:{width:I?"28px":"32px",height:I?"28px":"32px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${z.borderLight}`,flexShrink:0},userInfo:{display:"flex",flexDirection:"column",alignItems:"flex-start",flex:1,minWidth:0,overflow:"hidden"},userName:{fontSize:I?"13px":"14px",fontWeight:600,color:z.textPrimary,lineHeight:"1.2",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:I?"80px":"120px"},userEmail:{fontSize:I?"11px":"12px",color:z.textTertiary,lineHeight:"1.2",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:I?"80px":"120px"},chevron:{transition:"transform 0.2s ease",transform:P?"rotate(180deg)":"rotate(0deg)",color:z.textTertiary,flexShrink:0},dropdown:{position:"absolute",top:"100%",marginTop:"8px",[V?"left":"right"]:"0",backgroundColor:z.surfaceElevated,border:`1px solid ${z.border}`,borderRadius:"12px",boxShadow:"0 20px 40px rgba(0,0,0,0.15), 0 4px 12px rgba(0,0,0,0.1)",width:"min(280px, 90vw)",maxWidth:"calc(100vw - 20px)",padding:"6px 6px 16px 6px",zIndex:1e3,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",opacity:P?1:0,pointerEvents:P?"auto":"none",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",transform:P?"translateY(0) scale(1)":"translateY(-8px) scale(0.95)",overflow:"hidden"},dropdownSection:{padding:I?"10px 12px":"0px 16px","&:last-child":{borderBottom:"none"}},userSection:{display:"flex",alignItems:"center",gap:I?"10px":"12px",padding:I?"14px":"16px"},dropdownAvatar:{width:I?"40px":"48px",height:I?"40px":"48px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${z.borderLight}`,flexShrink:0},dropdownUserInfo:{display:"flex",flexDirection:"column",flex:1,minWidth:0},dropdownUserName:{fontSize:I?"15px":"16px",fontWeight:600,color:z.textPrimary,lineHeight:"1.2",marginBottom:"2px",overflow:"hidden",textOverflow:"ellipsis"},dropdownUserEmail:{fontSize:I?"13px":"14px",color:z.textSecondary,lineHeight:"1.2",overflow:"hidden",textOverflow:"ellipsis"},menuItem:{display:"flex",alignItems:"center",gap:I?"10px":"12px",padding:I?"10px 12px":"12px 16px",borderRadius:"8px",cursor:"pointer",transition:"all 0.15s ease",color:z.textPrimary,textDecoration:"none",border:"none",background:"none",width:"100%",fontSize:I?"13px":"14px",textAlign:"left",outline:"none"},menuItemText:{flex:1},icon:{width:I?"16px":"18px",height:I?"16px":"18px",color:z.textSecondary,flexShrink:0},logoutButton:{display:"flex",alignItems:"center",gap:I?"10px":"12px",padding:I?"10px 12px":"12px 16px",borderRadius:"8px",cursor:"pointer",transition:"all 0.15s ease",background:"none",border:"none",width:"100%",fontSize:I?"13px":"14px",color:z.error,textAlign:"left",outline:"none"},loadingText:{padding:I?"16px 12px":"20px 16px",textAlign:"center",color:z.textSecondary,fontSize:I?"13px":"14px"},errorState:{padding:I?"16px 12px":"20px 16px",textAlign:"center",color:z.textSecondary,fontSize:I?"13px":"14px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",flexDirection:"column"},retryButton:{marginTop:"8px",padding:"8px 16px",backgroundColor:z.accent,color:"#ffffff",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",fontWeight:500,transition:"background-color 0.2s ease"}},K=async()=>{U(null),O(!0);try{const x=localStorage.getItem("userInfo");if(x){const E=JSON.parse(x);M(E)}else o&&M(o)}catch(x){console.error("Retry failed:",x),U("Invalid user data"),localStorage.removeItem("userInfo"),M(null)}finally{O(!1)}},te=(x,E)=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),E())},X=()=>i||T?.profileUrl,f=()=>{const x=X();x&&window.open(x,"_self","noopener,noreferrer")},k=()=>{l&&window.open(l,"_self","noopener,noreferrer")};return r.jsxs("div",{style:R.wrapper,ref:B,className:a,role:"menu","aria-label":"User menu",children:[s==="classic"?r.jsx("div",{ref:F,onClick:()=>_(x=>!x),onKeyDown:x=>te(x,()=>_(E=>!E)),tabIndex:0,role:"button","aria-haspopup":"true","aria-expanded":P,"aria-label":"Toggle user menu",children:T?.avatarUrl?r.jsx("img",{src:T.avatarUrl,alt:`${T?.name||"User"}'s avatar`,style:{width:I?"34px":"40px",height:I?"34px":"40px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${z.borderLight}`,flexShrink:0},loading:"lazy",onError:x=>{const E=x.target;E.onerror=null,E.src=`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(T?.name||"User")}`}}):r.jsx("img",{src:`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(T?.name||"User")}`,alt:"Default user avatar",style:{width:I?"34px":"40px",height:I?"34px":"40px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${z.borderLight}`,flexShrink:0},loading:"lazy"})}):r.jsxs("div",{ref:F,style:R.avatarButton,onClick:()=>_(x=>!x),onKeyDown:x=>te(x,()=>_(E=>!E)),tabIndex:0,role:"button","aria-haspopup":"true","aria-expanded":P,"aria-label":"Toggle user menu",onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover,x.currentTarget.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)"},onMouseOut:x=>{x.currentTarget.style.backgroundColor=z.surface,x.currentTarget.style.boxShadow="none"},onBlur:x=>{x.currentTarget.style.outline="none"},children:[T?.avatarUrl?r.jsx("img",{src:T.avatarUrl,alt:`${T.name}'s avatar`,style:R.avatarImage,loading:"lazy",onError:x=>{const E=x.target;E.src="https://api.dicebear.com/9.x/glass/svg?seed=Kingston"}}):r.jsx("img",{src:"https://api.dicebear.com/9.x/glass/svg?seed=Kingston",alt:"Default user avatar",style:R.avatarImage,loading:"lazy"}),!I&&r.jsxs("div",{style:R.userInfo,children:[r.jsx("div",{style:R.userName,title:T?.name,children:T?.name||"Guest"}),T?.email&&r.jsx("div",{style:R.userEmail,title:T.email,children:T.email})]}),r.jsx(Fn,{size:I?14:16,style:R.chevron,"aria-hidden":"true"})]}),P&&r.jsx("div",{style:R.dropdown,role:"menu","aria-label":"User options",children:g?r.jsx("div",{style:R.loadingText,role:"status","aria-live":"polite",children:"Loading user information..."}):T?r.jsxs(r.Fragment,{children:[r.jsxs("div",{style:R.userSection,children:[T?.avatarUrl?r.jsx("img",{src:T.avatarUrl,alt:`${T.name}'s profile picture`,style:R.dropdownAvatar,loading:"lazy",onError:x=>{const E=x.target;E.src=`https://api.dicebear.com/9.x/initials/svg?seed=${T.name}`}}):r.jsx("img",{src:`https://api.dicebear.com/9.x/initials/svg?seed=${T.name}`,alt:`${T.name}'s default avatar`,style:R.dropdownAvatar,loading:"lazy"}),r.jsxs("div",{style:R.dropdownUserInfo,children:[r.jsx("div",{style:R.dropdownUserName,title:T.name,children:T.name}),r.jsx("div",{style:R.dropdownUserEmail,title:T.email,children:T.email})]})]}),r.jsxs("div",{style:R.dropdownSection,children:[h&&X()&&r.jsxs("button",{style:R.menuItem,onClick:f,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor="transparent"},onKeyDown:x=>te(x,f),role:"menuitem",tabIndex:0,children:[r.jsx(Se,{style:R.icon,"aria-hidden":"true"}),r.jsx("span",{style:R.menuItemText,children:b})]}),d&&l&&r.jsxs("button",{style:R.menuItem,onClick:k,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor="transparent"},onKeyDown:x=>te(x,k),role:"menuitem",tabIndex:0,children:[r.jsx(Xn,{style:R.icon,"aria-hidden":"true"}),r.jsx("span",{style:R.menuItemText,children:y})]}),u&&T.profileUrl&&r.jsxs("a",{href:T.profileUrl,target:"_self",rel:"noopener noreferrer",style:R.menuItem,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor="transparent"},role:"menuitem",tabIndex:0,children:[r.jsx(ce,{style:R.icon,"aria-hidden":"true"}),r.jsx("span",{style:R.menuItemText,children:S})]})]}),r.jsx("div",{style:R.dropdownSection,children:r.jsxs("button",{style:R.logoutButton,onClick:n,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor="transparent"},onKeyDown:x=>te(x,n),role:"menuitem",tabIndex:0,children:[r.jsx(it,{style:{...R.icon,color:z.error},"aria-hidden":"true"}),r.jsx("span",{style:R.menuItemText,children:c})]})})]}):r.jsxs("div",{style:R.errorState,role:"alert",children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(le,{size:16,"aria-hidden":"true"}),r.jsx("span",{children:v||"Not signed in"})]}),v&&v!=="Not signed in"&&r.jsx("button",{style:R.retryButton,onClick:K,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.accentHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor=z.accent},children:"Try Again"})]})})]})},cs=({user:e,darkMode:t=!0,primaryColor:n="#00C212",onVerify:s})=>{const{appId:o,baseUrl:a,apiKey:i}=ue(),[l,h]=w.useState({email:e?.email||"",otp:"",appId:o}),[d,u]=w.useState(!1),[b,y]=w.useState(!1),[S,c]=w.useState(null),j=(g,O)=>{let v=parseInt(g.replace("#",""),16),U=(v>>16)+O,B=(v>>8&255)+O,F=(v&255)+O;return U=Math.min(255,Math.max(0,U)),B=Math.min(255,Math.max(0,B)),F=Math.min(255,Math.max(0,F)),`#${(F|B<<8|U<<16).toString(16).padStart(6,"0")}`},m=t?{surface:"#09090b",surfaceLight:"#27272a",textPrimary:"#ffffff",textSecondary:"#d4d4d8",textTertiary:"#a1a1aa",border:"#27272a",accent:n,accentHover:j(n,-15),success:j(n,0),warning:"#f59e0b"}:{surface:"#fafafa",surfaceLight:"#f4f4f5",textPrimary:"#18181b",textSecondary:"#52525b",textTertiary:"#71717a",border:"#e4e4e7",accent:n,accentHover:j(n,-15),success:j(n,0),warning:"#d97706"};w.useEffect(()=>{e?.email&&h(g=>({...g,email:e.email}))},[e?.email]);const A=(g,O)=>{c({type:g,message:O}),setTimeout(()=>c(null),3e3)},P=async()=>{if(!l.email||!/\S+@\S+\.\S+/.test(l.email)){A("error","Please enter a valid email");return}try{y(!0);const g=await W.post(`${a}/users/send-verify-otp/${e?.id}`,{email:l.email},{headers:{"x-api-key":i,"x-app-id":o}});g.data.success?(A("success",g.data.message||"OTP sent!"),u(!0)):A("error",g.data.message||"Failed to send OTP")}catch(g){A("error",g.response?.data?.message||"Server error")}finally{y(!1)}},_=async g=>{if(g.preventDefault(),!l.email||!l.otp){A("error","Please fill in all fields");return}try{y(!0);const O=await W.post(`${a}/users/verify-email`,l);if(O.data.success&&e){const v={...e,isVerified:!0};s?.(v),A("success",O.data.message||"Email verified!"),u(!1),h({email:e.email,otp:"",appId:o})}else A("error",O.data.message||"Verification failed")}catch(O){A("error",O.response?.data?.message||"Server error")}finally{y(!1)}},T={width:"100%",padding:"12px 12px 12px 40px",borderRadius:8,border:`1px solid ${m.border}`,backgroundColor:m.surfaceLight,color:m.textPrimary,fontSize:14,outline:"none"},M=(g=!1)=>({flex:1,padding:12,borderRadius:8,color:"#fff",fontWeight:500,cursor:g?"not-allowed":"pointer",background:`linear-gradient(to right, ${m.accent}, ${m.accentHover})`,opacity:g?.7:1,display:"flex",alignItems:"center",justifyContent:"center",gap:8,fontSize:14,border:"none"});return r.jsxs("form",{onSubmit:_,style:{display:"flex",flexDirection:"column",gap:16,backgroundColor:m.surface,padding:24,borderRadius:16,border:`1px solid ${m.border}`},children:[S&&r.jsxs("div",{style:{padding:"12px 20px",borderRadius:12,fontSize:13,fontWeight:500,color:S.type==="success"?m.success:m.warning,border:`1px solid ${S.type==="success"?m.success:m.warning}`,backgroundColor:S.type==="success"?`${m.success}20`:`${m.warning}20`,display:"flex",alignItems:"center",gap:8},children:[S.type==="success"?r.jsx(de,{size:16}):r.jsx(le,{size:16}),S.message]}),r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[r.jsx("label",{style:{color:m.textSecondary},children:"Email"}),r.jsxs("div",{style:{position:"relative"},children:[r.jsx(ce,{size:18,style:{position:"absolute",left:12,top:"50%",transform:"translateY(-50%)",color:m.textTertiary,pointerEvents:"none"}}),r.jsx("input",{type:"email",value:l.email,onChange:g=>h(O=>({...O,email:g.target.value})),placeholder:"Enter your email",style:T,required:!0})]})]}),d&&r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[r.jsx("label",{style:{color:m.textSecondary},children:"OTP"}),r.jsxs("div",{style:{position:"relative"},children:[r.jsx(ot,{size:18,style:{position:"absolute",left:12,top:"50%",transform:"translateY(-50%)",color:m.textTertiary,pointerEvents:"none"}}),r.jsx("input",{type:"text",value:l.otp,onChange:g=>h(O=>({...O,otp:g.target.value})),placeholder:"Enter OTP",style:T,required:!0})]})]}),r.jsx("div",{style:{display:"flex",gap:12},children:d?r.jsxs("button",{type:"submit",disabled:b,style:M(b),children:[b?r.jsx(oe,{size:16,className:"spinner"}):r.jsx(de,{size:16}),b?"Verifying...":"Verify Email"]}):r.jsxs("button",{type:"button",onClick:P,disabled:b,style:M(b),children:[b?r.jsx(oe,{size:16,className:"spinner"}):r.jsx(at,{size:16}),b?"Sending...":"Send OTP"]})})]})};Q.NeuctraAuthix=On,Q.ReactEmailVerification=cs,Q.ReactSignedIn=rs,Q.ReactSignedOut=ns,Q.ReactUserButton=ds,Q.ReactUserLogin=ts,Q.ReactUserProfile=ls,Q.ReactUserSignUp=Qn,Q.getSdkConfig=ue,Q.setSdkConfig=Zn,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"})}));
582
+ `})]})},ds=({darkMode:e=!0,primaryColor:t="#3b82f6",onLogout:n,varient:s="classic",propUser:o,className:a="",profileUrl:i,settingsUrl:l,showProfileMenuItem:h=!0,showSettingsMenuItem:d=!0,showViewProfileMenuItem:u=!0,profileLabel:b="My Profile",settingsLabel:y="Settings",viewProfileLabel:S="View Profile",logoutLabel:c="Sign Out"})=>{const{baseUrl:j,apiKey:m,appId:A}=ue(),[P,_]=w.useState(!1),[T,M]=w.useState(null),[g,O]=w.useState(!0),[v,U]=w.useState(null),B=w.useRef(null),F=w.useRef(null),[V,Z]=w.useState(!1),[I,J]=w.useState(!1);w.useEffect(()=>{if(typeof window>"u")return;const x=()=>{J(window.innerWidth<768)};return x(),window.addEventListener("resize",x),()=>window.removeEventListener("resize",x)},[]),w.useEffect(()=>{(async()=>{try{if(O(!0),U(null),o){if(!o.id||!o.name||!o.email)throw new Error("Invalid user data provided");M(o)}else if(typeof window<"u"){const E=localStorage.getItem("userInfo");if(E)try{const $=JSON.parse(E);if(!$.id||!$.name||!$.email)throw new Error("Invalid stored user data");M($)}catch($){console.error("Failed to parse stored user data:",$),localStorage.removeItem("userInfo"),U("Invalid user data")}}}catch(E){console.error("User initialization failed:",E),U(E.message||"Failed to load user")}finally{O(!1)}})()},[o]),w.useEffect(()=>{if(typeof window>"u")return;const x=()=>{if(!P||!F.current)return;const E=F.current.getBoundingClientRect(),$=window.innerWidth,N=window.innerHeight,Y=280,ie=$-E.right,he=E.left;N-E.bottom;const Oe=ie>=Y||ie>he;Z(Oe)};return x(),window.addEventListener("resize",x),()=>window.removeEventListener("resize",x)},[P]),w.useEffect(()=>{if(typeof window>"u"||typeof document>"u")return;const x=N=>{B.current&&!B.current.contains(N.target)&&!F.current?.contains(N.target)&&_(!1)},E=N=>{N.key==="Escape"&&_(!1)},$=()=>{P&&_(!1)};return P&&(document.addEventListener("mousedown",x),document.addEventListener("keydown",E),window.addEventListener("scroll",$)),()=>{document.removeEventListener("mousedown",x),document.removeEventListener("keydown",E),window.removeEventListener("scroll",$)}},[P]);const z=e?{surface:"#000000",surfaceElevated:"#000000",surfaceHover:"#262626",border:"#262626",borderLight:"#404040",textPrimary:"#ffffff",textSecondary:"#a3a3a3",textTertiary:"#737373",accent:t,accentHover:`${t}e6`,error:"#ef4444"}:{surface:"#ffffff",surfaceElevated:"#fafafa",surfaceHover:"#f5f5f5",border:"#e5e5e5",borderLight:"#f0f0f0",textPrimary:"#171717",textSecondary:"#525252",textTertiary:"#a3a3a3",accent:t,accentHover:`${t}e6`,error:"#ef4444"},R={wrapper:{position:"relative",display:"inline-block"},avatarButton:{display:"flex",alignItems:"center",gap:I?"6px":"8px",padding:I?"6px 10px 6px 6px":"8px 12px 8px 8px",borderRadius:"24px",backgroundColor:z.surface,cursor:"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",minWidth:I?"auto":"140px",maxWidth:I?"200px":"none",outline:"none"},avatarImage:{width:I?"28px":"32px",height:I?"28px":"32px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${z.borderLight}`,flexShrink:0},userInfo:{display:"flex",flexDirection:"column",alignItems:"flex-start",flex:1,minWidth:0,overflow:"hidden"},userName:{fontSize:I?"13px":"14px",fontWeight:600,color:z.textPrimary,lineHeight:"1.2",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:I?"80px":"120px"},userEmail:{fontSize:I?"11px":"12px",color:z.textTertiary,lineHeight:"1.2",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:I?"80px":"120px"},chevron:{transition:"transform 0.2s ease",transform:P?"rotate(180deg)":"rotate(0deg)",color:z.textTertiary,flexShrink:0},dropdown:{position:"absolute",top:"100%",marginTop:"8px",[V?"left":"right"]:"0",backgroundColor:z.surfaceElevated,border:`1px solid ${z.border}`,borderRadius:"12px",boxShadow:"0 20px 40px rgba(0,0,0,0.15), 0 4px 12px rgba(0,0,0,0.1)",width:"min(280px, 90vw)",maxWidth:"calc(100vw - 20px)",padding:"6px 6px 16px 6px",zIndex:1e3,fontFamily:"'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif",opacity:P?1:0,pointerEvents:P?"auto":"none",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",transform:P?"translateY(0) scale(1)":"translateY(-8px) scale(0.95)",overflow:"hidden"},dropdownSection:{padding:I?"10px 12px":"0px 16px","&:last-child":{borderBottom:"none"}},userSection:{display:"flex",alignItems:"center",gap:I?"10px":"12px",padding:I?"14px":"16px"},dropdownAvatar:{width:I?"40px":"48px",height:I?"40px":"48px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${z.borderLight}`,flexShrink:0},dropdownUserInfo:{display:"flex",flexDirection:"column",flex:1,minWidth:0},dropdownUserName:{fontSize:I?"15px":"16px",fontWeight:600,color:z.textPrimary,lineHeight:"1.2",marginBottom:"2px",overflow:"hidden",textOverflow:"ellipsis"},dropdownUserEmail:{fontSize:I?"13px":"14px",color:z.textSecondary,lineHeight:"1.2",overflow:"hidden",textOverflow:"ellipsis"},menuItem:{display:"flex",alignItems:"center",gap:I?"10px":"12px",padding:I?"10px 12px":"12px 16px",borderRadius:"8px",cursor:"pointer",transition:"all 0.15s ease",color:z.textPrimary,textDecoration:"none",border:"none",background:"none",width:"100%",fontSize:I?"13px":"14px",textAlign:"left",outline:"none"},menuItemText:{flex:1},icon:{width:I?"16px":"18px",height:I?"16px":"18px",color:z.textSecondary,flexShrink:0},logoutButton:{display:"flex",alignItems:"center",gap:I?"10px":"12px",padding:I?"10px 12px":"12px 16px",borderRadius:"8px",cursor:"pointer",transition:"all 0.15s ease",background:"none",border:"none",width:"100%",fontSize:I?"13px":"14px",color:z.error,textAlign:"left",outline:"none"},loadingText:{padding:I?"16px 12px":"20px 16px",textAlign:"center",color:z.textSecondary,fontSize:I?"13px":"14px"},errorState:{padding:I?"16px 12px":"20px 16px",textAlign:"center",color:z.textSecondary,fontSize:I?"13px":"14px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",flexDirection:"column"},retryButton:{marginTop:"8px",padding:"8px 16px",backgroundColor:z.accent,color:"#ffffff",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",fontWeight:500,transition:"background-color 0.2s ease"}},K=async()=>{U(null),O(!0);try{const x=localStorage.getItem("userInfo");if(x){const E=JSON.parse(x);M(E)}else o&&M(o)}catch(x){console.error("Retry failed:",x),U("Invalid user data"),localStorage.removeItem("userInfo"),M(null)}finally{O(!1)}},te=(x,E)=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),E())},X=()=>i||T?.profileUrl,f=()=>{const x=X();x&&window.open(x,"_self","noopener,noreferrer")},k=()=>{l&&window.open(l,"_self","noopener,noreferrer")};return r.jsxs("div",{style:R.wrapper,ref:B,className:a,role:"menu","aria-label":"User menu",children:[s==="classic"?r.jsx("div",{ref:F,onClick:()=>_(x=>!x),onKeyDown:x=>te(x,()=>_(E=>!E)),tabIndex:0,role:"button","aria-haspopup":"true","aria-expanded":P,"aria-label":"Toggle user menu",children:T?.avatarUrl?r.jsx("img",{src:T.avatarUrl,alt:`${T?.name||"User"}'s avatar`,style:{width:I?"34px":"40px",height:I?"34px":"40px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${z.borderLight}`,flexShrink:0},loading:"lazy",onError:x=>{const E=x.target;E.onerror=null,E.src=`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(T?.name||"User")}`}}):r.jsx("img",{src:`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(T?.name||"User")}`,alt:"Default user avatar",style:{width:I?"34px":"40px",height:I?"34px":"40px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${z.borderLight}`,flexShrink:0},loading:"lazy"})}):r.jsxs("div",{ref:F,style:R.avatarButton,onClick:()=>_(x=>!x),onKeyDown:x=>te(x,()=>_(E=>!E)),tabIndex:0,role:"button","aria-haspopup":"true","aria-expanded":P,"aria-label":"Toggle user menu",onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover,x.currentTarget.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)"},onMouseOut:x=>{x.currentTarget.style.backgroundColor=z.surface,x.currentTarget.style.boxShadow="none"},onBlur:x=>{x.currentTarget.style.outline="none"},children:[T?.avatarUrl?r.jsx("img",{src:T.avatarUrl,alt:`${T.name}'s avatar`,style:R.avatarImage,loading:"lazy",onError:x=>{const E=x.target;E.src="https://api.dicebear.com/9.x/glass/svg?seed=Kingston"}}):r.jsx("img",{src:"https://api.dicebear.com/9.x/glass/svg?seed=Kingston",alt:"Default user avatar",style:R.avatarImage,loading:"lazy"}),!I&&r.jsxs("div",{style:R.userInfo,children:[r.jsx("div",{style:R.userName,title:T?.name,children:T?.name||"Guest"}),T?.email&&r.jsx("div",{style:R.userEmail,title:T.email,children:T.email})]}),r.jsx(Fn,{size:I?14:16,style:R.chevron,"aria-hidden":"true"})]}),P&&r.jsx("div",{style:R.dropdown,role:"menu","aria-label":"User options",children:g?r.jsx("div",{style:R.loadingText,role:"status","aria-live":"polite",children:"Loading user information..."}):T?r.jsxs(r.Fragment,{children:[r.jsxs("div",{style:R.userSection,children:[T?.avatarUrl?r.jsx("img",{src:T.avatarUrl,alt:`${T.name}'s profile picture`,style:R.dropdownAvatar,loading:"lazy",onError:x=>{const E=x.target;E.src=`https://api.dicebear.com/9.x/initials/svg?seed=${T.name}`}}):r.jsx("img",{src:`https://api.dicebear.com/9.x/initials/svg?seed=${T.name}`,alt:`${T.name}'s default avatar`,style:R.dropdownAvatar,loading:"lazy"}),r.jsxs("div",{style:R.dropdownUserInfo,children:[r.jsx("div",{style:R.dropdownUserName,title:T.name,children:T.name}),r.jsx("div",{style:R.dropdownUserEmail,title:T.email,children:T.email})]})]}),r.jsxs("div",{style:R.dropdownSection,children:[h&&X()&&r.jsxs("button",{style:R.menuItem,onClick:f,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor="transparent"},onKeyDown:x=>te(x,f),role:"menuitem",tabIndex:0,children:[r.jsx(Se,{style:R.icon,"aria-hidden":"true"}),r.jsx("span",{style:R.menuItemText,children:b})]}),d&&l&&r.jsxs("button",{style:R.menuItem,onClick:k,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor="transparent"},onKeyDown:x=>te(x,k),role:"menuitem",tabIndex:0,children:[r.jsx(Xn,{style:R.icon,"aria-hidden":"true"}),r.jsx("span",{style:R.menuItemText,children:y})]}),u&&T.profileUrl&&r.jsxs("a",{href:T.profileUrl,target:"_self",rel:"noopener noreferrer",style:R.menuItem,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor="transparent"},role:"menuitem",tabIndex:0,children:[r.jsx(ce,{style:R.icon,"aria-hidden":"true"}),r.jsx("span",{style:R.menuItemText,children:S})]})]}),r.jsx("div",{style:R.dropdownSection,children:r.jsxs("button",{style:R.logoutButton,onClick:n,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.surfaceHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor="transparent"},onKeyDown:x=>te(x,n),role:"menuitem",tabIndex:0,children:[r.jsx(it,{style:{...R.icon,color:z.error},"aria-hidden":"true"}),r.jsx("span",{style:R.menuItemText,children:c})]})})]}):r.jsxs("div",{style:R.errorState,role:"alert",children:[r.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[r.jsx(le,{size:16,"aria-hidden":"true"}),r.jsx("span",{children:v||"Not signed in"})]}),v&&v!=="Not signed in"&&r.jsx("button",{style:R.retryButton,onClick:K,onMouseOver:x=>{x.currentTarget.style.backgroundColor=z.accentHover},onMouseOut:x=>{x.currentTarget.style.backgroundColor=z.accent},children:"Try Again"})]})})]})},cs=({user:e,darkMode:t=!0,primaryColor:n="#00C212",onVerify:s})=>{const{appId:o,baseUrl:a,apiKey:i}=ue(),[l,h]=w.useState({email:e?.email||"",otp:"",appId:o}),[d,u]=w.useState(!1),[b,y]=w.useState(!1),[S,c]=w.useState(null),j=(g,O)=>{let v=parseInt(g.replace("#",""),16),U=(v>>16)+O,B=(v>>8&255)+O,F=(v&255)+O;return U=Math.min(255,Math.max(0,U)),B=Math.min(255,Math.max(0,B)),F=Math.min(255,Math.max(0,F)),`#${(F|B<<8|U<<16).toString(16).padStart(6,"0")}`},m=t?{surface:"#09090b",surfaceLight:"#27272a",textPrimary:"#ffffff",textSecondary:"#d4d4d8",textTertiary:"#a1a1aa",border:"#27272a",accent:n,accentHover:j(n,-15),success:j(n,0),warning:"#f59e0b"}:{surface:"#fafafa",surfaceLight:"#f4f4f5",textPrimary:"#18181b",textSecondary:"#52525b",textTertiary:"#71717a",border:"#e4e4e7",accent:n,accentHover:j(n,-15),success:j(n,0),warning:"#d97706"};w.useEffect(()=>{e?.email&&h(g=>({...g,email:e.email}))},[e?.email]);const A=(g,O)=>{c({type:g,message:O}),setTimeout(()=>c(null),3e3)},P=async()=>{if(!l.email||!/\S+@\S+\.\S+/.test(l.email)){A("error","Please enter a valid email");return}try{y(!0);const g=await W.post(`${a}/users/send-verify-otp/${e?.id}`,{email:l.email},{headers:{"x-api-key":i,"x-app-id":o}});g.data.success?(A("success",g.data.message||"OTP sent!"),u(!0)):A("error",g.data.message||"Failed to send OTP")}catch(g){A("error",g.response?.data?.message||"Server error")}finally{y(!1)}},_=async g=>{if(g.preventDefault(),!l.email||!l.otp){A("error","Please fill in all fields");return}try{y(!0);const O=await W.post(`${a}/users/verify-email`,l);if(O.data.success&&e){const v={...e,isVerified:!0};s?.(v),A("success",O.data.message||"Email verified!"),u(!1),h({email:e.email,otp:"",appId:o})}else A("error",O.data.message||"Verification failed")}catch(O){A("error",O.response?.data?.message||"Server error")}finally{y(!1)}},T={width:"100%",padding:"12px 12px 12px 40px",borderRadius:8,border:`1px solid ${m.border}`,backgroundColor:m.surfaceLight,color:m.textPrimary,fontSize:14,outline:"none"},M=(g=!1)=>({flex:1,padding:12,borderRadius:8,color:"#fff",fontWeight:500,cursor:g?"not-allowed":"pointer",background:`linear-gradient(to right, ${m.accent}, ${m.accentHover})`,opacity:g?.7:1,display:"flex",alignItems:"center",justifyContent:"center",gap:8,fontSize:14,border:"none"});return r.jsxs("form",{onSubmit:_,style:{width:"100%",height:"100%",display:"flex",flexDirection:"column",gap:16,backgroundColor:m.surface,padding:24,borderRadius:16,border:`1px solid ${m.border}`},children:[S&&r.jsxs("div",{style:{padding:"12px 20px",borderRadius:12,fontSize:13,fontWeight:500,color:S.type==="success"?m.success:m.warning,border:`1px solid ${S.type==="success"?m.success:m.warning}`,backgroundColor:S.type==="success"?`${m.success}20`:`${m.warning}20`,display:"flex",alignItems:"center",gap:8},children:[S.type==="success"?r.jsx(de,{size:16}):r.jsx(le,{size:16}),S.message]}),r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[r.jsx("label",{style:{color:m.textSecondary},children:"Email"}),r.jsxs("div",{style:{position:"relative"},children:[r.jsx(ce,{size:18,style:{position:"absolute",left:12,top:"50%",transform:"translateY(-50%)",color:m.textTertiary,pointerEvents:"none"}}),r.jsx("input",{type:"email",value:l.email,onChange:g=>h(O=>({...O,email:g.target.value})),placeholder:"Enter your email",style:T,required:!0})]})]}),d&&r.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8},children:[r.jsx("label",{style:{color:m.textSecondary},children:"OTP"}),r.jsxs("div",{style:{position:"relative"},children:[r.jsx(ot,{size:18,style:{position:"absolute",left:12,top:"50%",transform:"translateY(-50%)",color:m.textTertiary,pointerEvents:"none"}}),r.jsx("input",{type:"text",value:l.otp,onChange:g=>h(O=>({...O,otp:g.target.value})),placeholder:"Enter OTP",style:T,required:!0})]})]}),r.jsx("div",{style:{display:"flex",gap:12},children:d?r.jsxs("button",{type:"submit",disabled:b,style:M(b),children:[b?r.jsx(oe,{size:16,className:"spinner"}):r.jsx(de,{size:16}),b?"Verifying...":"Verify Email"]}):r.jsxs("button",{type:"button",onClick:P,disabled:b,style:M(b),children:[b?r.jsx(oe,{size:16,className:"spinner"}):r.jsx(at,{size:16}),b?"Sending...":"Send OTP"]})})]})};Q.NeuctraAuthix=On,Q.ReactEmailVerification=cs,Q.ReactSignedIn=rs,Q.ReactSignedOut=ns,Q.ReactUserButton=ds,Q.ReactUserLogin=ts,Q.ReactUserProfile=ls,Q.ReactUserSignUp=Qn,Q.getSdkConfig=ue,Q.setSdkConfig=Zn,Object.defineProperty(Q,Symbol.toStringTag,{value:"Module"})}));
@@ -1 +1 @@
1
- {"version":3,"file":"UserVerify.d.ts","sourceRoot":"","sources":["../../src/react/UserVerify.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAI3C,UAAU,2BAA2B;IACnC,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC5C;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CA2QxE,CAAC"}
1
+ {"version":3,"file":"UserVerify.d.ts","sourceRoot":"","sources":["../../src/react/UserVerify.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAI3C,UAAU,2BAA2B;IACnC,IAAI,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,QAAQ,KAAK,IAAI,CAAC;CAC5C;AAED,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CA6QxE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuctra/authix",
3
- "version": "1.1.22",
3
+ "version": "1.1.23",
4
4
  "description": "Universal authentication SDK and UI components for React (v16–v19) with TailwindCSS.",
5
5
  "author": "Taha Asif",
6
6
  "license": "MIT",