@strands.gg/accui 2.17.22 → 2.17.24
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.
- package/dist/accui.css +1 -1
- package/dist/index.cjs.js +5 -5
- package/dist/index.es.js +1292 -1293
- package/dist/nuxt/runtime/composables/useStrandsAuth.cjs.js +1 -1
- package/dist/nuxt/runtime/composables/useStrandsAuth.d.ts +1 -0
- package/dist/nuxt/runtime/composables/useStrandsAuth.es.js +1 -1
- package/dist/types/composables.d.ts +1 -0
- package/dist/{useStrandsAuth-Dhcd1aWs.cjs.js → useStrandsAuth-CTh6ELtc.cjs.js} +1 -1
- package/dist/{useStrandsAuth-CX9dSRKi.es.js → useStrandsAuth-mv5zJr7L.es.js} +29 -28
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("nuxt/app"),a=require("../../../useStrandsAuth-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("nuxt/app"),a=require("../../../useStrandsAuth-CTh6ELtc.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;
|
|
@@ -18,6 +18,7 @@ export declare const useStrandsAuth: () => {
|
|
|
18
18
|
loading: ComputedRef<boolean>;
|
|
19
19
|
loadingMessage: ComputedRef<string>;
|
|
20
20
|
isInitializing: ComputedRef<boolean>;
|
|
21
|
+
isInitialized: ComputedRef<boolean>;
|
|
21
22
|
isSigningIn: ComputedRef<boolean>;
|
|
22
23
|
isSigningUp: ComputedRef<boolean>;
|
|
23
24
|
isSigningOut: ComputedRef<boolean>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useRuntimeConfig as e, navigateTo as a } from "nuxt/app";
|
|
2
|
-
import { u as r } from "../../../useStrandsAuth-
|
|
2
|
+
import { u as r } from "../../../useStrandsAuth-mv5zJr7L.es.js";
|
|
3
3
|
const u = () => {
|
|
4
4
|
const n = e().public.strandsAuth, t = r();
|
|
5
5
|
return {
|
|
@@ -9,6 +9,7 @@ export interface UseStrandsAuthReturn {
|
|
|
9
9
|
loading: ComputedRef<boolean>;
|
|
10
10
|
loadingMessage: ComputedRef<string>;
|
|
11
11
|
isInitializing: ComputedRef<boolean>;
|
|
12
|
+
isInitialized: ComputedRef<boolean>;
|
|
12
13
|
isSigningIn: ComputedRef<boolean>;
|
|
13
14
|
isSigningUp: ComputedRef<boolean>;
|
|
14
15
|
isSigningOut: ComputedRef<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const u=require("vue"),we=require("./useStrandsConfig-B5kp4aF9.cjs.js");class ye{cache=new Map;DEFAULT_TTL=300*1e3;async fetch(d,v,g=this.DEFAULT_TTL){const b=Date.now(),s=this.cache.get(d);if(s&&b-s.timestamp<s.ttl)return s.promise;this.cleanExpired();const o=v().finally(()=>{setTimeout(()=>{this.cache.delete(d)},g)});return this.cache.set(d,{promise:o,timestamp:b,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 ye;function pe(){return{fetch:m.fetch.bind(m),clear:m.clear.bind(m),invalidate:m.invalidate.bind(m),getStats:m.getStats.bind(m)}}function Se(n,d){let v=null;return(...g)=>{v&&clearTimeout(v),v=setTimeout(()=>{n(...g)},d)}}const F=Se((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()}),_e={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,x=null,A=null;function Te(){const{getUrl:n,config:d}=we.useStrandsConfig(),{fetch:v,clear:g,invalidate:b}=pe(),{currentUser:s,currentSession:o,loadingStates:i,isInitialized:y,mfaRequired:p,mfaSessionId:h,availableMfaMethods:S}=_e,_=()=>{if(s.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")),I(),$(),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)}},L=u.computed(()=>i.value.initializing),U=u.computed(()=>i.value.signingIn),R=u.computed(()=>i.value.signingUp),q=u.computed(()=>i.value.signingOut),B=u.computed(()=>i.value.refreshingToken),V=u.computed(()=>i.value.sendingMfaEmail),K=u.computed(()=>i.value.verifyingMfa);u.computed(()=>i.value.loadingProfile);const j=u.computed(()=>i.value.signingIn||i.value.signingUp||i.value.signingOut||i.value.refreshingToken||i.value.sendingMfaEmail||i.value.verifyingMfa||i.value.loadingProfile),W=u.computed(()=>i.value.initializing||j.value),G=u.computed(()=>{const e=i.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..."}),O=()=>{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()},Y=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()},Q=u.computed(()=>s.value!==null),X=async e=>{i.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,i.value.signingIn=!1,r}return await C(r),r}catch(t){throw t}finally{i.value.signingIn=!1}},Z=async e=>{i.value.signingUp=!0;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{i.value.signingUp=!1}},ee=async()=>{i.value.signingOut=!0;try{I(),$(),w=null,g(),s.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{i.value.signingOut=!1}},P=async()=>{if(!o.value?.refreshToken)return!1;if(w)return await w;w=(async()=>{i.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&&(s.value=E(a.user),s.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value)));const r={accessToken:a.access_token,refreshToken:a.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:a.user?.id||s.value?.id};return o.value=r,typeof window<"u"&&localStorage.setItem("strands_auth_session",JSON.stringify(r)),T(),M(),b(`sessions:${o.value.accessToken.slice(0,20)}`),!0}catch{return _(),!1}finally{i.value.refreshingToken=!1}})();const e=await w;return w=null,e},te=async()=>{const e=`profile:${o.value.accessToken.slice(0,20)}`;i.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 s.value=E(a),s.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value)),s.value})}finally{i.value.loadingProfile=!1}},ae=async e=>{i.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 s.value=E(a),s.value&&F("strands_auth_user",JSON.stringify(s.value)),s.value}finally{i.value.loadingProfile=!1}},ne=async e=>{i.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 s.value=E(a),s.value&&F("strands_auth_user",JSON.stringify(s.value)),s.value}finally{i.value.loadingProfile=!1}},se=async(e,t)=>{i.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 s.value&&(s.value={...s.value,email:e,emailVerified:!1,updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),r}finally{i.value.loadingProfile=!1}},ie=async(e,t,a=!1)=>{if(!h.value)throw new Error("No MFA session available");i.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 D=await l.text();let z="MFA verification failed";try{const J=JSON.parse(D);z=J.message||J.error||D}catch{z=D||"MFA verification failed"}throw new Error(z)}const f=await l.json();return p.value=!1,h.value=null,S.value=[],await C(f),f}finally{i.value.verifyingMfa=!1}},re=async e=>{if(!h.value)throw new Error("No MFA session available");i.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{i.value.sendingMfaEmail=!1}},oe=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()},C=async e=>{try{e.user&&(s.value=E(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:s.value?.id||e.user?.id};o.value=t,typeof window<"u"&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),s.value&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),T(),M()}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){P();return}k=setTimeout(async()=>{(typeof document>"u"||document.visibilityState==="visible")&&await P()&&T()},a)},I=()=>{k&&(clearTimeout(k),k=null)},M=()=>{x||typeof window>"u"||(x=setInterval(()=>{s.value&&o.value&&(localStorage.getItem("strands_auth_session")||($(),_()))},2e3))},$=()=>{x&&(clearInterval(x),x=null)},N=async()=>{if(console.log("[useStrandsAuth] initialize() called, isInitialized:",y.value,"hasPromise:",!!A),y.value){console.log("[useStrandsAuth] Already initialized, setting initializing=false"),i.value.initializing=!1;return}return A?(console.log("[useStrandsAuth] Waiting for existing initialization..."),A):(console.log("[useStrandsAuth] Starting new initialization..."),A=(async()=>{i.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,s.value=r,await Promise.race([P(),new Promise(f=>setTimeout(()=>f(!1),5e3))])||_()):a.expiresAt>new Date?(o.value=a,s.value=r,T(),M()):(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, currentUser:",!!s.value),await new Promise(e=>setTimeout(e,50))}catch(e){console.error("[useStrandsAuth] initialization error:",e)}finally{console.log("[useStrandsAuth] finally - setting initializing=false"),i.value.initializing=!1,A=null}})(),A)},le=async e=>{i.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 s.value&&(s.value={...s.value,username:e,usernameLastChangedAt:new Date().toISOString(),updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),a}finally{i.value.loadingProfile=!1}},ue=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()},ce=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()},de=async()=>{const e=`sessions:${o.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await v(e,async()=>{const t=O(),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}},fe=async()=>{const e=await fetch(n("sessionsStats"),{method:"GET",headers:O()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},he=async e=>{const t=n("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),a=await fetch(t,{method:"POST",headers:O()});if(!a.ok)throw new Error(`Failed to revoke session: ${a.status} ${a.statusText}`);return a.status===200},ge=async()=>{const e=await fetch(n("sessionsRevokeAll"),{method:"POST",headers:O()});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(),ve()):document.visibilityState==="hidden"&&I()}),typeof window<"u"&&window.addEventListener("storage",e=>{(e.key==="strands_auth_session"||e.key==="strands_auth_user")&&!e.newValue&&s.value&&_()});const ve=()=>{if(!(typeof window>"u")&&s.value&&o.value){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");(!e||!t)&&_()}},me=()=>{I(),$(),g()};try{u.getCurrentInstance()&&u.onUnmounted(me)}catch{}return y.value||N(),{user:u.computed(()=>s.value),currentUser:u.computed(()=>s.value),currentSession:u.computed(()=>o.value),isAuthenticated:Q,isLoading:u.computed(()=>W.value||!y.value),loading:j,loadingMessage:G,isInitializing:L,isSigningIn:U,isSigningUp:R,isSigningOut:q,isRefreshingToken:B,isSendingMfaEmail:V,isVerifyingMfa:K,mfaRequired:u.computed(()=>p.value),mfaSessionId:u.computed(()=>h.value),availableMfaMethods:u.computed(()=>S.value),signIn:X,signUp:Z,signOut:ee,refreshToken:P,fetchProfile:te,updateProfile:ae,updateUserSettings:ne,changeEmail:se,changeUsername:le,getUsernameCooldown:ue,checkUsernameAvailability:ce,getUserSessions:de,getSessionStats:fe,revokeSession:he,revokeAllOtherSessions:ge,initialize:N,setAuthData:C,verifyMfa:ie,sendMfaEmailCode:re,getMfaWebAuthnChallenge:oe,registerHardwareKey:Y,completeHardwareKeyRegistration:H,startTokenRefreshTimer:T,stopTokenRefreshTimer:I,getAuthHeaders:O,forceReInit:()=>{y.value=!1,i.value.initializing=!0,N()}}}exports.useStrandsAuth=Te;
|
|
1
|
+
"use strict";const u=require("vue"),we=require("./useStrandsConfig-B5kp4aF9.cjs.js");class ye{cache=new Map;DEFAULT_TTL=300*1e3;async fetch(d,v,g=this.DEFAULT_TTL){const b=Date.now(),s=this.cache.get(d);if(s&&b-s.timestamp<s.ttl)return s.promise;this.cleanExpired();const o=v().finally(()=>{setTimeout(()=>{this.cache.delete(d)},g)});return this.cache.set(d,{promise:o,timestamp:b,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 ye;function pe(){return{fetch:m.fetch.bind(m),clear:m.clear.bind(m),invalidate:m.invalidate.bind(m),getStats:m.getStats.bind(m)}}function Se(n,d){let v=null;return(...g)=>{v&&clearTimeout(v),v=setTimeout(()=>{n(...g)},d)}}const F=Se((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()}),_e={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,y=null,x=null,A=null;function Te(){const{getUrl:n,config:d}=we.useStrandsConfig(),{fetch:v,clear:g,invalidate:b}=pe(),{currentUser:s,currentSession:o,loadingStates:i,isInitialized:w,mfaRequired:p,mfaSessionId:h,availableMfaMethods:S}=_e,_=()=>{if(s.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")),I(),$(),y=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)}},L=u.computed(()=>i.value.initializing),U=u.computed(()=>i.value.signingIn),R=u.computed(()=>i.value.signingUp),q=u.computed(()=>i.value.signingOut),B=u.computed(()=>i.value.refreshingToken),V=u.computed(()=>i.value.sendingMfaEmail),K=u.computed(()=>i.value.verifyingMfa);u.computed(()=>i.value.loadingProfile);const j=u.computed(()=>i.value.signingIn||i.value.signingUp||i.value.signingOut||i.value.refreshingToken||i.value.sendingMfaEmail||i.value.verifyingMfa||i.value.loadingProfile),W=u.computed(()=>i.value.initializing||j.value),G=u.computed(()=>{const e=i.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..."}),O=()=>{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()},Y=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()},Q=u.computed(()=>s.value!==null),X=async e=>{i.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,i.value.signingIn=!1,r}return await C(r),r}catch(t){throw t}finally{i.value.signingIn=!1}},Z=async e=>{i.value.signingUp=!0;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{i.value.signingUp=!1}},ee=async()=>{i.value.signingOut=!0;try{I(),$(),y=null,g(),s.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{i.value.signingOut=!1}},P=async()=>{if(!o.value?.refreshToken)return!1;if(y)return await y;y=(async()=>{i.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&&(s.value=E(a.user),s.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value)));const r={accessToken:a.access_token,refreshToken:a.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:a.user?.id||s.value?.id};return o.value=r,typeof window<"u"&&localStorage.setItem("strands_auth_session",JSON.stringify(r)),T(),M(),b(`sessions:${o.value.accessToken.slice(0,20)}`),!0}catch{return _(),!1}finally{i.value.refreshingToken=!1}})();const e=await y;return y=null,e},te=async()=>{const e=`profile:${o.value.accessToken.slice(0,20)}`;i.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 s.value=E(a),s.value&&typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value)),s.value})}finally{i.value.loadingProfile=!1}},ae=async e=>{i.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 s.value=E(a),s.value&&F("strands_auth_user",JSON.stringify(s.value)),s.value}finally{i.value.loadingProfile=!1}},ne=async e=>{i.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 s.value=E(a),s.value&&F("strands_auth_user",JSON.stringify(s.value)),s.value}finally{i.value.loadingProfile=!1}},se=async(e,t)=>{i.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 s.value&&(s.value={...s.value,email:e,emailVerified:!1,updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),r}finally{i.value.loadingProfile=!1}},ie=async(e,t,a=!1)=>{if(!h.value)throw new Error("No MFA session available");i.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 z=await l.text();let D="MFA verification failed";try{const J=JSON.parse(z);D=J.message||J.error||z}catch{D=z||"MFA verification failed"}throw new Error(D)}const f=await l.json();return p.value=!1,h.value=null,S.value=[],await C(f),f}finally{i.value.verifyingMfa=!1}},re=async e=>{if(!h.value)throw new Error("No MFA session available");i.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{i.value.sendingMfaEmail=!1}},oe=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()},C=async e=>{try{e.user&&(s.value=E(e.user));const t={accessToken:e.access_token,refreshToken:e.refresh_token,expiresAt:new Date(Date.now()+300*1e3),userId:s.value?.id||e.user?.id};o.value=t,typeof window<"u"&&(localStorage.setItem("strands_auth_session",JSON.stringify(t)),s.value&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),T(),M()}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){P();return}k=setTimeout(async()=>{(typeof document>"u"||document.visibilityState==="visible")&&await P()&&T()},a)},I=()=>{k&&(clearTimeout(k),k=null)},M=()=>{x||typeof window>"u"||(x=setInterval(()=>{s.value&&o.value&&(localStorage.getItem("strands_auth_session")||($(),_()))},2e3))},$=()=>{x&&(clearInterval(x),x=null)},N=async()=>{if(console.log("[useStrandsAuth] initialize() called, isInitialized:",w.value,"hasPromise:",!!A),w.value){console.log("[useStrandsAuth] Already initialized, setting initializing=false"),i.value.initializing=!1;return}return A?(console.log("[useStrandsAuth] Waiting for existing initialization..."),A):(console.log("[useStrandsAuth] Starting new initialization..."),A=(async()=>{i.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,s.value=r,await Promise.race([P(),new Promise(f=>setTimeout(()=>f(!1),5e3))])||_()):a.expiresAt>new Date?(o.value=a,s.value=r,T(),M()):(localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user"))}catch{localStorage.removeItem("strands_auth_session"),localStorage.removeItem("strands_auth_user")}}w.value=!0,console.log("[useStrandsAuth] isInitialized set to true, currentUser:",!!s.value),await new Promise(e=>setTimeout(e,50))}catch(e){console.error("[useStrandsAuth] initialization error:",e)}finally{console.log("[useStrandsAuth] finally - setting initializing=false"),i.value.initializing=!1,A=null}})(),A)},le=async e=>{i.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 s.value&&(s.value={...s.value,username:e,usernameLastChangedAt:new Date().toISOString(),updatedAt:new Date().toISOString()},typeof window<"u"&&localStorage.setItem("strands_auth_user",JSON.stringify(s.value))),a}finally{i.value.loadingProfile=!1}},ue=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()},ce=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()},de=async()=>{const e=`sessions:${o.value?.accessToken?.slice(0,20)||"no-token"}`;try{return await v(e,async()=>{const t=O(),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}},fe=async()=>{const e=await fetch(n("sessionsStats"),{method:"GET",headers:O()});if(!e.ok)throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);return e.json()},he=async e=>{const t=n("sessionRevoke").replace("{session_id}",encodeURIComponent(e)),a=await fetch(t,{method:"POST",headers:O()});if(!a.ok)throw new Error(`Failed to revoke session: ${a.status} ${a.statusText}`);return a.status===200},ge=async()=>{const e=await fetch(n("sessionsRevokeAll"),{method:"POST",headers:O()});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(),ve()):document.visibilityState==="hidden"&&I()}),typeof window<"u"&&window.addEventListener("storage",e=>{(e.key==="strands_auth_session"||e.key==="strands_auth_user")&&!e.newValue&&s.value&&_()});const ve=()=>{if(!(typeof window>"u")&&s.value&&o.value){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");(!e||!t)&&_()}},me=()=>{I(),$(),g()};try{u.getCurrentInstance()&&u.onUnmounted(me)}catch{}return w.value||N(),{user:u.computed(()=>s.value),currentUser:u.computed(()=>s.value),currentSession:u.computed(()=>o.value),isAuthenticated:Q,isLoading:u.computed(()=>W.value||!w.value),loading:j,loadingMessage:G,isInitializing:L,isInitialized:u.computed(()=>w.value),isSigningIn:U,isSigningUp:R,isSigningOut:q,isRefreshingToken:B,isSendingMfaEmail:V,isVerifyingMfa:K,mfaRequired:u.computed(()=>p.value),mfaSessionId:u.computed(()=>h.value),availableMfaMethods:u.computed(()=>S.value),signIn:X,signUp:Z,signOut:ee,refreshToken:P,fetchProfile:te,updateProfile:ae,updateUserSettings:ne,changeEmail:se,changeUsername:le,getUsernameCooldown:ue,checkUsernameAvailability:ce,getUserSessions:de,getSessionStats:fe,revokeSession:he,revokeAllOtherSessions:ge,initialize:N,setAuthData:C,verifyMfa:ie,sendMfaEmailCode:re,getMfaWebAuthnChallenge:oe,registerHardwareKey:Y,completeHardwareKeyRegistration:H,startTokenRefreshTimer:T,stopTokenRefreshTimer:I,getAuthHeaders:O,forceReInit:()=>{w.value=!1,i.value.initializing=!0,N()}}}exports.useStrandsAuth=Te;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed as c, ref as
|
|
1
|
+
import { computed as c, ref as y, getCurrentInstance as ye, onUnmounted as pe } from "vue";
|
|
2
2
|
import { u as Se } from "./useStrandsConfig-CMKVW1p3.es.js";
|
|
3
3
|
class _e {
|
|
4
4
|
cache = /* @__PURE__ */ new Map();
|
|
@@ -90,9 +90,9 @@ const L = ke((n, f) => {
|
|
|
90
90
|
createdAt: n.created_at || n.createdAt,
|
|
91
91
|
updatedAt: n.updated_at || n.updatedAt || (/* @__PURE__ */ new Date()).toISOString()
|
|
92
92
|
}), Ae = {
|
|
93
|
-
currentUser:
|
|
94
|
-
currentSession:
|
|
95
|
-
loadingStates:
|
|
93
|
+
currentUser: y(null),
|
|
94
|
+
currentSession: y(null),
|
|
95
|
+
loadingStates: y({
|
|
96
96
|
initializing: !0,
|
|
97
97
|
signingIn: !1,
|
|
98
98
|
signingUp: !1,
|
|
@@ -102,15 +102,15 @@ const L = ke((n, f) => {
|
|
|
102
102
|
verifyingMfa: !1,
|
|
103
103
|
loadingProfile: !1
|
|
104
104
|
}),
|
|
105
|
-
isInitialized:
|
|
106
|
-
mfaRequired:
|
|
107
|
-
mfaSessionId:
|
|
108
|
-
availableMfaMethods:
|
|
105
|
+
isInitialized: y(!1),
|
|
106
|
+
mfaRequired: y(!1),
|
|
107
|
+
mfaSessionId: y(null),
|
|
108
|
+
availableMfaMethods: y([])
|
|
109
109
|
};
|
|
110
|
-
let A = null,
|
|
110
|
+
let A = null, p = null, b = null, O = null;
|
|
111
111
|
function Ee() {
|
|
112
|
-
const { getUrl: n, config: f } = Se(), { fetch: v, clear: g, invalidate: P } = Te(), { currentUser: s, currentSession: o, loadingStates: i, isInitialized:
|
|
113
|
-
if (s.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")), E(), M(),
|
|
112
|
+
const { getUrl: n, config: f } = Se(), { fetch: v, clear: g, invalidate: P } = Te(), { currentUser: s, currentSession: o, loadingStates: i, isInitialized: m, mfaRequired: S, mfaSessionId: h, availableMfaMethods: _ } = Ae, T = () => {
|
|
113
|
+
if (s.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")), E(), M(), p = 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
|
}
|
|
@@ -222,16 +222,16 @@ function Ee() {
|
|
|
222
222
|
}, te = async () => {
|
|
223
223
|
i.value.signingOut = !0;
|
|
224
224
|
try {
|
|
225
|
-
E(), M(),
|
|
225
|
+
E(), M(), p = null, g(), s.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
|
i.value.signingOut = !1;
|
|
228
228
|
}
|
|
229
229
|
}, $ = async () => {
|
|
230
230
|
if (!o.value?.refreshToken)
|
|
231
231
|
return !1;
|
|
232
|
-
if (
|
|
233
|
-
return await
|
|
234
|
-
|
|
232
|
+
if (p)
|
|
233
|
+
return await p;
|
|
234
|
+
p = (async () => {
|
|
235
235
|
i.value.refreshingToken = !0;
|
|
236
236
|
try {
|
|
237
237
|
const t = await fetch(n("refresh"), {
|
|
@@ -264,8 +264,8 @@ function Ee() {
|
|
|
264
264
|
i.value.refreshingToken = !1;
|
|
265
265
|
}
|
|
266
266
|
})();
|
|
267
|
-
const e = await
|
|
268
|
-
return
|
|
267
|
+
const e = await p;
|
|
268
|
+
return p = null, e;
|
|
269
269
|
}, ae = async () => {
|
|
270
270
|
const e = `profile:${o.value.accessToken.slice(0, 20)}`;
|
|
271
271
|
i.value.loadingProfile = !0;
|
|
@@ -371,13 +371,13 @@ function Ee() {
|
|
|
371
371
|
body: JSON.stringify(u)
|
|
372
372
|
});
|
|
373
373
|
if (!l.ok) {
|
|
374
|
-
const
|
|
374
|
+
const D = await l.text();
|
|
375
375
|
let j = "MFA verification failed";
|
|
376
376
|
try {
|
|
377
|
-
const F = JSON.parse(
|
|
378
|
-
j = F.message || F.error ||
|
|
377
|
+
const F = JSON.parse(D);
|
|
378
|
+
j = F.message || F.error || D;
|
|
379
379
|
} catch {
|
|
380
|
-
j =
|
|
380
|
+
j = D || "MFA verification failed";
|
|
381
381
|
}
|
|
382
382
|
throw new Error(j);
|
|
383
383
|
}
|
|
@@ -469,8 +469,8 @@ function Ee() {
|
|
|
469
469
|
}, 2e3));
|
|
470
470
|
}, M = () => {
|
|
471
471
|
b && (clearInterval(b), b = null);
|
|
472
|
-
},
|
|
473
|
-
if (console.log("[useStrandsAuth] initialize() called, isInitialized:",
|
|
472
|
+
}, z = async () => {
|
|
473
|
+
if (console.log("[useStrandsAuth] initialize() called, isInitialized:", m.value, "hasPromise:", !!O), m.value) {
|
|
474
474
|
console.log("[useStrandsAuth] Already initialized, setting initializing=false"), i.value.initializing = !1;
|
|
475
475
|
return;
|
|
476
476
|
}
|
|
@@ -490,7 +490,7 @@ function Ee() {
|
|
|
490
490
|
localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user");
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
|
-
|
|
493
|
+
m.value = !0, console.log("[useStrandsAuth] isInitialized set to true, currentUser:", !!s.value), await new Promise((e) => setTimeout(e, 50));
|
|
494
494
|
} catch (e) {
|
|
495
495
|
console.error("[useStrandsAuth] initialization error:", e);
|
|
496
496
|
} finally {
|
|
@@ -601,17 +601,18 @@ function Ee() {
|
|
|
601
601
|
ye() && pe(me);
|
|
602
602
|
} catch {
|
|
603
603
|
}
|
|
604
|
-
return
|
|
604
|
+
return m.value || z(), {
|
|
605
605
|
// State
|
|
606
606
|
user: c(() => s.value),
|
|
607
607
|
currentUser: c(() => s.value),
|
|
608
608
|
currentSession: c(() => o.value),
|
|
609
609
|
isAuthenticated: X,
|
|
610
|
-
isLoading: c(() => G.value || !
|
|
610
|
+
isLoading: c(() => G.value || !m.value),
|
|
611
611
|
loading: J,
|
|
612
612
|
loadingMessage: H,
|
|
613
613
|
// Specific loading states
|
|
614
614
|
isInitializing: U,
|
|
615
|
+
isInitialized: c(() => m.value),
|
|
615
616
|
isSigningIn: R,
|
|
616
617
|
isSigningUp: B,
|
|
617
618
|
isSigningOut: V,
|
|
@@ -639,7 +640,7 @@ function Ee() {
|
|
|
639
640
|
getSessionStats: he,
|
|
640
641
|
revokeSession: ge,
|
|
641
642
|
revokeAllOtherSessions: ve,
|
|
642
|
-
initialize:
|
|
643
|
+
initialize: z,
|
|
643
644
|
setAuthData: N,
|
|
644
645
|
verifyMfa: re,
|
|
645
646
|
sendMfaEmailCode: oe,
|
|
@@ -652,7 +653,7 @@ function Ee() {
|
|
|
652
653
|
getAuthHeaders: I,
|
|
653
654
|
// Force re-initialization (useful for testing or navigation)
|
|
654
655
|
forceReInit: () => {
|
|
655
|
-
|
|
656
|
+
m.value = !1, i.value.initializing = !0, z();
|
|
656
657
|
}
|
|
657
658
|
};
|
|
658
659
|
}
|