@strands.gg/accui 2.17.12 → 2.17.14

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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("nuxt/app"),a=require("../../../useStrandsAuth-DSDtq0F7.cjs.js"),u=()=>{const t=e.useRuntimeConfig().public.strandsAuth,n=a.useStrandsAuth();return{...n,initialize:async()=>{await n.initialize()},signIn:async s=>{const i=await n.signIn(s);return i&&t.onSignInUrl&&await e.navigateTo(t.onSignInUrl),i},signUp:async s=>await n.signUp({email:s.email,password:"",firstName:"",lastName:""}),signOut:async()=>{await n.signOut(),t.onSignOutUrl&&await e.navigateTo(t.onSignOutUrl)}}},r=()=>{const{user:t}=u();return{user:t}},o=()=>{const{isAuthenticated:t,isLoading:n}=u();return{isAuthenticated:t,isLoading:n}};exports.useAuthState=o;exports.useAuthUser=r;exports.useStrandsAuth=u;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("nuxt/app"),a=require("../../../useStrandsAuth-CA_pJ6rc.cjs.js"),u=()=>{const t=e.useRuntimeConfig().public.strandsAuth,n=a.useStrandsAuth();return{...n,initialize:async()=>{await n.initialize()},signIn:async s=>{const i=await n.signIn(s);return i&&t.onSignInUrl&&await e.navigateTo(t.onSignInUrl),i},signUp:async s=>await n.signUp({email:s.email,password:"",firstName:"",lastName:""}),signOut:async()=>{await n.signOut(),t.onSignOutUrl&&await e.navigateTo(t.onSignOutUrl)}}},r=()=>{const{user:t}=u();return{user:t}},o=()=>{const{isAuthenticated:t,isLoading:n}=u();return{isAuthenticated:t,isLoading:n}};exports.useAuthState=o;exports.useAuthUser=r;exports.useStrandsAuth=u;
@@ -1,5 +1,5 @@
1
1
  import { useRuntimeConfig as e, navigateTo as a } from "nuxt/app";
