@neuctra/authix 1.1.7 → 1.1.8

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.
@@ -7825,4 +7825,3 @@ export {
7825
7825
  ve as getSdkConfig,
7826
7826
  po as setSdkConfig
7827
7827
  };
7828
- //# sourceMappingURL=index.es.js.map
@@ -580,4 +580,3 @@ React keys must be passed directly to JSX without using spread:
580
580
  }
581
581
  }
582
582
  `})]})},us=({darkMode:e=!0,primaryColor:t="#3b82f6",onLogout:r,varient:s="classic",propUser:o,className:i="",profileUrl:a,settingsUrl:l,showProfileMenuItem:g=!0,showSettingsMenuItem:p=!0,showViewProfileMenuItem:c=!0,profileLabel:m="My Profile",settingsLabel:I="Settings",viewProfileLabel:j="View Profile",logoutLabel:d="Sign Out"})=>{const{baseUrl:S,apiKey:h,appId:U}=he(),[z,P]=b.useState(!1),[E,M]=b.useState(null),[y,O]=b.useState(!0),[w,N]=b.useState(null),J=b.useRef(null),F=b.useRef(null),[V,Q]=b.useState(!1),[k,G]=b.useState(!1);b.useEffect(()=>{const f=()=>{G(window.innerWidth<768)};return f(),window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)},[]);const B=async f=>{try{if(!f)throw new Error("Invalid user ID");const{data:v}=await W.get(`${S}/users/check-user/${f}?appId=${U}`,{headers:{"x-api-key":h},timeout:1e4});(!v.success||!v.exists)&&(console.warn("User not found, clearing session..."),localStorage.removeItem("userInfo"),M(null),N("Session expired"))}catch(v){console.error("User validation failed:",v);const X=v.response?.status===404?"User not found":v.code==="NETWORK_ERROR"?"Network error":"Validation failed";N(X),v.response?.status===404&&(localStorage.removeItem("userInfo"),M(null))}};b.useEffect(()=>{(async()=>{try{if(O(!0),N(null),o){if(!o.id||!o.name||!o.email)throw new Error("Invalid user data provided");M(o),await B(o.id)}else{const v=localStorage.getItem("userInfo");if(v)try{const X=JSON.parse(v);if(!X.id||!X.name||!X.email)throw new Error("Invalid stored user data");M(X),await B(X.id)}catch(X){console.error("Failed to parse stored user data:",X),localStorage.removeItem("userInfo"),N("Invalid user data")}}}catch(v){console.error("User initialization failed:",v),N(v.message||"Failed to load user")}finally{O(!1)}})()},[o]),b.useEffect(()=>{const f=()=>{if(z&&F.current){const v=F.current.getBoundingClientRect(),X=window.innerWidth,q=window.innerHeight,ae=280,ce=300,ge=X-v.right,$e=v.left,_=q-v.bottom,it=ge>=ae||ge>$e;Q(it),_<ce&&v.top>ce}};return f(),window.addEventListener("resize",f),()=>window.removeEventListener("resize",f)},[z]),b.useEffect(()=>{const f=q=>{J.current&&!J.current.contains(q.target)&&!F.current?.contains(q.target)&&P(!1)},v=q=>{q.key==="Escape"&&P(!1)},X=()=>{z&&P(!1)};return z&&(document.addEventListener("mousedown",f),document.addEventListener("keydown",v),window.addEventListener("scroll",X,{passive:!0})),()=>{document.removeEventListener("mousedown",f),document.removeEventListener("keydown",v),window.removeEventListener("scroll",X)}},[z]);const L=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"},T={wrapper:{position:"relative",display:"inline-block"},avatarButton:{display:"flex",alignItems:"center",gap:k?"6px":"8px",padding:k?"6px 10px 6px 6px":"8px 12px 8px 8px",borderRadius:"24px",backgroundColor:L.surface,cursor:"pointer",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",minWidth:k?"auto":"140px",maxWidth:k?"200px":"none",outline:"none"},avatarImage:{width:k?"28px":"32px",height:k?"28px":"32px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${L.borderLight}`,flexShrink:0},userInfo:{display:"flex",flexDirection:"column",alignItems:"flex-start",flex:1,minWidth:0,overflow:"hidden"},userName:{fontSize:k?"13px":"14px",fontWeight:600,color:L.textPrimary,lineHeight:"1.2",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:k?"80px":"120px"},userEmail:{fontSize:k?"11px":"12px",color:L.textTertiary,lineHeight:"1.2",whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:k?"80px":"120px"},chevron:{transition:"transform 0.2s ease",transform:z?"rotate(180deg)":"rotate(0deg)",color:L.textTertiary,flexShrink:0},dropdown:{position:"absolute",top:"100%",marginTop:"8px",[V?"left":"right"]:"0",backgroundColor:L.surfaceElevated,border:`1px solid ${L.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:z?1:0,pointerEvents:z?"auto":"none",transition:"all 0.2s cubic-bezier(0.4, 0, 0.2, 1)",transform:z?"translateY(0) scale(1)":"translateY(-8px) scale(0.95)",overflow:"hidden"},dropdownSection:{padding:k?"10px 12px":"0px 16px","&:last-child":{borderBottom:"none"}},userSection:{display:"flex",alignItems:"center",gap:k?"10px":"12px",padding:k?"14px":"16px"},dropdownAvatar:{width:k?"40px":"48px",height:k?"40px":"48px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${L.borderLight}`,flexShrink:0},dropdownUserInfo:{display:"flex",flexDirection:"column",flex:1,minWidth:0},dropdownUserName:{fontSize:k?"15px":"16px",fontWeight:600,color:L.textPrimary,lineHeight:"1.2",marginBottom:"2px",overflow:"hidden",textOverflow:"ellipsis"},dropdownUserEmail:{fontSize:k?"13px":"14px",color:L.textSecondary,lineHeight:"1.2",overflow:"hidden",textOverflow:"ellipsis"},menuItem:{display:"flex",alignItems:"center",gap:k?"10px":"12px",padding:k?"10px 12px":"12px 16px",borderRadius:"8px",cursor:"pointer",transition:"all 0.15s ease",color:L.textPrimary,textDecoration:"none",border:"none",background:"none",width:"100%",fontSize:k?"13px":"14px",textAlign:"left",outline:"none"},menuItemText:{flex:1},icon:{width:k?"16px":"18px",height:k?"16px":"18px",color:L.textSecondary,flexShrink:0},logoutButton:{display:"flex",alignItems:"center",gap:k?"10px":"12px",padding:k?"10px 12px":"12px 16px",borderRadius:"8px",cursor:"pointer",transition:"all 0.15s ease",background:"none",border:"none",width:"100%",fontSize:k?"13px":"14px",color:L.error,textAlign:"left",outline:"none"},loadingText:{padding:k?"16px 12px":"20px 16px",textAlign:"center",color:L.textSecondary,fontSize:k?"13px":"14px"},errorState:{padding:k?"16px 12px":"20px 16px",textAlign:"center",color:L.textSecondary,fontSize:k?"13px":"14px",display:"flex",alignItems:"center",justifyContent:"center",gap:"8px",flexDirection:"column"},retryButton:{marginTop:"8px",padding:"8px 16px",backgroundColor:L.accent,color:"#ffffff",border:"none",borderRadius:"6px",cursor:"pointer",fontSize:"12px",fontWeight:500,transition:"background-color 0.2s ease"}},Y=()=>{N(null),O(!0);const f=localStorage.getItem("userInfo");if(f)try{const v=JSON.parse(f);M(v),B(v.id)}catch{N("Invalid user data")}O(!1)},K=(f,v)=>{(f.key==="Enter"||f.key===" ")&&(f.preventDefault(),v())},x=()=>a||E?.profileUrl,R=()=>{const f=x();f&&window.open(f,"_self","noopener,noreferrer")},D=()=>{l&&window.open(l,"_self","noopener,noreferrer")};return n.jsxs("div",{style:T.wrapper,ref:J,className:i,role:"menu","aria-label":"User menu",children:[s==="classic"?n.jsx("div",{ref:F,onClick:()=>P(f=>!f),onKeyDown:f=>K(f,()=>P(v=>!v)),tabIndex:0,role:"button","aria-haspopup":"true","aria-expanded":z,"aria-label":"Toggle user menu",children:E?.avatarUrl?n.jsx("img",{src:E.avatarUrl,alt:`${E?.name||"User"}'s avatar`,style:{width:k?"34px":"40px",height:k?"34px":"40px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${L.borderLight}`,flexShrink:0},loading:"lazy",onError:f=>{const v=f.target;v.onerror=null,v.src=`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(E?.name||"User")}`}}):n.jsx("img",{src:`https://api.dicebear.com/9.x/initials/svg?seed=${encodeURIComponent(E?.name||"User")}`,alt:"Default user avatar",style:{width:k?"34px":"40px",height:k?"34px":"40px",borderRadius:"50%",objectFit:"cover",border:`2px solid ${L.borderLight}`,flexShrink:0},loading:"lazy"})}):n.jsxs("div",{ref:F,style:T.avatarButton,onClick:()=>P(f=>!f),onKeyDown:f=>K(f,()=>P(v=>!v)),tabIndex:0,role:"button","aria-haspopup":"true","aria-expanded":z,"aria-label":"Toggle user menu",onMouseOver:f=>{f.currentTarget.style.backgroundColor=L.surfaceHover,f.currentTarget.style.boxShadow="0 4px 12px rgba(0,0,0,0.15)"},onMouseOut:f=>{f.currentTarget.style.backgroundColor=L.surface,f.currentTarget.style.boxShadow="none"},onBlur:f=>{f.currentTarget.style.outline="none"},children:[E?.avatarUrl?n.jsx("img",{src:E.avatarUrl,alt:`${E.name}'s avatar`,style:T.avatarImage,loading:"lazy",onError:f=>{const v=f.target;v.src="https://api.dicebear.com/9.x/glass/svg?seed=Kingston"}}):n.jsx("img",{src:"https://api.dicebear.com/9.x/glass/svg?seed=Kingston",alt:"Default user avatar",style:T.avatarImage,loading:"lazy"}),!k&&n.jsxs("div",{style:T.userInfo,children:[n.jsx("div",{style:T.userName,title:E?.name,children:E?.name||"Guest"}),E?.email&&n.jsx("div",{style:T.userEmail,title:E.email,children:E.email})]}),n.jsx(Bn,{size:k?14:16,style:T.chevron,"aria-hidden":"true"})]}),z&&n.jsx("div",{style:T.dropdown,role:"menu","aria-label":"User options",children:y?n.jsx("div",{style:T.loadingText,role:"status","aria-live":"polite",children:"Loading user information..."}):E?n.jsxs(n.Fragment,{children:[n.jsxs("div",{style:T.userSection,children:[E?.avatarUrl?n.jsx("img",{src:E.avatarUrl,alt:`${E.name}'s profile picture`,style:T.dropdownAvatar,loading:"lazy",onError:f=>{const v=f.target;v.src=`https://api.dicebear.com/9.x/initials/svg?seed=${E.name}`}}):n.jsx("img",{src:`https://api.dicebear.com/9.x/initials/svg?seed=${E.name}`,alt:`${E.name}'s default avatar`,style:T.dropdownAvatar,loading:"lazy"}),n.jsxs("div",{style:T.dropdownUserInfo,children:[n.jsx("div",{style:T.dropdownUserName,title:E.name,children:E.name}),n.jsx("div",{style:T.dropdownUserEmail,title:E.email,children:E.email})]})]}),n.jsxs("div",{style:T.dropdownSection,children:[g&&x()&&n.jsxs("button",{style:T.menuItem,onClick:R,onMouseOver:f=>{f.currentTarget.style.backgroundColor=L.surfaceHover},onMouseOut:f=>{f.currentTarget.style.backgroundColor="transparent"},onKeyDown:f=>K(f,R),role:"menuitem",tabIndex:0,children:[n.jsx(je,{style:T.icon,"aria-hidden":"true"}),n.jsx("span",{style:T.menuItemText,children:m})]}),p&&l&&n.jsxs("button",{style:T.menuItem,onClick:D,onMouseOver:f=>{f.currentTarget.style.backgroundColor=L.surfaceHover},onMouseOut:f=>{f.currentTarget.style.backgroundColor="transparent"},onKeyDown:f=>K(f,D),role:"menuitem",tabIndex:0,children:[n.jsx(Gn,{style:T.icon,"aria-hidden":"true"}),n.jsx("span",{style:T.menuItemText,children:I})]}),c&&E.profileUrl&&n.jsxs("a",{href:E.profileUrl,target:"_self",rel:"noopener noreferrer",style:T.menuItem,onMouseOver:f=>{f.currentTarget.style.backgroundColor=L.surfaceHover},onMouseOut:f=>{f.currentTarget.style.backgroundColor="transparent"},role:"menuitem",tabIndex:0,children:[n.jsx(xe,{style:T.icon,"aria-hidden":"true"}),n.jsx("span",{style:T.menuItemText,children:j})]})]}),n.jsx("div",{style:T.dropdownSection,children:n.jsxs("button",{style:T.logoutButton,onClick:r,onMouseOver:f=>{f.currentTarget.style.backgroundColor=L.surfaceHover},onMouseOut:f=>{f.currentTarget.style.backgroundColor="transparent"},onKeyDown:f=>K(f,r),role:"menuitem",tabIndex:0,children:[n.jsx(at,{style:{...T.icon,color:L.error},"aria-hidden":"true"}),n.jsx("span",{style:T.menuItemText,children:d})]})})]}):n.jsxs("div",{style:T.errorState,role:"alert",children:[n.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"8px"},children:[n.jsx(ie,{size:16,"aria-hidden":"true"}),n.jsx("span",{children:w||"Not signed in"})]}),w&&w!=="Not signed in"&&n.jsx("button",{style:T.retryButton,onClick:Y,onMouseOver:f=>{f.currentTarget.style.backgroundColor=L.accentHover},onMouseOut:f=>{f.currentTarget.style.backgroundColor=L.accent},children:"Try Again"})]})})]})};te.NeuctraAuthix=On,te.ReactSignedIn=ss,te.ReactSignedOut=os,te.ReactUserButton=us,te.ReactUserLogin=rs,te.ReactUserProfile=ds,te.ReactUserSignUp=es,te.getSdkConfig=he,te.setSdkConfig=Qn,Object.defineProperty(te,Symbol.toStringTag,{value:"Module"})}));
583
- //# sourceMappingURL=index.umd.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuctra/authix",
3
- "version": "1.1.7",
3
+ "version": "1.1.8",
4
4
  "description": "Universal authentication SDK and UI components for React (16–19) + TailwindCSS",
5
5
  "author": "Taha Asif",
6
6
  "license": "MIT",
@@ -25,7 +25,9 @@
25
25
  "require": "./dist/sdk/index.cjs.js"
26
26
  }
27
27
  },
28
- "files": ["dist"],
28
+ "files": [
29
+ "dist"
30
+ ],
29
31
  "scripts": {
30
32
  "dev": "vite",
31
33
  "build": "npm run clean && vite build && tsc --emitDeclarationOnly",