@strands.gg/accui 2.17.42 → 2.17.44
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/{StrandsUIPlugin-D6qvy6mu.cjs.js → StrandsUIPlugin-CoNziSk9.cjs.js} +35 -35
- package/dist/{StrandsUIPlugin-DuI6-C0h.es.js → StrandsUIPlugin-DEGzan-Q.es.js} +1908 -1862
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +3 -3
- package/dist/nuxt/runtime/composables/useStrandsAuth.cjs.js +1 -1
- package/dist/nuxt/runtime/composables/useStrandsAuth.es.js +1 -1
- package/dist/nuxt/runtime/middleware/auth.global.cjs.js +1 -1
- package/dist/nuxt/runtime/middleware/auth.global.es.js +8 -8
- package/dist/useStrandsAuth-CmAxFCQ_.cjs.js +1 -0
- package/dist/{useStrandsAuth-DDFF_fP4.es.js → useStrandsAuth-DWsqp9WI.es.js} +109 -110
- package/dist/vite.cjs.js +1 -1
- package/dist/vite.es.js +1 -1
- package/package.json +1 -1
- package/dist/useStrandsAuth-CzzMjqan.cjs.js +0 -1
package/dist/index.es.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { _ as Be, S as lt, U as Ka, a as Ga, b as Ya, c as Wa, d as kt, M as Qa, e as At, f as Gt, g as wa, u as Da, C as $a, h as Ze, i as gt, j as Na, k as mt, l as Et } from "./StrandsUIPlugin-
|
|
2
|
-
import { m as ed } from "./StrandsUIPlugin-
|
|
1
|
+
import { _ as Be, S as lt, U as Ka, a as Ga, b as Ya, c as Wa, d as kt, M as Qa, e as At, f as Gt, g as wa, u as Da, C as $a, h as Ze, i as gt, j as Na, k as mt, l as Et } from "./StrandsUIPlugin-DEGzan-Q.es.js";
|
|
2
|
+
import { m as ed } from "./StrandsUIPlugin-DEGzan-Q.es.js";
|
|
3
3
|
import { defineComponent as Ve, computed as D, provide as Qt, onMounted as We, onUnmounted as xt, createElementBlock as s, openBlock as a, normalizeClass as we, createElementVNode as e, createBlock as Ce, renderSlot as Oe, Teleport as Ft, createCommentVNode as I, toDisplayString as R, ref as A, watch as Le, createTextVNode as Q, reactive as Ye, withModifiers as De, createStaticVNode as Xt, createVNode as d, withDirectives as Xe, withCtx as M, unref as n, vModelText as Je, nextTick as ht, Fragment as Ne, Transition as rt, createSlots as qt, normalizeStyle as Re, renderList as Ke, mergeProps as ba, useSlots as ma, inject as pa, resolveDynamicComponent as ot, onBeforeUnmount as Ba, withKeys as Ue, h as oe, isMemoSame as Xa, getCurrentInstance as Ja } from "vue";
|
|
4
4
|
import { u as pt, p as Ta } from "./useStrandsConfig-CKLyNlSd.es.js";
|
|
5
5
|
import { s as ad } from "./useStrandsConfig-CKLyNlSd.es.js";
|
|
6
|
-
import { u as ft } from "./useStrandsAuth-
|
|
6
|
+
import { u as ft } from "./useStrandsAuth-DWsqp9WI.es.js";
|
|
7
7
|
import { u as es } from "./useDarkMode-CvinMR9O.es.js";
|
|
8
8
|
const ts = { class: "app-content" }, as = {
|
|
9
9
|
key: 0,
|
|
@@ -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-CmAxFCQ_.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-
|
|
2
|
+
import { u as r } from "../../../useStrandsAuth-DWsqp9WI.es.js";
|
|
3
3
|
const u = () => {
|
|
4
4
|
const n = e().public.strandsAuth, t = r();
|
|
5
5
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const r=require("nuxt/app"),g=r.defineNuxtRouteMiddleware(
|
|
1
|
+
"use strict";const r=require("nuxt/app"),g=r.defineNuxtRouteMiddleware(c=>{const n=r.useRuntimeConfig().public.strandsAuth;return new Promise(a=>{Promise.resolve().then(()=>require("../composables/useStrandsAuth.cjs.js")).then(({useStrandsAuth:d})=>{const{isAuthenticated:i,isLoading:l}=d(),o=()=>{if(l.value){setTimeout(o,50);return}const e=c.path,h=n.protectedRoutes?.some(t=>t.endsWith("*")?e.startsWith(t.slice(0,-1)):e===t||e.startsWith(t+"/")),f=n.guestOnlyRoutes?.some(t=>t.endsWith("*")?e.startsWith(t.slice(0,-1)):e===t||e.startsWith(t+"/"));if(h&&!i.value&&n.authUrl){const t=n.authUrl,s=t.includes("?")?`${t}&redirect=${encodeURIComponent(e)}`:`${t}?redirect=${encodeURIComponent(e)}`;try{return r.navigateTo(s)}catch(u){if(console.warn("[Strands Auth] navigateTo failed, using window.location:",u),typeof window<"u"){window.location.href=s;return}throw u}}if(f&&i.value&&n.onSignInUrl)return r.navigateTo(n.onSignInUrl);a()};o()})})});module.exports=g;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { defineNuxtRouteMiddleware as m, useRuntimeConfig as g, navigateTo as
|
|
2
|
-
const w = m((
|
|
1
|
+
import { defineNuxtRouteMiddleware as m, useRuntimeConfig as g, navigateTo as u } from "nuxt/app";
|
|
2
|
+
const w = m((a) => {
|
|
3
3
|
const n = g().public.strandsAuth;
|
|
4
4
|
if (!import.meta.server)
|
|
5
5
|
return new Promise((c) => {
|
|
@@ -9,11 +9,11 @@ const w = m((u) => {
|
|
|
9
9
|
setTimeout(i, 50);
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
const e =
|
|
13
|
-
if (h && !r.value) {
|
|
14
|
-
const t = n.authUrl
|
|
12
|
+
const e = a.path, h = n.protectedRoutes?.some((t) => t.endsWith("*") ? e.startsWith(t.slice(0, -1)) : e === t || e.startsWith(t + "/")), f = n.guestOnlyRoutes?.some((t) => t.endsWith("*") ? e.startsWith(t.slice(0, -1)) : e === t || e.startsWith(t + "/"));
|
|
13
|
+
if (h && !r.value && n.authUrl) {
|
|
14
|
+
const t = n.authUrl, o = t.includes("?") ? `${t}&redirect=${encodeURIComponent(e)}` : `${t}?redirect=${encodeURIComponent(e)}`;
|
|
15
15
|
try {
|
|
16
|
-
return
|
|
16
|
+
return u(o);
|
|
17
17
|
} catch (s) {
|
|
18
18
|
if (console.warn("[Strands Auth] navigateTo failed, using window.location:", s), typeof window < "u") {
|
|
19
19
|
window.location.href = o;
|
|
@@ -22,8 +22,8 @@ const w = m((u) => {
|
|
|
22
22
|
throw s;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
if (f && r.value)
|
|
26
|
-
return
|
|
25
|
+
if (f && r.value && n.onSignInUrl)
|
|
26
|
+
return u(n.onSignInUrl);
|
|
27
27
|
c();
|
|
28
28
|
};
|
|
29
29
|
i();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const u=require("vue"),we=require("./useStrandsConfig-nOR0oGdb.cjs.js");class ye{cache=new Map;DEFAULT_TTL=300*1e3;async fetch(d,v,g=this.DEFAULT_TTL){const b=Date.now(),i=this.cache.get(d);if(i&&b-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: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),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()}),_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,E=null,x=null;function Te(){const{getUrl:n,config:d}=we.useStrandsConfig(),{fetch:v,clear:g,invalidate:b}=pe(),{currentUser:i,currentSession:o,loadingStates:s,isInitialized:y,mfaRequired:p,mfaSessionId:h,availableMfaMethods:S}=_e,_=()=>{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(),$(),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(()=>s.value.initializing),R=u.computed(()=>s.value.signingIn),U=u.computed(()=>s.value.signingUp),q=u.computed(()=>s.value.signingOut),B=u.computed(()=>s.value.refreshingToken),V=u.computed(()=>s.value.sendingMfaEmail),K=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),G=u.computed(()=>s.value.initializing||J.value),H=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},W=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(()=>i.value!==null),X=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 C(r),r}catch(t){throw t}finally{s.value.signingIn=!1}},Z=async e=>{s.value.signingUp=!0;try{throw new Error("Sign up not implemented - please integrate with auth SDK")}finally{s.value.signingUp=!1}},ee=async()=>{s.value.signingOut=!0;try{O(),$(),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}},P=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(),M(),b(`sessions:${o.value.accessToken.slice(0,20)}`),!0}catch{return _(),!1}finally{s.value.refreshingToken=!1}})();const e=await w;return w=null,e},te=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}},ae=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&&F("strands_auth_user",JSON.stringify(i.value)),i.value}finally{s.value.loadingProfile=!1}},ne=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&&F("strands_auth_user",JSON.stringify(i.value)),i.value}finally{s.value.loadingProfile=!1}},se=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}},ie=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 D=await l.text();let j="MFA verification failed";try{const z=JSON.parse(D);j=z.message||z.error||D}catch{j=D||"MFA verification failed"}throw new Error(j)}const f=await l.json();return p.value=!1,h.value=null,S.value=[],await C(f),f}finally{s.value.verifyingMfa=!1}},re=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}},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&&(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(),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)},O=()=>{k&&(clearTimeout(k),k=null)},M=()=>{E||typeof window>"u"||(E=setInterval(()=>{i.value&&o.value&&(localStorage.getItem("strands_auth_session")||($(),_()))},2e3))},$=()=>{E&&(clearInterval(E),E=null)},N=async()=>{if(y.value){s.value.initializing=!1;return}return x||(x=(async()=>{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 Promise.race([P(),new Promise(f=>setTimeout(()=>f(!1),5e3))])||_()):a.expiresAt>new Date?(o.value=a,i.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,await new Promise(e=>setTimeout(e,50))}catch{}finally{s.value.initializing=!1,x=null}})(),x)},le=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}},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=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}},fe=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()},he=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},ge=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(),ve()):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 ve=()=>{if(!(typeof window>"u")&&i.value&&o.value){const e=localStorage.getItem("strands_auth_session"),t=localStorage.getItem("strands_auth_user");(!e||!t)&&_()}},me=()=>{O(),$(),g()};try{u.getCurrentInstance()&&u.onUnmounted(me)}catch{}return y.value||N(),{user:u.computed(()=>i.value),currentUser:u.computed(()=>i.value),currentSession:u.computed(()=>o.value),isAuthenticated:Q,isLoading:u.computed(()=>G.value||!y.value),loading:J,loadingMessage:H,isInitializing:L,isInitialized:u.computed(()=>y.value),isSigningIn:R,isSigningUp:U,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:W,startTokenRefreshTimer:T,stopTokenRefreshTimer:O,getAuthHeaders:A,forceReInit:()=>{y.value=!1,s.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 m, getCurrentInstance as ye, onUnmounted as pe } from "vue";
|
|
2
2
|
import { u as Se } from "./useStrandsConfig-CKLyNlSd.es.js";
|
|
3
3
|
class _e {
|
|
4
4
|
cache = /* @__PURE__ */ new Map();
|
|
@@ -8,9 +8,9 @@ class _e {
|
|
|
8
8
|
* Memoized fetch - prevents duplicate requests and caches results
|
|
9
9
|
*/
|
|
10
10
|
async fetch(f, v, g = this.DEFAULT_TTL) {
|
|
11
|
-
const P = Date.now(),
|
|
12
|
-
if (
|
|
13
|
-
return
|
|
11
|
+
const P = Date.now(), i = this.cache.get(f);
|
|
12
|
+
if (i && P - i.timestamp < i.ttl)
|
|
13
|
+
return i.promise;
|
|
14
14
|
this.cleanExpired();
|
|
15
15
|
const o = v().finally(() => {
|
|
16
16
|
setTimeout(() => {
|
|
@@ -72,7 +72,7 @@ function ke(n, f) {
|
|
|
72
72
|
}
|
|
73
73
|
const L = ke((n, f) => {
|
|
74
74
|
typeof window < "u" && localStorage.setItem(n, f);
|
|
75
|
-
}, 300),
|
|
75
|
+
}, 300), E = (n) => ({
|
|
76
76
|
id: n.id,
|
|
77
77
|
email: n.email,
|
|
78
78
|
firstName: n.first_name || n.firstName || "",
|
|
@@ -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: m(null),
|
|
94
|
+
currentSession: m(null),
|
|
95
|
+
loadingStates: m({
|
|
96
96
|
initializing: !0,
|
|
97
97
|
signingIn: !1,
|
|
98
98
|
signingUp: !1,
|
|
@@ -102,26 +102,26 @@ 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: m(!1),
|
|
106
|
+
mfaRequired: m(!1),
|
|
107
|
+
mfaSessionId: m(null),
|
|
108
|
+
availableMfaMethods: m([])
|
|
109
109
|
};
|
|
110
|
-
let A = null,
|
|
110
|
+
let A = null, y = null, x = null, b = null;
|
|
111
111
|
function Ee() {
|
|
112
|
-
const { getUrl: n, config: f } = Se(), { fetch: v, clear: g, invalidate: P } = Te(), { currentUser:
|
|
113
|
-
if (
|
|
112
|
+
const { getUrl: n, config: f } = Se(), { fetch: v, clear: g, invalidate: P } = Te(), { currentUser: i, currentSession: o, loadingStates: s, isInitialized: p, mfaRequired: S, mfaSessionId: h, availableMfaMethods: _ } = Ae, 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(), M(), 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
|
-
},
|
|
118
|
-
c(() =>
|
|
119
|
-
const
|
|
120
|
-
() =>
|
|
121
|
-
),
|
|
122
|
-
const e =
|
|
117
|
+
}, R = c(() => s.value.initializing), U = c(() => s.value.signingIn), B = c(() => s.value.signingUp), V = c(() => s.value.signingOut), q = c(() => s.value.refreshingToken), K = c(() => s.value.sendingMfaEmail), G = c(() => s.value.verifyingMfa);
|
|
118
|
+
c(() => s.value.loadingProfile);
|
|
119
|
+
const z = c(
|
|
120
|
+
() => s.value.signingIn || s.value.signingUp || s.value.signingOut || s.value.refreshingToken || s.value.sendingMfaEmail || s.value.verifyingMfa || s.value.loadingProfile
|
|
121
|
+
), H = c(() => s.value.initializing || z.value), W = c(() => {
|
|
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 = () => {
|
|
125
125
|
const e = {};
|
|
126
126
|
return o.value?.accessToken && (e.Authorization = `Bearer ${o.value.accessToken}`), o.value?.refreshToken && (e["x-refresh-token"] = o.value.refreshToken), e;
|
|
127
127
|
}, Y = async (e, t, a) => {
|
|
@@ -172,8 +172,8 @@ function Ee() {
|
|
|
172
172
|
throw new Error(l);
|
|
173
173
|
}
|
|
174
174
|
return r.json();
|
|
175
|
-
}, X = c(() =>
|
|
176
|
-
|
|
175
|
+
}, X = c(() => i.value !== null), Z = async (e) => {
|
|
176
|
+
s.value.signingIn = !0;
|
|
177
177
|
try {
|
|
178
178
|
S.value = !1, h.value = null, _.value = [];
|
|
179
179
|
const t = {
|
|
@@ -204,35 +204,35 @@ function Ee() {
|
|
|
204
204
|
device_info: l.device_info
|
|
205
205
|
};
|
|
206
206
|
});
|
|
207
|
-
return _.value = u,
|
|
207
|
+
return _.value = u, s.value.signingIn = !1, r;
|
|
208
208
|
}
|
|
209
209
|
return await N(r), r;
|
|
210
210
|
} catch (t) {
|
|
211
211
|
throw t;
|
|
212
212
|
} finally {
|
|
213
|
-
|
|
213
|
+
s.value.signingIn = !1;
|
|
214
214
|
}
|
|
215
215
|
}, ee = async (e) => {
|
|
216
|
-
|
|
216
|
+
s.value.signingUp = !0;
|
|
217
217
|
try {
|
|
218
218
|
throw new Error("Sign up not implemented - please integrate with auth SDK");
|
|
219
219
|
} finally {
|
|
220
|
-
|
|
220
|
+
s.value.signingUp = !1;
|
|
221
221
|
}
|
|
222
222
|
}, te = async () => {
|
|
223
|
-
|
|
223
|
+
s.value.signingOut = !0;
|
|
224
224
|
try {
|
|
225
|
-
|
|
225
|
+
I(), M(), 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
229
|
}, $ = async () => {
|
|
230
230
|
if (!o.value?.refreshToken)
|
|
231
231
|
return !1;
|
|
232
|
-
if (
|
|
233
|
-
return await
|
|
234
|
-
|
|
235
|
-
|
|
232
|
+
if (y)
|
|
233
|
+
return await y;
|
|
234
|
+
y = (async () => {
|
|
235
|
+
s.value.refreshingToken = !0;
|
|
236
236
|
try {
|
|
237
237
|
const t = await fetch(n("refresh"), {
|
|
238
238
|
method: "POST",
|
|
@@ -249,26 +249,26 @@ function Ee() {
|
|
|
249
249
|
throw new Error(`Token refresh failed: ${t.status} ${t.statusText}`);
|
|
250
250
|
}
|
|
251
251
|
const a = await t.json();
|
|
252
|
-
a.user && (
|
|
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,
|
|
256
256
|
expiresAt: new Date(Date.now() + 300 * 1e3),
|
|
257
257
|
// 5 minutes from now
|
|
258
|
-
userId: a.user?.id ||
|
|
258
|
+
userId: a.user?.id || i.value?.id
|
|
259
259
|
};
|
|
260
260
|
return o.value = r, typeof window < "u" && localStorage.setItem("strands_auth_session", JSON.stringify(r)), k(), C(), P(`sessions:${o.value.accessToken.slice(0, 20)}`), !0;
|
|
261
261
|
} catch {
|
|
262
262
|
return T(), !1;
|
|
263
263
|
} finally {
|
|
264
|
-
|
|
264
|
+
s.value.refreshingToken = !1;
|
|
265
265
|
}
|
|
266
266
|
})();
|
|
267
|
-
const e = await
|
|
268
|
-
return
|
|
267
|
+
const e = await y;
|
|
268
|
+
return y = null, e;
|
|
269
269
|
}, ae = async () => {
|
|
270
270
|
const e = `profile:${o.value.accessToken.slice(0, 20)}`;
|
|
271
|
-
|
|
271
|
+
s.value.loadingProfile = !0;
|
|
272
272
|
try {
|
|
273
273
|
return await v(e, async () => {
|
|
274
274
|
const t = await fetch(n("profile"), {
|
|
@@ -281,13 +281,13 @@ 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
|
|
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;
|
|
288
288
|
}
|
|
289
289
|
}, ne = async (e) => {
|
|
290
|
-
|
|
290
|
+
s.value.loadingProfile = !0;
|
|
291
291
|
try {
|
|
292
292
|
const t = await fetch(n("profile"), {
|
|
293
293
|
method: "POST",
|
|
@@ -303,12 +303,12 @@ 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
|
|
306
|
+
return i.value = E(a), i.value && L("strands_auth_user", JSON.stringify(i.value)), i.value;
|
|
307
307
|
} finally {
|
|
308
|
-
|
|
308
|
+
s.value.loadingProfile = !1;
|
|
309
309
|
}
|
|
310
310
|
}, se = async (e) => {
|
|
311
|
-
|
|
311
|
+
s.value.loadingProfile = !0;
|
|
312
312
|
try {
|
|
313
313
|
const t = await fetch(n("settings"), {
|
|
314
314
|
method: "POST",
|
|
@@ -323,12 +323,12 @@ 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
|
|
326
|
+
return i.value = E(a), i.value && L("strands_auth_user", JSON.stringify(i.value)), i.value;
|
|
327
327
|
} finally {
|
|
328
|
-
|
|
328
|
+
s.value.loadingProfile = !1;
|
|
329
329
|
}
|
|
330
330
|
}, ie = async (e, t) => {
|
|
331
|
-
|
|
331
|
+
s.value.loadingProfile = !0;
|
|
332
332
|
try {
|
|
333
333
|
const a = await fetch(n("changeEmail"), {
|
|
334
334
|
method: "POST",
|
|
@@ -350,20 +350,20 @@ function Ee() {
|
|
|
350
350
|
}
|
|
351
351
|
}
|
|
352
352
|
const r = await a.json();
|
|
353
|
-
return
|
|
354
|
-
...
|
|
353
|
+
return i.value && (i.value = {
|
|
354
|
+
...i.value,
|
|
355
355
|
email: e,
|
|
356
356
|
emailVerified: !1,
|
|
357
357
|
// Email needs to be verified again
|
|
358
358
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
359
|
-
}, typeof window < "u" && localStorage.setItem("strands_auth_user", JSON.stringify(
|
|
359
|
+
}, typeof window < "u" && localStorage.setItem("strands_auth_user", JSON.stringify(i.value))), r;
|
|
360
360
|
} finally {
|
|
361
|
-
|
|
361
|
+
s.value.loadingProfile = !1;
|
|
362
362
|
}
|
|
363
363
|
}, re = async (e, t, a = !1) => {
|
|
364
364
|
if (!h.value)
|
|
365
365
|
throw new Error("No MFA session available");
|
|
366
|
-
|
|
366
|
+
s.value.verifyingMfa = !0;
|
|
367
367
|
try {
|
|
368
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",
|
|
@@ -371,25 +371,25 @@ function Ee() {
|
|
|
371
371
|
body: JSON.stringify(u)
|
|
372
372
|
});
|
|
373
373
|
if (!l.ok) {
|
|
374
|
-
const
|
|
375
|
-
let
|
|
374
|
+
const j = await l.text();
|
|
375
|
+
let J = "MFA verification failed";
|
|
376
376
|
try {
|
|
377
|
-
const F = JSON.parse(
|
|
378
|
-
|
|
377
|
+
const F = JSON.parse(j);
|
|
378
|
+
J = F.message || F.error || j;
|
|
379
379
|
} catch {
|
|
380
|
-
|
|
380
|
+
J = j || "MFA verification failed";
|
|
381
381
|
}
|
|
382
|
-
throw new Error(
|
|
382
|
+
throw new Error(J);
|
|
383
383
|
}
|
|
384
384
|
const d = await l.json();
|
|
385
385
|
return S.value = !1, h.value = null, _.value = [], await N(d), d;
|
|
386
386
|
} finally {
|
|
387
|
-
|
|
387
|
+
s.value.verifyingMfa = !1;
|
|
388
388
|
}
|
|
389
389
|
}, oe = async (e) => {
|
|
390
390
|
if (!h.value)
|
|
391
391
|
throw new Error("No MFA session available");
|
|
392
|
-
|
|
392
|
+
s.value.sendingMfaEmail = !0;
|
|
393
393
|
try {
|
|
394
394
|
const t = await fetch(n("mfaSigninSendEmail"), {
|
|
395
395
|
method: "POST",
|
|
@@ -412,7 +412,7 @@ function Ee() {
|
|
|
412
412
|
}
|
|
413
413
|
return await t.json();
|
|
414
414
|
} finally {
|
|
415
|
-
|
|
415
|
+
s.value.sendingMfaEmail = !1;
|
|
416
416
|
}
|
|
417
417
|
}, le = async (e) => {
|
|
418
418
|
if (!h.value)
|
|
@@ -439,15 +439,15 @@ function Ee() {
|
|
|
439
439
|
return t.json();
|
|
440
440
|
}, N = async (e) => {
|
|
441
441
|
try {
|
|
442
|
-
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,
|
|
446
446
|
expiresAt: new Date(Date.now() + 300 * 1e3),
|
|
447
447
|
// 5 minutes from now (matching API token expiry)
|
|
448
|
-
userId:
|
|
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)),
|
|
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(), C();
|
|
451
451
|
} catch {
|
|
452
452
|
}
|
|
453
453
|
}, k = () => {
|
|
@@ -461,44 +461,43 @@ function Ee() {
|
|
|
461
461
|
A = setTimeout(async () => {
|
|
462
462
|
(typeof document > "u" || document.visibilityState === "visible") && await $() && k();
|
|
463
463
|
}, a);
|
|
464
|
-
},
|
|
464
|
+
}, I = () => {
|
|
465
465
|
A && (clearTimeout(A), A = null);
|
|
466
466
|
}, C = () => {
|
|
467
|
-
|
|
468
|
-
|
|
467
|
+
x || typeof window > "u" || (x = setInterval(() => {
|
|
468
|
+
i.value && o.value && (localStorage.getItem("strands_auth_session") || (M(), T()));
|
|
469
469
|
}, 2e3));
|
|
470
470
|
}, M = () => {
|
|
471
|
-
|
|
472
|
-
},
|
|
473
|
-
if (
|
|
474
|
-
|
|
471
|
+
x && (clearInterval(x), x = null);
|
|
472
|
+
}, D = async () => {
|
|
473
|
+
if (p.value) {
|
|
474
|
+
s.value.initializing = !1;
|
|
475
475
|
return;
|
|
476
476
|
}
|
|
477
|
-
return
|
|
478
|
-
|
|
477
|
+
return b || (b = (async () => {
|
|
478
|
+
s.value.initializing = !0;
|
|
479
479
|
try {
|
|
480
480
|
if (typeof window < "u") {
|
|
481
481
|
const e = localStorage.getItem("strands_auth_session"), t = localStorage.getItem("strands_auth_user");
|
|
482
482
|
if (e && t)
|
|
483
483
|
try {
|
|
484
484
|
const a = JSON.parse(e), r = JSON.parse(t);
|
|
485
|
-
a.expiresAt = new Date(a.expiresAt), a.expiresAt <= /* @__PURE__ */ new Date() && a.refreshToken ? (o.value = a,
|
|
485
|
+
a.expiresAt = new Date(a.expiresAt), a.expiresAt <= /* @__PURE__ */ new Date() && a.refreshToken ? (o.value = a, i.value = r, await Promise.race([
|
|
486
486
|
$(),
|
|
487
487
|
new Promise((d) => setTimeout(() => d(!1), 5e3))
|
|
488
|
-
]) || T()) : a.expiresAt > /* @__PURE__ */ new Date() ? (o.value = a,
|
|
488
|
+
]) || T()) : a.expiresAt > /* @__PURE__ */ new Date() ? (o.value = a, i.value = r, k(), C()) : (localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user"));
|
|
489
489
|
} catch {
|
|
490
490
|
localStorage.removeItem("strands_auth_session"), localStorage.removeItem("strands_auth_user");
|
|
491
491
|
}
|
|
492
492
|
}
|
|
493
|
-
|
|
494
|
-
} catch
|
|
495
|
-
console.error("[useStrandsAuth] initialization error:", e);
|
|
493
|
+
p.value = !0, await new Promise((e) => setTimeout(e, 50));
|
|
494
|
+
} catch {
|
|
496
495
|
} finally {
|
|
497
|
-
|
|
496
|
+
s.value.initializing = !1, b = null;
|
|
498
497
|
}
|
|
499
|
-
})(),
|
|
498
|
+
})(), b);
|
|
500
499
|
}, ue = async (e) => {
|
|
501
|
-
|
|
500
|
+
s.value.loadingProfile = !0;
|
|
502
501
|
try {
|
|
503
502
|
const t = await fetch(n("changeUsername"), {
|
|
504
503
|
method: "POST",
|
|
@@ -515,14 +514,14 @@ function Ee() {
|
|
|
515
514
|
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}`);
|
|
516
515
|
}
|
|
517
516
|
const a = await t.json();
|
|
518
|
-
return
|
|
519
|
-
...
|
|
517
|
+
return i.value && (i.value = {
|
|
518
|
+
...i.value,
|
|
520
519
|
username: e,
|
|
521
520
|
usernameLastChangedAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
522
521
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
523
|
-
}, typeof window < "u" && localStorage.setItem("strands_auth_user", JSON.stringify(
|
|
522
|
+
}, typeof window < "u" && localStorage.setItem("strands_auth_user", JSON.stringify(i.value))), a;
|
|
524
523
|
} finally {
|
|
525
|
-
|
|
524
|
+
s.value.loadingProfile = !1;
|
|
526
525
|
}
|
|
527
526
|
}, ce = async () => {
|
|
528
527
|
const e = await fetch(n("usernameCooldown"), {
|
|
@@ -548,7 +547,7 @@ function Ee() {
|
|
|
548
547
|
const e = `sessions:${o.value?.accessToken?.slice(0, 20) || "no-token"}`;
|
|
549
548
|
try {
|
|
550
549
|
return await v(e, async () => {
|
|
551
|
-
const t =
|
|
550
|
+
const t = O(), a = await fetch(n("sessions"), {
|
|
552
551
|
method: "GET",
|
|
553
552
|
headers: t
|
|
554
553
|
});
|
|
@@ -562,7 +561,7 @@ function Ee() {
|
|
|
562
561
|
}, he = async () => {
|
|
563
562
|
const e = await fetch(n("sessionsStats"), {
|
|
564
563
|
method: "GET",
|
|
565
|
-
headers:
|
|
564
|
+
headers: O()
|
|
566
565
|
});
|
|
567
566
|
if (!e.ok)
|
|
568
567
|
throw new Error(`Failed to get session stats: ${e.status} ${e.statusText}`);
|
|
@@ -570,7 +569,7 @@ function Ee() {
|
|
|
570
569
|
}, ge = async (e) => {
|
|
571
570
|
const t = n("sessionRevoke").replace("{session_id}", encodeURIComponent(e)), a = await fetch(t, {
|
|
572
571
|
method: "POST",
|
|
573
|
-
headers:
|
|
572
|
+
headers: O()
|
|
574
573
|
});
|
|
575
574
|
if (!a.ok)
|
|
576
575
|
throw new Error(`Failed to revoke session: ${a.status} ${a.statusText}`);
|
|
@@ -578,47 +577,47 @@ function Ee() {
|
|
|
578
577
|
}, ve = async () => {
|
|
579
578
|
const e = await fetch(n("sessionsRevokeAll"), {
|
|
580
579
|
method: "POST",
|
|
581
|
-
headers:
|
|
580
|
+
headers: O()
|
|
582
581
|
});
|
|
583
582
|
if (!e.ok)
|
|
584
583
|
throw new Error(`Failed to revoke all other sessions: ${e.status} ${e.statusText}`);
|
|
585
584
|
return e.status === 200;
|
|
586
585
|
};
|
|
587
586
|
typeof document < "u" && document.addEventListener("visibilitychange", () => {
|
|
588
|
-
document.visibilityState === "visible" && o.value ? (k(), we()) : document.visibilityState === "hidden" &&
|
|
587
|
+
document.visibilityState === "visible" && o.value ? (k(), we()) : document.visibilityState === "hidden" && I();
|
|
589
588
|
}), typeof window < "u" && window.addEventListener("storage", (e) => {
|
|
590
|
-
(e.key === "strands_auth_session" || e.key === "strands_auth_user") && !e.newValue &&
|
|
589
|
+
(e.key === "strands_auth_session" || e.key === "strands_auth_user") && !e.newValue && i.value && T();
|
|
591
590
|
});
|
|
592
591
|
const we = () => {
|
|
593
|
-
if (!(typeof window > "u") &&
|
|
592
|
+
if (!(typeof window > "u") && i.value && o.value) {
|
|
594
593
|
const e = localStorage.getItem("strands_auth_session"), t = localStorage.getItem("strands_auth_user");
|
|
595
594
|
(!e || !t) && T();
|
|
596
595
|
}
|
|
597
596
|
}, me = () => {
|
|
598
|
-
|
|
597
|
+
I(), M(), g();
|
|
599
598
|
};
|
|
600
599
|
try {
|
|
601
600
|
ye() && pe(me);
|
|
602
601
|
} catch {
|
|
603
602
|
}
|
|
604
|
-
return
|
|
603
|
+
return p.value || D(), {
|
|
605
604
|
// State
|
|
606
|
-
user: c(() =>
|
|
607
|
-
currentUser: c(() =>
|
|
605
|
+
user: c(() => i.value),
|
|
606
|
+
currentUser: c(() => i.value),
|
|
608
607
|
currentSession: c(() => o.value),
|
|
609
608
|
isAuthenticated: X,
|
|
610
|
-
isLoading: c(() =>
|
|
611
|
-
loading:
|
|
612
|
-
loadingMessage:
|
|
609
|
+
isLoading: c(() => H.value || !p.value),
|
|
610
|
+
loading: z,
|
|
611
|
+
loadingMessage: W,
|
|
613
612
|
// Specific loading states
|
|
614
|
-
isInitializing:
|
|
615
|
-
isInitialized: c(() =>
|
|
616
|
-
isSigningIn:
|
|
613
|
+
isInitializing: R,
|
|
614
|
+
isInitialized: c(() => p.value),
|
|
615
|
+
isSigningIn: U,
|
|
617
616
|
isSigningUp: B,
|
|
618
617
|
isSigningOut: V,
|
|
619
618
|
isRefreshingToken: q,
|
|
620
619
|
isSendingMfaEmail: K,
|
|
621
|
-
isVerifyingMfa:
|
|
620
|
+
isVerifyingMfa: G,
|
|
622
621
|
// MFA State
|
|
623
622
|
mfaRequired: c(() => S.value),
|
|
624
623
|
mfaSessionId: c(() => h.value),
|
|
@@ -640,7 +639,7 @@ function Ee() {
|
|
|
640
639
|
getSessionStats: he,
|
|
641
640
|
revokeSession: ge,
|
|
642
641
|
revokeAllOtherSessions: ve,
|
|
643
|
-
initialize:
|
|
642
|
+
initialize: D,
|
|
644
643
|
setAuthData: N,
|
|
645
644
|
verifyMfa: re,
|
|
646
645
|
sendMfaEmailCode: oe,
|
|
@@ -649,11 +648,11 @@ function Ee() {
|
|
|
649
648
|
completeHardwareKeyRegistration: Y,
|
|
650
649
|
// Token management
|
|
651
650
|
startTokenRefreshTimer: k,
|
|
652
|
-
stopTokenRefreshTimer:
|
|
653
|
-
getAuthHeaders:
|
|
651
|
+
stopTokenRefreshTimer: I,
|
|
652
|
+
getAuthHeaders: O,
|
|
654
653
|
// Force re-initialization (useful for testing or navigation)
|
|
655
654
|
forceReInit: () => {
|
|
656
|
-
|
|
655
|
+
p.value = !1, s.value.initializing = !0, D();
|
|
657
656
|
}
|
|
658
657
|
};
|
|
659
658
|
}
|
package/dist/vite.cjs.js
CHANGED
|
@@ -26,4 +26,4 @@ if (typeof window !== 'undefined') {
|
|
|
26
26
|
window.__STRANDS_INJECTED__ = true
|
|
27
27
|
}
|
|
28
28
|
`}
|
|
29
|
-
${s}`,map:null}:null}}}function d(i={}){return{install(a){Promise.resolve().then(()=>require("./StrandsUIPlugin-
|
|
29
|
+
${s}`,map:null}:null}}}function d(i={}){return{install(a){Promise.resolve().then(()=>require("./StrandsUIPlugin-CoNziSk9.cjs.js")).then(n=>n.StrandsUIPlugin$1).then(n=>{const r=n.default;a.use(r)}),Promise.resolve().then(()=>require("./useStrandsConfig-nOR0oGdb.cjs.js")).then(n=>n.useStrandsConfig$1).then(n=>{const{setStrandsConfig:r}=n;r(i),typeof window<"u"&&(window.__STRANDS_CONFIG__=i)})}}}exports.StrandsAuth=e;exports.StrandsAuthVitePlugin=e;exports.createStrandsAuth=d;exports.default=e;exports.strandsAuth=e;
|
package/dist/vite.es.js
CHANGED
|
@@ -73,7 +73,7 @@ ${s}`,
|
|
|
73
73
|
function d(r = {}) {
|
|
74
74
|
return {
|
|
75
75
|
install(a) {
|
|
76
|
-
import("./StrandsUIPlugin-
|
|
76
|
+
import("./StrandsUIPlugin-DEGzan-Q.es.js").then((n) => n.n).then((n) => {
|
|
77
77
|
const i = n.default;
|
|
78
78
|
a.use(i);
|
|
79
79
|
}), import("./useStrandsConfig-CKLyNlSd.es.js").then((n) => n.a).then((n) => {
|