2
- import { u as r } from "../../../useStrandsAuth-C2WOjQ2Z.es.js";
2
+ import { u as r } from "../../../useStrandsAuth-D0lFZGwG.es.js";
3
3
  const u = () => {
4
4
  const n = e().public.strandsAuth, t = r();
5
5
  return {
@@ -1 +1 @@
1
- "use strict";const u=require("vue"),we=require("./useStrandsConfig-B5kp4aF9.cjs.js");class me{cache=new Map;DEFAULT_TTL=300*1e3;async fetch(d,v,g=this.DEFAULT_TTL){const x=Date.now(),i=this.cache.get(d);if(i&&x-i.timestamp<i.ttl)return i.promise;this.cleanExpired();const o=v().finally(()=>{setTimeout(()=>{this.cache.delete(d)},g)});return this.cache.set(d,{promise:o,timestamp:x,ttl:g}),o}clear(){this.cache.clear()}invalidate(d){this.cache.delete(d)}cleanExpired(){const d=Date.now();for(const[v,g]of this.cache.entries())d-g.timestamp>g.ttl&&this.cache.delete(v)}getStats(){return{size:this.cache.size,entries:Array.from(this.cache.keys())}}}const w=new me;function ye(){return{fetch:w.fetch.bind(w),clear:w.clear.bind(w),invalidate:w.invalidate.bind(w),getStats:w.getStats.bind(w)}}function pe(n,d){let v=null;return(...g)=>{v&&clearTimeout(v),v=setTimeout(()=>{n(...g)},d)}}const F=pe((n,d)=>{typeof window<"u"&&localStorage.setItem(n,d)},300),E=n=>({id:n.id,email:n.email,firstName:n.first_name||n.firstName||"",lastName:n.last_name||n.lastName||"",avatar:n.avatar_url||n.avatar,mfaEnabled:n.mfa_enabled??n.mfaEnabled??!1,emailVerified:n.email_verified??n.emailVerified??!1,passwordUpdatedAt:n.password_updated_at||n.passwordUpdatedAt,settings:n.settings||{},xp:n.xp||0,level:n.level||1,next_level_xp:n.next_level_xp||n.next_level_xp||4,username:n.username,usernameLastChangedAt:n.username_last_changed_at||n.usernameLastChangedAt,createdAt:n.created_at||n.createdAt,updatedAt:n.updated_at||n.updatedAt||new Date().toISOString()}),Se={currentUser:u.ref(null),currentSession:u.ref(null),loadingStates:u.ref({initializing:!0,signingIn:!1,signingUp:!1,signingOut:!1,refreshingToken:!1,sendingMfaEmail:!1,verifyingMfa:!1,loadingProfile:!1}),isInitialized:u.ref(!1),mfaRequired:u.ref(!1),mfaSessionId:u.ref(null),availableMfaMethods:u.ref([])};let T=null,m=null,I=null;function _e(){const{getUrl:n,config:d}=we.useStrandsConfig(),{fetch:v,clear:g,invalidate:x}=ye(),{currentUser:i,currentSession:o,loadingStates:s,isInitialized:k,mfaRequired:y,mfaSessionId:f,availableMfaMethods:p}=Se,S=()=>{if(i.value=null,o.value=null,y.value=!1,f.value=null,p.value=[],typeof window<"u"&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),O(),$(),m=null,g(),typeof window<"u"&&d.value?.onSignOutUrl){const e=window.location.pathname+window.location.search,t=d.value.onSignOutUrl;e!==t&&(window.location.href=t)}},z=u.computed(()=>s.value.initializing),L=u.computed(()=>s.value.signingIn),R=u.computed(()=>s.value.signingUp),U=u.computed(()=>s.value.signingOut),q=u.computed(()=>s.value.refreshingToken),B=u.computed(()=>s.value.sendingMfaEmail),V=u.computed(()=>s.value.verifyingMfa);u.computed(()=>s.value.loadingProfile);const j=u.computed(()=>s.value.signingIn||s.value.signingUp||s.value.signingOut||s.value.refreshingToken||s.value.sendingMfaEmail||s.value.verifyingMfa||s.value.loadingProfile),K=u.computed(()=>s.value.initializing||j.value),G=u.computed(()=>{const e=s.value;return e.initializing?"Checking authentication...":e.signingIn?"Signing you in...":e.signingUp?"Creating your account...":e.signingOut?"Signing you out...":e.refreshingToken?"Refreshing session...":e.sendingMfaEmail?"Sending verification code...":e.verifyingMfa?"Verifying code...":e.loadingProfile?"Loading profile...":"Loading..."}),A=()=>{const e={};return o.value?.accessToken&&(e.Authorization=`Bearer ${o.value.accessToken}`),o.value?.refreshToken&&(e["x-refresh-token"]=o.value.refreshToken),e},H=async(e,t,a)=>{const r=await fetch(n("mfaHardwareCompleteRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({device_id:e,credential:t})});if(!r.ok){const c=await r.text();let l="Failed to complete hardware key registration";try{const h=JSON.parse(c);l=h.message||h.error||c}catch{l=c||"Failed to complete hardware key registration"}throw new Error(l)}return r.json()},W=async(e,t,a="hardware")=>{const r=await fetch(n("mfaHardwareStartRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({device_name:e,device_type:a})});if(!r.ok){const c=await r.text();let l="Failed to start hardware key registration";try{const h=JSON.parse(c);l=h.message||h.error||c}catch{l=c||"Failed to start hardware key registration"}throw new Error(l)}return r.json()},Y=u.computed(()=>i.value!==null),Q=async e=>{s.value.signingIn=!0;try{y.value=!1,f.value=null,p.value=[];const t={"Content-Type":"application/json"};typeof window<"u"&&window.location&&(t.Origin=window.location.origin);const a=await fetch(n("signIn"),{method:"POST",headers:t,body:JSON.stringify(e)});if(!a.ok)throw a.status===401?new Error("Invalid email or password"):a.status===403?new Error("Please verify your email address before signing in"):new Error(`Sign in failed: ${a.status} ${a.statusText}`);const r=await a.json();if(r.mfa_required){y.value=!0,f.value=r.mfa_session_id||null;const c=(r.available_mfa_methods||[]).map(l=>{let h=`${l.device_type.charAt(0).toUpperCase()+l.device_type.slice(1)} Authentication`;return l.device_type==="hardware"?h=l.device_name||"Security Key":l.device_type==="totp"?h=l.device_name||"Authenticator App":l.device_type==="email"&&(h=l.device_name||"Email Verification"),{id:l.device_id,device_type:l.device_type,device_name:l.device_name||h,is_active:!0,created_at:new Date().toISOString(),last_used_at:l.last_used_at,credential_id:l.credential_id,device_info:l.device_info}});return p.value=c,s.value.signingIn=!1,r}return await P(r),r}catch(t){throw t}finally{s.value.signingIn=!1}},X=async e=>{s.value.signingUp=!0;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{s.value.signingUp=!1}},Z=async()=>{s.value.signingOut=!0;try{O(),$(),m=null,g(),i.value=null,o.value=null,y.value=!1,f.value=null,p.value=[],typeof window<"u"&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),typeof window<"u"&&d.value?.onSignOutUrl&&(window.location.href=d.value.onSignOutUrl)}finally{s.value.signingOut=!1}},b=async()=>{if(!o.value?.refreshToken)return!1;if(m)return await m;m=(async()=>{s.value.refreshingToken=!0;try{const t=await fetch(n("refresh"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:o.value.refreshToken})});if(!t.ok){if(t.status===401)return S(),!1;throw new Error(`Token refresh failed: ${t.status} ${t.statusText}`)}const a=await t.json();a.user&&(i.value=E(a.user),i.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value)));const r={accessToken:a.access_token,refreshToken:a.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:a.user?.id||i.value?.id};return o.value=r,typeof window<"u"&&localStorage.setItem("strands_auth_session",JSON.stringify(r)),_(),C(),x(`sessions:${o.value.accessToken.slice(0,20)}`),!0}catch{return S(),!1}finally{s.value.refreshingToken=!1}})();const e=await m;return m=null,e},ee=async()=>{const e=`profile:${o.value.accessToken.slice(0,20)}`;s.value.loadingProfile=!0;try{return await v(e,async()=>{const t=await fetch(n("profile"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value?.accessToken}`}});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Failed to fetch profile: ${t.status} ${t.statusText}`);const a=await t.json();return i.value=E(a),i.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value)),i.value})}finally{s.value.loadingProfile=!1}},te=async e=>{s.value.loadingProfile=!0;try{const t=await fetch(n("profile"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({first_name:e.firstName,last_name:e.lastName})});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Profile update failed: ${t.status} ${t.statusText}`);const a=await t.json();return i.value=E(a),i.value&&F("strands_auth_user",JSON.stringify(i.value)),i.value}finally{s.value.loadingProfile=!1}},ae=async e=>{s.value.loadingProfile=!0;try{const t=await fetch(n("settings"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({settings:e})});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Settings update failed: ${t.status} ${t.statusText}`);const a=await t.json();return i.value=E(a),i.value&&F("strands_auth_user",JSON.stringify(i.value)),i.value}finally{s.value.loadingProfile=!1}},ne=async(e,t)=>{s.value.loadingProfile=!0;try{const a=await fetch(n("changeEmail"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({new_email:e,password:t})});if(!a.ok){if(a.status===401)throw new Error("Authentication expired. Please sign in again.");{const c=await a.json().catch(()=>({}));throw new Error(c.message||`Email change failed: ${a.status} ${a.statusText}`)}}const r=await a.json();return i.value&&(i.value={...i.value,email:e,emailVerified:!1,updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value))),r}finally{s.value.loadingProfile=!1}},se=async(e,t,a=!1)=>{if(!f.value)throw new Error("No MFA session available");s.value.verifyingMfa=!0;try{const r=n(a?"mfaBackupCodeVerify":"mfaSigninVerify"),c=a?{mfa_session_id:f.value,backup_code:t}:{mfa_session_id:f.value,device_id:e,code:t},l=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!l.ok){const N=await l.text();let D="MFA verification failed";try{const J=JSON.parse(N);D=J.message||J.error||N}catch{D=N||"MFA verification failed"}throw new Error(D)}const h=await l.json();return y.value=!1,f.value=null,p.value=[],await P(h),h}finally{s.value.verifyingMfa=!1}},ie=async e=>{if(!f.value)throw new Error("No MFA session available");s.value.sendingMfaEmail=!0;try{const t=await fetch(n("mfaSigninSendEmail"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:f.value,device_id:e})});if(!t.ok){const r=await t.text();let c="Failed to send MFA email code";try{const l=JSON.parse(r);c=l.message||l.error||r}catch{c=r||"Failed to send MFA email code"}throw new Error(c)}return await t.json()}finally{s.value.sendingMfaEmail=!1}},re=async e=>{if(!f.value)throw new Error("No MFA session available");const t=await fetch(n("mfaWebAuthnChallenge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:f.value,device_id:e})});if(!t.ok){const a=await t.text();let r="Failed to get WebAuthn challenge";try{const c=JSON.parse(a);r=c.message||c.error||a}catch{r=a||r}throw new Error(r)}return t.json()},P=async e=>{try{e.user&&(i.value=E(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:i.value?.id||e.user?.id};o.value=t,typeof window<"u"&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),i.value&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value))),_(),C()}catch{}},_=()=>{if(T&&clearTimeout(T),!o.value||typeof document<"u"&&document.visibilityState==="hidden")return;const e=new Date,a=o.value.expiresAt.getTime()-e.getTime()-60*1e3;if(a<=0){b();return}T=setTimeout(async()=>{(typeof document>"u"||document.visibilityState==="visible")&&await b()&&_()},a)},O=()=>{T&&(clearTimeout(T),T=null)},C=()=>{I||typeof window>"u"||(I=setInterval(()=>{i.value&&o.value&&(localStorage.getItem("strands_auth_session")||($(),S()))},2e3))},$=()=>{I&&(clearInterval(I),I=null)},M=async()=>{if(k.value){s.value.initializing=!1;return}s.value.initializing=!0;try{if(typeof window<"u"){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");if(e&&t)try{const a=JSON.parse(e),r=JSON.parse(t);a.expiresAt=new Date(a.expiresAt),a.expiresAt<=new Date&&a.refreshToken?(o.value=a,i.value=r,await b()||S()):a.expiresAt>new Date?(o.value=a,i.value=r,_(),C()):(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}catch{localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")}}k.value=!0,await new Promise(e=>setTimeout(e,50))}catch{}finally{s.value.initializing=!1}},oe=async e=>{s.value.loadingProfile=!0;try{const t=await fetch(n("changeUsername"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({username:e})});if(!t.ok){const r=await t.json().catch(()=>({}));throw t.status===409?new Error("Username is already taken"):r.cooldown_end?new Error(`You can only change your username once every 30 days. You can change it again on ${new Date(r.cooldown_end).toLocaleDateString()}`):new Error(r.message||`Username change failed: ${t.status} ${t.statusText}`)}const a=await t.json();return i.value&&(i.value={...i.value,username:e,usernameLastChangedAt:new Date().toISOString(),updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value))),a}finally{s.value.loadingProfile=!1}},le=async()=>{const e=await fetch(n("usernameCooldown"),{method:"GET",headers:{Authorization:`Bearer ${o.value.accessToken}`}});if(!e.ok)throw new Error(`Failed to get username cooldown: ${e.status} ${e.statusText}`);return e.json()},ue=async e=>{const t=n("checkUsernameAvailability").replace("{username}",encodeURIComponent(e)),a=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok)throw new Error(`Failed to check username availability: ${a.status} ${a.statusText}`);return a.json()},ce=async()=>{const e=`sessions:${o.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await v(e,async()=>{const t=A(),a=await fetch(n("sessions"),{method:"GET",headers:t});if(!a.ok)throw await a.text(),new Error(`Failed to get user sessions: ${a.status} ${a.statusText}`);return a.json()},120*1e3)}catch(t){throw t}},de=async()=>{const e=await fetch(n("sessionsStats"),{method:"GET",headers:A()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},fe=async e=>{const t=n("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),a=await fetch(t,{method:"POST",headers:A()});if(!a.ok)throw new Error(`Failed to revoke session: ${a.status} ${a.statusText}`);return a.status===200},he=async()=>{const e=await fetch(n("sessionsRevokeAll"),{method:"POST",headers:A()});if(!e.ok)throw new Error(`Failed to revoke all other sessions: ${e.status} ${e.statusText}`);return e.status===200};typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&o.value?(_(),ge()):document.visibilityState==="hidden"&&O()}),typeof window<"u"&&window.addEventListener("storage",e=>{(e.key==="strands_auth_session"||e.key==="strands_auth_user")&&!e.newValue&&i.value&&S()});const ge=()=>{if(!(typeof window>"u")&&i.value&&o.value){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");(!e||!t)&&S()}},ve=()=>{O(),$(),g()};try{u.getCurrentInstance()&&u.onUnmounted(ve)}catch{}return k.value||M(),{user:u.computed(()=>i.value),currentUser:u.computed(()=>i.value),currentSession:u.computed(()=>o.value),isAuthenticated:Y,isLoading:u.computed(()=>K.value||!k.value),loading:j,loadingMessage:G,isInitializing:z,isSigningIn:L,isSigningUp:R,isSigningOut:U,isRefreshingToken:q,isSendingMfaEmail:B,isVerifyingMfa:V,mfaRequired:u.computed(()=>y.value),mfaSessionId:u.computed(()=>f.value),availableMfaMethods:u.computed(()=>p.value),signIn:Q,signUp:X,signOut:Z,refreshToken:b,fetchProfile:ee,updateProfile:te,updateUserSettings:ae,changeEmail:ne,changeUsername:oe,getUsernameCooldown:le,checkUsernameAvailability:ue,getUserSessions:ce,getSessionStats:de,revokeSession:fe,revokeAllOtherSessions:he,initialize:M,setAuthData:P,verifyMfa:se,sendMfaEmailCode:ie,getMfaWebAuthnChallenge:re,registerHardwareKey:W,completeHardwareKeyRegistration:H,startTokenRefreshTimer:_,stopTokenRefreshTimer:O,getAuthHeaders:A,forceReInit:()=>{k.value=!1,s.value.initializing=!0,M()}}}exports.useStrandsAuth=_e;
1
+ "use strict";const u=require("vue"),me=require("./useStrandsConfig-B5kp4aF9.cjs.js");class we{cache=new Map;DEFAULT_TTL=300*1e3;async fetch(d,v,g=this.DEFAULT_TTL){const x=Date.now(),i=this.cache.get(d);if(i&&x-i.timestamp<i.ttl)return i.promise;this.cleanExpired();const o=v().finally(()=>{setTimeout(()=>{this.cache.delete(d)},g)});return this.cache.set(d,{promise:o,timestamp:x,ttl:g}),o}clear(){this.cache.clear()}invalidate(d){this.cache.delete(d)}cleanExpired(){const d=Date.now();for(const[v,g]of this.cache.entries())d-g.timestamp>g.ttl&&this.cache.delete(v)}getStats(){return{size:this.cache.size,entries:Array.from(this.cache.keys())}}}const m=new we;function ye(){return{fetch:m.fetch.bind(m),clear:m.clear.bind(m),invalidate:m.invalidate.bind(m),getStats:m.getStats.bind(m)}}function pe(n,d){let v=null;return(...g)=>{v&&clearTimeout(v),v=setTimeout(()=>{n(...g)},d)}}const J=pe((n,d)=>{typeof window<"u"&&localStorage.setItem(n,d)},300),I=n=>({id:n.id,email:n.email,firstName:n.first_name||n.firstName||"",lastName:n.last_name||n.lastName||"",avatar:n.avatar_url||n.avatar,mfaEnabled:n.mfa_enabled??n.mfaEnabled??!1,emailVerified:n.email_verified??n.emailVerified??!1,passwordUpdatedAt:n.password_updated_at||n.passwordUpdatedAt,settings:n.settings||{},xp:n.xp||0,level:n.level||1,next_level_xp:n.next_level_xp||n.next_level_xp||4,username:n.username,usernameLastChangedAt:n.username_last_changed_at||n.usernameLastChangedAt,createdAt:n.created_at||n.createdAt,updatedAt:n.updated_at||n.updatedAt||new Date().toISOString()}),Se={currentUser:u.ref(null),currentSession:u.ref(null),loadingStates:u.ref({initializing:!0,signingIn:!1,signingUp:!1,signingOut:!1,refreshingToken:!1,sendingMfaEmail:!1,verifyingMfa:!1,loadingProfile:!1}),isInitialized:u.ref(!1),mfaRequired:u.ref(!1),mfaSessionId:u.ref(null),availableMfaMethods:u.ref([])};let k=null,w=null,E=null;function _e(){const{getUrl:n,config:d}=me.useStrandsConfig(),{fetch:v,clear:g,invalidate:x}=ye(),{currentUser:i,currentSession:o,loadingStates:s,isInitialized:y,mfaRequired:p,mfaSessionId:h,availableMfaMethods:S}=Se,_=()=>{if(i.value=null,o.value=null,p.value=!1,h.value=null,S.value=[],typeof window<"u"&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),O(),P(),w=null,g(),typeof window<"u"&&d.value?.onSignOutUrl){const e=window.location.pathname+window.location.search,t=d.value.onSignOutUrl;e!==t&&(window.location.href=t)}},F=u.computed(()=>s.value.initializing),L=u.computed(()=>s.value.signingIn),R=u.computed(()=>s.value.signingUp),U=u.computed(()=>s.value.signingOut),q=u.computed(()=>s.value.refreshingToken),B=u.computed(()=>s.value.sendingMfaEmail),V=u.computed(()=>s.value.verifyingMfa);u.computed(()=>s.value.loadingProfile);const j=u.computed(()=>s.value.signingIn||s.value.signingUp||s.value.signingOut||s.value.refreshingToken||s.value.sendingMfaEmail||s.value.verifyingMfa||s.value.loadingProfile),K=u.computed(()=>s.value.initializing||j.value),G=u.computed(()=>{const e=s.value;return e.initializing?"Checking authentication...":e.signingIn?"Signing you in...":e.signingUp?"Creating your account...":e.signingOut?"Signing you out...":e.refreshingToken?"Refreshing session...":e.sendingMfaEmail?"Sending verification code...":e.verifyingMfa?"Verifying code...":e.loadingProfile?"Loading profile...":"Loading..."}),A=()=>{const e={};return o.value?.accessToken&&(e.Authorization=`Bearer ${o.value.accessToken}`),o.value?.refreshToken&&(e["x-refresh-token"]=o.value.refreshToken),e},H=async(e,t,a)=>{const r=await fetch(n("mfaHardwareCompleteRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({device_id:e,credential:t})});if(!r.ok){const c=await r.text();let l="Failed to complete hardware key registration";try{const f=JSON.parse(c);l=f.message||f.error||c}catch{l=c||"Failed to complete hardware key registration"}throw new Error(l)}return r.json()},W=async(e,t,a="hardware")=>{const r=await fetch(n("mfaHardwareStartRegistration"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({device_name:e,device_type:a})});if(!r.ok){const c=await r.text();let l="Failed to start hardware key registration";try{const f=JSON.parse(c);l=f.message||f.error||c}catch{l=c||"Failed to start hardware key registration"}throw new Error(l)}return r.json()},Y=u.computed(()=>i.value!==null),Q=async e=>{s.value.signingIn=!0;try{p.value=!1,h.value=null,S.value=[];const t={"Content-Type":"application/json"};typeof window<"u"&&window.location&&(t.Origin=window.location.origin);const a=await fetch(n("signIn"),{method:"POST",headers:t,body:JSON.stringify(e)});if(!a.ok)throw a.status===401?new Error("Invalid email or password"):a.status===403?new Error("Please verify your email address before signing in"):new Error(`Sign in failed: ${a.status} ${a.statusText}`);const r=await a.json();if(r.mfa_required){p.value=!0,h.value=r.mfa_session_id||null;const c=(r.available_mfa_methods||[]).map(l=>{let f=`${l.device_type.charAt(0).toUpperCase()+l.device_type.slice(1)} Authentication`;return l.device_type==="hardware"?f=l.device_name||"Security Key":l.device_type==="totp"?f=l.device_name||"Authenticator App":l.device_type==="email"&&(f=l.device_name||"Email Verification"),{id:l.device_id,device_type:l.device_type,device_name:l.device_name||f,is_active:!0,created_at:new Date().toISOString(),last_used_at:l.last_used_at,credential_id:l.credential_id,device_info:l.device_info}});return S.value=c,s.value.signingIn=!1,r}return await $(r),r}catch(t){throw t}finally{s.value.signingIn=!1}},X=async e=>{s.value.signingUp=!0;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{s.value.signingUp=!1}},Z=async()=>{s.value.signingOut=!0;try{O(),P(),w=null,g(),i.value=null,o.value=null,p.value=!1,h.value=null,S.value=[],typeof window<"u"&&(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")),typeof window<"u"&&d.value?.onSignOutUrl&&(window.location.href=d.value.onSignOutUrl)}finally{s.value.signingOut=!1}},b=async()=>{if(!o.value?.refreshToken)return!1;if(w)return await w;w=(async()=>{s.value.refreshingToken=!0;try{const t=await fetch(n("refresh"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({refresh_token:o.value.refreshToken})});if(!t.ok){if(t.status===401)return _(),!1;throw new Error(`Token refresh failed: ${t.status} ${t.statusText}`)}const a=await t.json();a.user&&(i.value=I(a.user),i.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value)));const r={accessToken:a.access_token,refreshToken:a.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:a.user?.id||i.value?.id};return o.value=r,typeof window<"u"&&localStorage.setItem("strands_auth_session",JSON.stringify(r)),T(),C(),x(`sessions:${o.value.accessToken.slice(0,20)}`),!0}catch{return _(),!1}finally{s.value.refreshingToken=!1}})();const e=await w;return w=null,e},ee=async()=>{const e=`profile:${o.value.accessToken.slice(0,20)}`;s.value.loadingProfile=!0;try{return await v(e,async()=>{const t=await fetch(n("profile"),{method:"GET",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value?.accessToken}`}});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Failed to fetch profile: ${t.status} ${t.statusText}`);const a=await t.json();return i.value=I(a),i.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value)),i.value})}finally{s.value.loadingProfile=!1}},te=async e=>{s.value.loadingProfile=!0;try{const t=await fetch(n("profile"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({first_name:e.firstName,last_name:e.lastName})});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Profile update failed: ${t.status} ${t.statusText}`);const a=await t.json();return i.value=I(a),i.value&&J("strands_auth_user",JSON.stringify(i.value)),i.value}finally{s.value.loadingProfile=!1}},ae=async e=>{s.value.loadingProfile=!0;try{const t=await fetch(n("settings"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({settings:e})});if(!t.ok)throw t.status===401?new Error("Authentication expired. Please sign in again."):new Error(`Settings update failed: ${t.status} ${t.statusText}`);const a=await t.json();return i.value=I(a),i.value&&J("strands_auth_user",JSON.stringify(i.value)),i.value}finally{s.value.loadingProfile=!1}},ne=async(e,t)=>{s.value.loadingProfile=!0;try{const a=await fetch(n("changeEmail"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({new_email:e,password:t})});if(!a.ok){if(a.status===401)throw new Error("Authentication expired. Please sign in again.");{const c=await a.json().catch(()=>({}));throw new Error(c.message||`Email change failed: ${a.status} ${a.statusText}`)}}const r=await a.json();return i.value&&(i.value={...i.value,email:e,emailVerified:!1,updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value))),r}finally{s.value.loadingProfile=!1}},se=async(e,t,a=!1)=>{if(!h.value)throw new Error("No MFA session available");s.value.verifyingMfa=!0;try{const r=n(a?"mfaBackupCodeVerify":"mfaSigninVerify"),c=a?{mfa_session_id:h.value,backup_code:t}:{mfa_session_id:h.value,device_id:e,code:t},l=await fetch(r,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(c)});if(!l.ok){const N=await l.text();let D="MFA verification failed";try{const z=JSON.parse(N);D=z.message||z.error||N}catch{D=N||"MFA verification failed"}throw new Error(D)}const f=await l.json();return p.value=!1,h.value=null,S.value=[],await $(f),f}finally{s.value.verifyingMfa=!1}},ie=async e=>{if(!h.value)throw new Error("No MFA session available");s.value.sendingMfaEmail=!0;try{const t=await fetch(n("mfaSigninSendEmail"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:h.value,device_id:e})});if(!t.ok){const r=await t.text();let c="Failed to send MFA email code";try{const l=JSON.parse(r);c=l.message||l.error||r}catch{c=r||"Failed to send MFA email code"}throw new Error(c)}return await t.json()}finally{s.value.sendingMfaEmail=!1}},re=async e=>{if(!h.value)throw new Error("No MFA session available");const t=await fetch(n("mfaWebAuthnChallenge"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({mfa_session_id:h.value,device_id:e})});if(!t.ok){const a=await t.text();let r="Failed to get WebAuthn challenge";try{const c=JSON.parse(a);r=c.message||c.error||a}catch{r=a||r}throw new Error(r)}return t.json()},$=async e=>{try{e.user&&(i.value=I(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:i.value?.id||e.user?.id};o.value=t,typeof window<"u"&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),i.value&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value))),T(),C()}catch{}},T=()=>{if(k&&clearTimeout(k),!o.value||typeof document<"u"&&document.visibilityState==="hidden")return;const e=new Date,a=o.value.expiresAt.getTime()-e.getTime()-60*1e3;if(a<=0){b();return}k=setTimeout(async()=>{(typeof document>"u"||document.visibilityState==="visible")&&await b()&&T()},a)},O=()=>{k&&(clearTimeout(k),k=null)},C=()=>{E||typeof window>"u"||(E=setInterval(()=>{i.value&&o.value&&(localStorage.getItem("strands_auth_session")||(P(),_()))},2e3))},P=()=>{E&&(clearInterval(E),E=null)},M=async()=>{if(console.log("[useStrandsAuth] initialize() called, isInitialized:",y.value),y.value){console.log("[useStrandsAuth] Already initialized, setting initializing=false"),s.value.initializing=!1;return}s.value.initializing=!0,console.log("[useStrandsAuth] Starting initialization...");try{if(typeof window<"u"){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");if(e&&t)try{const a=JSON.parse(e),r=JSON.parse(t);a.expiresAt=new Date(a.expiresAt),a.expiresAt<=new Date&&a.refreshToken?(o.value=a,i.value=r,await Promise.race([b(),new Promise(f=>setTimeout(()=>f(!1),5e3))])||_()):a.expiresAt>new Date?(o.value=a,i.value=r,T(),C()):(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}catch{localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")}}y.value=!0,console.log("[useStrandsAuth] isInitialized set to true"),await new Promise(e=>setTimeout(e,50))}catch(e){console.error("[useStrandsAuth] initialization error:",e)}finally{console.log("[useStrandsAuth] finally block - setting initializing=false"),s.value.initializing=!1}},oe=async e=>{s.value.loadingProfile=!0;try{const t=await fetch(n("changeUsername"),{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${o.value.accessToken}`},body:JSON.stringify({username:e})});if(!t.ok){const r=await t.json().catch(()=>({}));throw t.status===409?new Error("Username is already taken"):r.cooldown_end?new Error(`You can only change your username once every 30 days. You can change it again on ${new Date(r.cooldown_end).toLocaleDateString()}`):new Error(r.message||`Username change failed: ${t.status} ${t.statusText}`)}const a=await t.json();return i.value&&(i.value={...i.value,username:e,usernameLastChangedAt:new Date().toISOString(),updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(i.value))),a}finally{s.value.loadingProfile=!1}},le=async()=>{const e=await fetch(n("usernameCooldown"),{method:"GET",headers:{Authorization:`Bearer ${o.value.accessToken}`}});if(!e.ok)throw new Error(`Failed to get username cooldown: ${e.status} ${e.statusText}`);return e.json()},ue=async e=>{const t=n("checkUsernameAvailability").replace("{username}",encodeURIComponent(e)),a=await fetch(t,{method:"GET",headers:{"Content-Type":"application/json"}});if(!a.ok)throw new Error(`Failed to check username availability: ${a.status} ${a.statusText}`);return a.json()},ce=async()=>{const e=`sessions:${o.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await v(e,async()=>{const t=A(),a=await fetch(n("sessions"),{method:"GET",headers:t});if(!a.ok)throw await a.text(),new Error(`Failed to get user sessions: ${a.status} ${a.statusText}`);return a.json()},120*1e3)}catch(t){throw t}},de=async()=>{const e=await fetch(n("sessionsStats"),{method:"GET",headers:A()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},fe=async e=>{const t=n("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),a=await fetch(t,{method:"POST",headers:A()});if(!a.ok)throw new Error(`Failed to revoke session: ${a.status} ${a.statusText}`);return a.status===200},he=async()=>{const e=await fetch(n("sessionsRevokeAll"),{method:"POST",headers:A()});if(!e.ok)throw new Error(`Failed to revoke all other sessions: ${e.status} ${e.statusText}`);return e.status===200};typeof document<"u"&&document.addEventListener("visibilitychange",()=>{document.visibilityState==="visible"&&o.value?(T(),ge()):document.visibilityState==="hidden"&&O()}),typeof window<"u"&&window.addEventListener("storage",e=>{(e.key==="strands_auth_session"||e.key==="strands_auth_user")&&!e.newValue&&i.value&&_()});const ge=()=>{if(!(typeof window>"u")&&i.value&&o.value){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");(!e||!t)&&_()}},ve=()=>{O(),P(),g()};try{u.getCurrentInstance()&&u.onUnmounted(ve)}catch{}return y.value||M(),{user:u.computed(()=>i.value),currentUser:u.computed(()=>i.value),currentSession:u.computed(()=>o.value),isAuthenticated:Y,isLoading:u.computed(()=>K.value||!y.value),loading:j,loadingMessage:G,isInitializing:F,isSigningIn:L,isSigningUp:R,isSigningOut:U,isRefreshingToken:q,isSendingMfaEmail:B,isVerifyingMfa:V,mfaRequired:u.computed(()=>p.value),mfaSessionId:u.computed(()=>h.value),availableMfaMethods:u.computed(()=>S.value),signIn:Q,signUp:X,signOut:Z,refreshToken:b,fetchProfile:ee,updateProfile:te,updateUserSettings:ae,changeEmail:ne,changeUsername:oe,getUsernameCooldown:le,checkUsernameAvailability:ue,getUserSessions:ce,getSessionStats:de,revokeSession:fe,revokeAllOtherSessions:he,initialize:M,setAuthData:$,verifyMfa:se,sendMfaEmailCode:ie,getMfaWebAuthnChallenge:re,registerHardwareKey:W,completeHardwareKeyRegistration:H,startTokenRefreshTimer:T,stopTokenRefreshTimer:O,getAuthHeaders:A,forceReInit:()=>{y.value=!1,s.value.initializing=!0,M()}}}exports.useStrandsAuth=_e;
@@ -70,9 +70,9 @@ function Te(n, f) {
70
70
  }, f);
71
71
  };
72
72
  }
73
- const z = Te((n, f) => {
73
+ const F = Te((n, f) => {
74
74
  typeof window < "u" && localStorage.setItem(n, f);
75
- }, 300), I = (n) => ({
75
+ }, 300), E = (n) => ({
76
76
  id: n.id,
77
77
  email: n.email,
78
78
  firstName: n.first_name || n.firstName || "",
@@ -107,18 +107,18 @@ const z = Te((n, f) => {
107
107
  mfaSessionId: m(null),
108
108
  availableMfaMethods: m([])
109
109
  };
110
- let k = null, y = null, x = null;
111
- function Ee() {
112
- const { getUrl: n, config: f } = pe(), { fetch: v, clear: g, invalidate: b } = _e(), { currentUser: i, currentSession: o, loadingStates: s, isInitialized: A, mfaRequired: p, mfaSessionId: d, availableMfaMethods: S } = ke, _ = () => {
113
- if (i.value = null, o.value = null, p.value = !1, d.value = null, S.value = [], typeof window < "u" && (localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user")), E(), P(), y = null, g(), typeof window < "u" && f.value?.onSignOutUrl) {
110
+ let A = null, y = null, x = null;
111
+ function Ie() {
112
+ const { getUrl: n, config: f } = pe(), { fetch: v, clear: g, invalidate: b } = _e(), { currentUser: i, currentSession: o, loadingStates: s, isInitialized: p, mfaRequired: S, mfaSessionId: h, availableMfaMethods: _ } = ke, T = () => {
113
+ if (i.value = null, o.value = null, S.value = !1, h.value = null, _.value = [], typeof window < "u" && (localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user")), I(), $(), y = null, g(), typeof window < "u" && f.value?.onSignOutUrl) {
114
114
  const e = window.location.pathname + window.location.search, t = f.value.onSignOutUrl;
115
115
  e !== t && (window.location.href = t);
116
116
  }
117
117
  }, L = c(() => s.value.initializing), R = c(() => s.value.signingIn), U = c(() => s.value.signingUp), B = c(() => s.value.signingOut), V = c(() => s.value.refreshingToken), q = c(() => s.value.sendingMfaEmail), K = c(() => s.value.verifyingMfa);
118
118
  c(() => s.value.loadingProfile);
119
- const J = c(
119
+ const z = c(
120
120
  () => s.value.signingIn || s.value.signingUp || s.value.signingOut || s.value.refreshingToken || s.value.sendingMfaEmail || s.value.verifyingMfa || s.value.loadingProfile
121
- ), G = c(() => s.value.initializing || J.value), H = c(() => {
121
+ ), G = c(() => s.value.initializing || z.value), H = c(() => {
122
122
  const e = s.value;
123
123
  return e.initializing ? "Checking authentication..." : e.signingIn ? "Signing you in..." : e.signingUp ? "Creating your account..." : e.signingOut ? "Signing you out..." : e.refreshingToken ? "Refreshing session..." : e.sendingMfaEmail ? "Sending verification code..." : e.verifyingMfa ? "Verifying code..." : e.loadingProfile ? "Loading profile..." : "Loading...";
124
124
  }), O = () => {
@@ -140,8 +140,8 @@ function Ee() {
140
140
  const u = await r.text();
141
141
  let l = "Failed to complete hardware key registration";
142
142
  try {
143
- const h = JSON.parse(u);
144
- l = h.message || h.error || u;
143
+ const d = JSON.parse(u);
144
+ l = d.message || d.error || u;
145
145
  } catch {
146
146
  l = u || "Failed to complete hardware key registration";
147
147
  }
@@ -164,8 +164,8 @@ function Ee() {
164
164
  const u = await r.text();
165
165
  let l = "Failed to start hardware key registration";
166
166
  try {
167
- const h = JSON.parse(u);
168
- l = h.message || h.error || u;
167
+ const d = JSON.parse(u);
168
+ l = d.message || d.error || u;
169
169
  } catch {
170
170
  l = u || "Failed to start hardware key registration";
171
171
  }
@@ -175,7 +175,7 @@ function Ee() {
175
175
  }, Q = c(() => i.value !== null), X = async (e) => {
176
176
  s.value.signingIn = !0;
177
177
  try {
178
- p.value = !1, d.value = null, S.value = [];
178
+ S.value = !1, h.value = null, _.value = [];
179
179
  const t = {
180
180
  "Content-Type": "application/json"
181
181
  };
@@ -189,13 +189,13 @@ function Ee() {
189
189
  throw a.status === 401 ? new Error("Invalid email or password") : a.status === 403 ? new Error("Please verify your email address before signing in") : new Error(`Sign in failed: ${a.status} ${a.statusText}`);
190
190
  const r = await a.json();
191
191
  if (r.mfa_required) {
192
- p.value = !0, d.value = r.mfa_session_id || null;
192
+ S.value = !0, h.value = r.mfa_session_id || null;
193
193
  const u = (r.available_mfa_methods || []).map((l) => {
194
- let h = `${l.device_type.charAt(0).toUpperCase() + l.device_type.slice(1)} Authentication`;
195
- return l.device_type === "hardware" ? h = l.device_name || "Security Key" : l.device_type === "totp" ? h = l.device_name || "Authenticator App" : l.device_type === "email" && (h = l.device_name || "Email Verification"), {
194
+ let d = `${l.device_type.charAt(0).toUpperCase() + l.device_type.slice(1)} Authentication`;
195
+ return l.device_type === "hardware" ? d = l.device_name || "Security Key" : l.device_type === "totp" ? d = l.device_name || "Authenticator App" : l.device_type === "email" && (d = l.device_name || "Email Verification"), {
196
196
  id: l.device_id,
197
197
  device_type: l.device_type,
198
- device_name: l.device_name || h,
198
+ device_name: l.device_name || d,
199
199
  is_active: !0,
200
200
  created_at: (/* @__PURE__ */ new Date()).toISOString(),
201
201
  last_used_at: l.last_used_at,
@@ -204,7 +204,7 @@ function Ee() {
204
204
  device_info: l.device_info
205
205
  };
206
206
  });
207
- return S.value = u, s.value.signingIn = !1, r;
207
+ return _.value = u, s.value.signingIn = !1, r;
208
208
  }
209
209
  return await M(r), r;
210
210
  } catch (t) {
@@ -222,11 +222,11 @@ function Ee() {
222
222
  }, ee = async () => {
223
223
  s.value.signingOut = !0;
224
224
  try {
225
- E(), P(), y = null, g(), i.value = null, o.value = null, p.value = !1, d.value = null, S.value = [], typeof window < "u" && (localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user")), typeof window < "u" && f.value?.onSignOutUrl && (window.location.href = f.value.onSignOutUrl);
225
+ I(), $(), y = null, g(), i.value = null, o.value = null, S.value = !1, h.value = null, _.value = [], typeof window < "u" && (localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user")), typeof window < "u" && f.value?.onSignOutUrl && (window.location.href = f.value.onSignOutUrl);
226
226
  } finally {
227
227
  s.value.signingOut = !1;
228
228
  }
229
- }, $ = async () => {
229
+ }, P = async () => {
230
230
  if (!o.value?.refreshToken)
231
231
  return !1;
232
232
  if (y)
@@ -245,11 +245,11 @@ function Ee() {
245
245
  });
246
246
  if (!t.ok) {
247
247
  if (t.status === 401)
248
- return _(), !1;
248
+ return T(), !1;
249
249
  throw new Error(`Token refresh failed: ${t.status} ${t.statusText}`);
250
250
  }
251
251
  const a = await t.json();
252
- a.user && (i.value = I(a.user), i.value && typeof window < "u" && localStorage.setItem("strands_auth_user", JSON.stringify(i.value)));
252
+ a.user && (i.value = E(a.user), i.value && typeof window < "u" && localStorage.setItem("strands_auth_user", JSON.stringify(i.value)));
253
253
  const r = {
254
254
  accessToken: a.access_token,
255
255
  refreshToken: a.refresh_token,
@@ -257,9 +257,9 @@ function Ee() {
257
257
  // 5 minutes from now
258
258
  userId: a.user?.id || i.value?.id
259
259
  };
260
- return o.value = r, typeof window < "u" && localStorage.setItem("strands_auth_session", JSON.stringify(r)), T(), N(), b(`sessions:${o.value.accessToken.slice(0, 20)}`), !0;
260
+ return o.value = r, typeof window < "u" && localStorage.setItem("strands_auth_session", JSON.stringify(r)), k(), N(), b(`sessions:${o.value.accessToken.slice(0, 20)}`), !0;
261
261
  } catch {
262
- return _(), !1;
262
+ return T(), !1;
263
263
  } finally {
264
264
  s.value.refreshingToken = !1;
265
265
  }
@@ -281,7 +281,7 @@ function Ee() {
281
281
  if (!t.ok)
282
282
  throw t.status === 401 ? new Error("Authentication expired. Please sign in again.") : new Error(`Failed to fetch profile: ${t.status} ${t.statusText}`);
283
283
  const a = await t.json();
284
- return i.value = I(a), i.value && typeof window < "u" && localStorage.setItem("strands_auth_user", JSON.stringify(i.value)), i.value;
284
+ return i.value = E(a), i.value && typeof window < "u" && localStorage.setItem("strands_auth_user", JSON.stringify(i.value)), i.value;
285
285
  });
286
286
  } finally {
287
287
  s.value.loadingProfile = !1;
@@ -303,7 +303,7 @@ function Ee() {
303
303
  if (!t.ok)
304
304
  throw t.status === 401 ? new Error("Authentication expired. Please sign in again.") : new Error(`Profile update failed: ${t.status} ${t.statusText}`);
305
305
  const a = await t.json();
306
- return i.value = I(a), i.value && z("strands_auth_user", JSON.stringify(i.value)), i.value;
306
+ return i.value = E(a), i.value && F("strands_auth_user", JSON.stringify(i.value)), i.value;
307
307
  } finally {
308
308
  s.value.loadingProfile = !1;
309
309
  }
@@ -323,7 +323,7 @@ function Ee() {
323
323
  if (!t.ok)
324
324
  throw t.status === 401 ? new Error("Authentication expired. Please sign in again.") : new Error(`Settings update failed: ${t.status} ${t.statusText}`);
325
325
  const a = await t.json();
326
- return i.value = I(a), i.value && z("strands_auth_user", JSON.stringify(i.value)), i.value;
326
+ return i.value = E(a), i.value && F("strands_auth_user", JSON.stringify(i.value)), i.value;
327
327
  } finally {
328
328
  s.value.loadingProfile = !1;
329
329
  }
@@ -361,11 +361,11 @@ function Ee() {
361
361
  s.value.loadingProfile = !1;
362
362
  }
363
363
  }, ie = async (e, t, a = !1) => {
364
- if (!d.value)
364
+ if (!h.value)
365
365
  throw new Error("No MFA session available");
366
366
  s.value.verifyingMfa = !0;
367
367
  try {
368
- const r = n(a ? "mfaBackupCodeVerify" : "mfaSigninVerify"), u = a ? { mfa_session_id: d.value, backup_code: t } : { mfa_session_id: d.value, device_id: e, code: t }, l = await fetch(r, {
368
+ const r = n(a ? "mfaBackupCodeVerify" : "mfaSigninVerify"), u = a ? { mfa_session_id: h.value, backup_code: t } : { mfa_session_id: h.value, device_id: e, code: t }, l = await fetch(r, {
369
369
  method: "POST",
370
370
  headers: { "Content-Type": "application/json" },
371
371
  body: JSON.stringify(u)
@@ -374,20 +374,20 @@ function Ee() {
374
374
  const D = await l.text();
375
375
  let j = "MFA verification failed";
376
376
  try {
377
- const F = JSON.parse(D);
378
- j = F.message || F.error || D;
377
+ const J = JSON.parse(D);
378
+ j = J.message || J.error || D;
379
379
  } catch {
380
380
  j = D || "MFA verification failed";
381
381
  }
382
382
  throw new Error(j);
383
383
  }
384
- const h = await l.json();
385
- return p.value = !1, d.value = null, S.value = [], await M(h), h;
384
+ const d = await l.json();
385
+ return S.value = !1, h.value = null, _.value = [], await M(d), d;
386
386
  } finally {
387
387
  s.value.verifyingMfa = !1;
388
388
  }
389
389
  }, re = async (e) => {
390
- if (!d.value)
390
+ if (!h.value)
391
391
  throw new Error("No MFA session available");
392
392
  s.value.sendingMfaEmail = !0;
393
393
  try {
@@ -395,7 +395,7 @@ function Ee() {
395
395
  method: "POST",
396
396
  headers: { "Content-Type": "application/json" },
397
397
  body: JSON.stringify({
398
- mfa_session_id: d.value,
398
+ mfa_session_id: h.value,
399
399
  device_id: e
400
400
  })
401
401
  });
@@ -415,13 +415,13 @@ function Ee() {
415
415
  s.value.sendingMfaEmail = !1;
416
416
  }
417
417
  }, oe = async (e) => {
418
- if (!d.value)
418
+ if (!h.value)
419
419
  throw new Error("No MFA session available");
420
420
  const t = await fetch(n("mfaWebAuthnChallenge"), {
421
421
  method: "POST",
422
422
  headers: { "Content-Type": "application/json" },
423
423
  body: JSON.stringify({
424
- mfa_session_id: d.value,
424
+ mfa_session_id: h.value,
425
425
  device_id: e
426
426
  })
427
427
  });
@@ -439,7 +439,7 @@ function Ee() {
439
439
  return t.json();
440
440
  }, M = async (e) => {
441
441
  try {
442
- e.user && (i.value = I(e.user));
442
+ e.user && (i.value = E(e.user));
443
443
  const t = {
444
444
  accessToken: e.access_token,
445
445
  refreshToken: e.refresh_token,
@@ -447,49 +447,53 @@ function Ee() {
447
447
  // 5 minutes from now (matching API token expiry)
448
448
  userId: i.value?.id || e.user?.id
449
449
  };
450
- o.value = t, typeof window < "u" && (localStorage.setItem("strands_auth_session", JSON.stringify(t)), i.value && localStorage.setItem("strands_auth_user", JSON.stringify(i.value))), T(), N();
450
+ o.value = t, typeof window < "u" && (localStorage.setItem("strands_auth_session", JSON.stringify(t)), i.value && localStorage.setItem("strands_auth_user", JSON.stringify(i.value))), k(), N();
451
451
  } catch {
452
452
  }
453
- }, T = () => {
454
- if (k && clearTimeout(k), !o.value || typeof document < "u" && document.visibilityState === "hidden")
453
+ }, k = () => {
454
+ if (A && clearTimeout(A), !o.value || typeof document < "u" && document.visibilityState === "hidden")
455
455
  return;
456
456
  const e = /* @__PURE__ */ new Date(), a = o.value.expiresAt.getTime() - e.getTime() - 60 * 1e3;
457
457
  if (a <= 0) {
458
- $();
458
+ P();
459
459
  return;
460
460
  }
461
- k = setTimeout(async () => {
462
- (typeof document > "u" || document.visibilityState === "visible") && await $() && T();
461
+ A = setTimeout(async () => {
462
+ (typeof document > "u" || document.visibilityState === "visible") && await P() && k();
463
463
  }, a);
464
- }, E = () => {
465
- k && (clearTimeout(k), k = null);
464
+ }, I = () => {
465
+ A && (clearTimeout(A), A = null);
466
466
  }, N = () => {
467
467
  x || typeof window > "u" || (x = setInterval(() => {
468
- i.value && o.value && (localStorage.getItem("strands_auth_session") || (P(), _()));
468
+ i.value && o.value && (localStorage.getItem("strands_auth_session") || ($(), T()));
469
469
  }, 2e3));
470
- }, P = () => {
470
+ }, $ = () => {
471
471
  x && (clearInterval(x), x = null);
472
472
  }, C = async () => {
473
- if (A.value) {
474
- s.value.initializing = !1;
473
+ if (console.log("[useStrandsAuth] initialize() called, isInitialized:", p.value), p.value) {
474
+ console.log("[useStrandsAuth] Already initialized, setting initializing=false"), s.value.initializing = !1;
475
475
  return;
476
476
  }
477
- s.value.initializing = !0;
477
+ s.value.initializing = !0, console.log("[useStrandsAuth] Starting initialization...");
478
478
  try {
479
479
  if (typeof window < "u") {
480
480
  const e = localStorage.getItem("strands_auth_session"), t = localStorage.getItem("strands_auth_user");
481
481
  if (e && t)
482
482
  try {
483
483
  const a = JSON.parse(e), r = JSON.parse(t);
484
- a.expiresAt = new Date(a.expiresAt), a.expiresAt <= /* @__PURE__ */ new Date() && a.refreshToken ? (o.value = a, i.value = r, await $() || _()) : a.expiresAt > /* @__PURE__ */ new Date() ? (o.value = a, i.value = r, T(), N()) : (localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user"));
484
+ a.expiresAt = new Date(a.expiresAt), a.expiresAt <= /* @__PURE__ */ new Date() && a.refreshToken ? (o.value = a, i.value = r, await Promise.race([
485
+ P(),
486
+ new Promise((d) => setTimeout(() => d(!1), 5e3))
487
+ ]) || T()) : a.expiresAt > /* @__PURE__ */ new Date() ? (o.value = a, i.value = r, k(), N()) : (localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user"));
485
488
  } catch {
486
489
  localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user");
487
490
  }
488
491
  }
489
- A.value = !0, await new Promise((e) => setTimeout(e, 50));
490
- } catch {
492
+ p.value = !0, console.log("[useStrandsAuth] isInitialized set to true"), await new Promise((e) => setTimeout(e, 50));
493
+ } catch (e) {
494
+ console.error("[useStrandsAuth] initialization error:", e);
491
495
  } finally {
492
- s.value.initializing = !1;
496
+ console.log("[useStrandsAuth] finally block - setting initializing=false"), s.value.initializing = !1;
493
497
  }
494
498
  }, le = async (e) => {
495
499
  s.value.loadingProfile = !0;
@@ -579,30 +583,30 @@ function Ee() {
579
583
  return e.status === 200;
580
584
  };
581
585
  typeof document < "u" && document.addEventListener("visibilitychange", () => {
582
- document.visibilityState === "visible" && o.value ? (T(), ve()) : document.visibilityState === "hidden" && E();
586
+ document.visibilityState === "visible" && o.value ? (k(), ve()) : document.visibilityState === "hidden" && I();
583
587
  }), typeof window < "u" && window.addEventListener("storage", (e) => {
584
- (e.key === "strands_auth_session" || e.key === "strands_auth_user") && !e.newValue && i.value && _();
588
+ (e.key === "strands_auth_session" || e.key === "strands_auth_user") && !e.newValue && i.value && T();
585
589
  });
586
590
  const ve = () => {
587
591
  if (!(typeof window > "u") && i.value && o.value) {
588
592
  const e = localStorage.getItem("strands_auth_session"), t = localStorage.getItem("strands_auth_user");
589
- (!e || !t) && _();
593
+ (!e || !t) && T();
590
594
  }
591
595
  }, we = () => {
592
- E(), P(), g();
596
+ I(), $(), g();
593
597
  };
594
598
  try {
595
599
  me() && ye(we);
596
600
  } catch {
597
601
  }
598
- return A.value || C(), {
602
+ return p.value || C(), {
599
603
  // State
600
604
  user: c(() => i.value),
601
605
  currentUser: c(() => i.value),
602
606
  currentSession: c(() => o.value),
603
607
  isAuthenticated: Q,
604
- isLoading: c(() => G.value || !A.value),
605
- loading: J,
608
+ isLoading: c(() => G.value || !p.value),
609
+ loading: z,
606
610
  loadingMessage: H,
607
611
  // Specific loading states
608
612
  isInitializing: L,
@@ -613,14 +617,14 @@ function Ee() {
613
617
  isSendingMfaEmail: q,
614
618
  isVerifyingMfa: K,
615
619
  // MFA State
616
- mfaRequired: c(() => p.value),
617
- mfaSessionId: c(() => d.value),
618
- availableMfaMethods: c(() => S.value),
620
+ mfaRequired: c(() => S.value),
621
+ mfaSessionId: c(() => h.value),
622
+ availableMfaMethods: c(() => _.value),
619
623
  // Methods
620
624
  signIn: X,
621
625
  signUp: Z,
622
626
  signOut: ee,
623
- refreshToken: $,
627
+ refreshToken: P,
624
628
  fetchProfile: te,
625
629
  updateProfile: ae,
626
630
  updateUserSettings: ne,
@@ -641,15 +645,15 @@ function Ee() {
641
645
  registerHardwareKey: Y,
642
646
  completeHardwareKeyRegistration: W,
643
647
  // Token management
644
- startTokenRefreshTimer: T,
645
- stopTokenRefreshTimer: E,
648
+ startTokenRefreshTimer: k,
649
+ stopTokenRefreshTimer: I,
646
650
  getAuthHeaders: O,
647
651
  // Force re-initialization (useful for testing or navigation)
648
652
  forceReInit: () => {
649
- A.value = !1, s.value.initializing = !0, C();
653
+ p.value = !1, s.value.initializing = !0, C();
650
654
  }
651
655
  };
652
656
  }
653
657
  export {
654
- Ee as u
658
+ Ie as u
655
659
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strands.gg/accui",
3
- "version": "2.17.12",
3
+ "version": "2.17.14",
4
4
  "description": "Strands Authentication UI Components",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs.js",