vuethenticate 0.1.6 → 0.1.7
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/index.esm.js +1 -1
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
@@ -259,7 +259,7 @@ const h = /* @__PURE__ */ new Map(), J = (e) => {
|
|
259
259
|
await z(e);
|
260
260
|
const n = await e.userManager.signoutCallback();
|
261
261
|
return {
|
262
|
-
state: n == null ? void 0 : n.
|
262
|
+
state: n == null ? void 0 : n.userState
|
263
263
|
};
|
264
264
|
},
|
265
265
|
processSilentCallback: async () => {
|
package/dist/index.umd.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
(function(k,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("oidc-client-ts")):typeof define=="function"&&define.amd?define(["exports","vue","oidc-client-ts"],t):(k=typeof globalThis<"u"?globalThis:k||self,t(k.Vuethenticate={},k.Vue,k.OidcClientTs))})(this,function(k,t,I){"use strict";function L(e){const n=typeof window<"u"?window.location.origin:"";return{authority:e.authority,client_id:e.clientId,client_secret:e.clientSecret,client_authentication:e.clientAuthentication,redirect_uri:e.redirectUri??`${n}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new I.WebStorageStateStore({store:R(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${n}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??`${n}/auth/logout-callback`,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function R(e){if(typeof window>"u")return M();switch(e){case"localStorage":return window.localStorage;case"sessionStorage":return window.sessionStorage;case"memory":return M();default:return window.localStorage}}function M(){const e=new Map;return{getItem:n=>e.get(n)??null,setItem:(n,r)=>e.set(n,r),removeItem:n=>e.delete(n),clear:()=>e.clear(),get length(){return e.size},key:n=>Array.from(e.keys())[n]??null}}const g=new Map,V=e=>{try{const{userManager:n,eventCallbacks:r}=e;r.userLoaded&&n.events.removeUserLoaded(r.userLoaded),r.userUnloaded&&n.events.removeUserUnloaded(r.userUnloaded),r.accessTokenExpired&&n.events.removeAccessTokenExpired(r.accessTokenExpired),r.accessTokenExpiring&&n.events.removeAccessTokenExpiring(r.accessTokenExpiring),r.silentRenewError&&n.events.removeSilentRenewError(r.silentRenewError),n.stopSilentRenew(),n.clearStaleState()}catch(n){console.warn("Error during UserManager cleanup:",n)}},T=e=>`${e.authority}_${e.clientId}`,x=()=>g.size===0?null:(g.size===1||console.warn("Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."),Array.from(g.values())[0]||null),N=e=>{const n=T(e),r=g.get(n);if(r)return r;const i=$(e),a=t.ref(!1),d=t.ref(!1),l=t.ref(null),s=t.ref(!1),E=t.ref(null),m=t.computed(()=>!!l.value&&!l.value.expired),o=t.computed(()=>{var h;return((h=l.value)==null?void 0:h.access_token)||null}),u=t.computed(()=>{var h;return!!((h=l.value)!=null&&h.expired)}),p={userManager:i,isInitialized:a,isInitializing:d,user:l,isLoading:s,error:E,isAuthenticated:m,accessToken:o,isExpired:u,eventCallbacks:{}};return g.set(n,p),p},$=e=>{const n=L(e);return new I.UserManager(n)},b=(e,n,r,i)=>{const a=e instanceof Error?e:new Error(n);return r.value=a,i==null||i(a),a},_=e=>{var n,r;if(!((n=e.authority)!=null&&n.trim()))throw new Error("AuthConfig: authority is required");if(!((r=e.clientId)!=null&&r.trim()))throw new Error("AuthConfig: clientId is required");try{new URL(e.authority)}catch{throw new Error("AuthConfig: authority must be a valid URL")}},v=async(e,n=1e4)=>{if(!e.isInitialized.value)return new Promise((r,i)=>{const a=setTimeout(()=>{i(new Error("Authentication initialization timeout"))},n),d=t.watch(e.isInitialized,l=>{l&&(clearTimeout(a),d(),r())},{immediate:!0})})},F=e=>{_(e);const n=N(e),{userManager:r,isInitialized:i,isInitializing:a,user:d,isLoading:l,error:s,isAuthenticated:E,accessToken:m,isExpired:o}=n,u=T(e),p=async()=>{if(!(a.value||i.value))try{a.value=!0,l.value=!0,s.value=null;const w=await r.getUser();if(w)if(!w.expired)d.value=w;else if(e.automaticSilentRenew!==!1)try{await z()}catch(c){console.warn("Silent renewal failed during initialization:",c),await r.removeUser(),d.value=null}else await r.removeUser(),d.value=null}catch(w){b(w,"Failed to initialize authentication",s,e.onError)}finally{l.value=!1,a.value=!1,i.value=!0}},h=async w=>{try{l.value=!0,s.value=null,await r.signinRedirect({state:w})}catch(c){b(c,"Sign in failed",s,e.onError)}finally{l.value=!1}},O=async w=>{try{l.value=!0,s.value=null,d.value=null,await r.signoutRedirect({state:w})}catch(c){b(c,"Sign out failed",s,e.onError)}finally{l.value=!1}},z=async()=>{try{l.value=!0,s.value=null;const w=await r.signinSilent();d.value=w}catch(w){throw b(w,"Silent renewal failed",s,e.onError)}finally{l.value=!1}},D=()=>{s.value=null},K=(w,c)=>{const{userManager:S,user:A,error:W,eventCallbacks:f}=w;f.userLoaded=y=>{var C;A.value=y,(C=c.onUserLoaded)==null||C.call(c,y)},f.userUnloaded=()=>{var y;A.value=null,(y=c.onUserUnloaded)==null||y.call(c)},f.accessTokenExpired=()=>{var y;(y=c.onAccessTokenExpired)==null||y.call(c)},f.accessTokenExpiring=()=>{var y;(y=c.onAccessTokenExpiring)==null||y.call(c)},f.silentRenewError=async y=>{console.warn("Silent renewal failed:",y);try{await S.removeUser(),A.value=null}catch(C){console.error("Failed to remove user after silent renewal error:",C)}b(y,"Silent renewal failed",W,c.onError)},S.events.addUserLoaded(f.userLoaded),S.events.addUserUnloaded(f.userUnloaded),S.events.addAccessTokenExpired(f.accessTokenExpired),S.events.addAccessTokenExpiring(f.accessTokenExpiring),S.events.addSilentRenewError(f.silentRenewError)},j=()=>{V(n),g.delete(u)};return!i.value&&!a.value&&(p(),K(n,e)),{user:d,isAuthenticated:E,isLoading:l,error:s,accessToken:m,isExpired:o,signIn:h,signOut:O,silentRenew:z,clearError:D,cleanup:j}},U=()=>{const e=x();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async()=>{await v(e);const a=await e.userManager.signinCallback();if(!a)throw new Error("Authentication callback failed: no user returned");return{user:a,state:a.state}},processLogoutCallback:async()=>{await v(e);const a=await e.userManager.signoutCallback();return{state:a==null?void 0:a.
|
1
|
+
(function(k,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("oidc-client-ts")):typeof define=="function"&&define.amd?define(["exports","vue","oidc-client-ts"],t):(k=typeof globalThis<"u"?globalThis:k||self,t(k.Vuethenticate={},k.Vue,k.OidcClientTs))})(this,function(k,t,I){"use strict";function L(e){const n=typeof window<"u"?window.location.origin:"";return{authority:e.authority,client_id:e.clientId,client_secret:e.clientSecret,client_authentication:e.clientAuthentication,redirect_uri:e.redirectUri??`${n}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new I.WebStorageStateStore({store:R(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${n}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??`${n}/auth/logout-callback`,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function R(e){if(typeof window>"u")return M();switch(e){case"localStorage":return window.localStorage;case"sessionStorage":return window.sessionStorage;case"memory":return M();default:return window.localStorage}}function M(){const e=new Map;return{getItem:n=>e.get(n)??null,setItem:(n,r)=>e.set(n,r),removeItem:n=>e.delete(n),clear:()=>e.clear(),get length(){return e.size},key:n=>Array.from(e.keys())[n]??null}}const g=new Map,V=e=>{try{const{userManager:n,eventCallbacks:r}=e;r.userLoaded&&n.events.removeUserLoaded(r.userLoaded),r.userUnloaded&&n.events.removeUserUnloaded(r.userUnloaded),r.accessTokenExpired&&n.events.removeAccessTokenExpired(r.accessTokenExpired),r.accessTokenExpiring&&n.events.removeAccessTokenExpiring(r.accessTokenExpiring),r.silentRenewError&&n.events.removeSilentRenewError(r.silentRenewError),n.stopSilentRenew(),n.clearStaleState()}catch(n){console.warn("Error during UserManager cleanup:",n)}},T=e=>`${e.authority}_${e.clientId}`,x=()=>g.size===0?null:(g.size===1||console.warn("Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."),Array.from(g.values())[0]||null),N=e=>{const n=T(e),r=g.get(n);if(r)return r;const i=$(e),a=t.ref(!1),d=t.ref(!1),l=t.ref(null),s=t.ref(!1),E=t.ref(null),m=t.computed(()=>!!l.value&&!l.value.expired),o=t.computed(()=>{var h;return((h=l.value)==null?void 0:h.access_token)||null}),u=t.computed(()=>{var h;return!!((h=l.value)!=null&&h.expired)}),p={userManager:i,isInitialized:a,isInitializing:d,user:l,isLoading:s,error:E,isAuthenticated:m,accessToken:o,isExpired:u,eventCallbacks:{}};return g.set(n,p),p},$=e=>{const n=L(e);return new I.UserManager(n)},b=(e,n,r,i)=>{const a=e instanceof Error?e:new Error(n);return r.value=a,i==null||i(a),a},_=e=>{var n,r;if(!((n=e.authority)!=null&&n.trim()))throw new Error("AuthConfig: authority is required");if(!((r=e.clientId)!=null&&r.trim()))throw new Error("AuthConfig: clientId is required");try{new URL(e.authority)}catch{throw new Error("AuthConfig: authority must be a valid URL")}},v=async(e,n=1e4)=>{if(!e.isInitialized.value)return new Promise((r,i)=>{const a=setTimeout(()=>{i(new Error("Authentication initialization timeout"))},n),d=t.watch(e.isInitialized,l=>{l&&(clearTimeout(a),d(),r())},{immediate:!0})})},F=e=>{_(e);const n=N(e),{userManager:r,isInitialized:i,isInitializing:a,user:d,isLoading:l,error:s,isAuthenticated:E,accessToken:m,isExpired:o}=n,u=T(e),p=async()=>{if(!(a.value||i.value))try{a.value=!0,l.value=!0,s.value=null;const w=await r.getUser();if(w)if(!w.expired)d.value=w;else if(e.automaticSilentRenew!==!1)try{await z()}catch(c){console.warn("Silent renewal failed during initialization:",c),await r.removeUser(),d.value=null}else await r.removeUser(),d.value=null}catch(w){b(w,"Failed to initialize authentication",s,e.onError)}finally{l.value=!1,a.value=!1,i.value=!0}},h=async w=>{try{l.value=!0,s.value=null,await r.signinRedirect({state:w})}catch(c){b(c,"Sign in failed",s,e.onError)}finally{l.value=!1}},O=async w=>{try{l.value=!0,s.value=null,d.value=null,await r.signoutRedirect({state:w})}catch(c){b(c,"Sign out failed",s,e.onError)}finally{l.value=!1}},z=async()=>{try{l.value=!0,s.value=null;const w=await r.signinSilent();d.value=w}catch(w){throw b(w,"Silent renewal failed",s,e.onError)}finally{l.value=!1}},D=()=>{s.value=null},K=(w,c)=>{const{userManager:S,user:A,error:W,eventCallbacks:f}=w;f.userLoaded=y=>{var C;A.value=y,(C=c.onUserLoaded)==null||C.call(c,y)},f.userUnloaded=()=>{var y;A.value=null,(y=c.onUserUnloaded)==null||y.call(c)},f.accessTokenExpired=()=>{var y;(y=c.onAccessTokenExpired)==null||y.call(c)},f.accessTokenExpiring=()=>{var y;(y=c.onAccessTokenExpiring)==null||y.call(c)},f.silentRenewError=async y=>{console.warn("Silent renewal failed:",y);try{await S.removeUser(),A.value=null}catch(C){console.error("Failed to remove user after silent renewal error:",C)}b(y,"Silent renewal failed",W,c.onError)},S.events.addUserLoaded(f.userLoaded),S.events.addUserUnloaded(f.userUnloaded),S.events.addAccessTokenExpired(f.accessTokenExpired),S.events.addAccessTokenExpiring(f.accessTokenExpiring),S.events.addSilentRenewError(f.silentRenewError)},j=()=>{V(n),g.delete(u)};return!i.value&&!a.value&&(p(),K(n,e)),{user:d,isAuthenticated:E,isLoading:l,error:s,accessToken:m,isExpired:o,signIn:h,signOut:O,silentRenew:z,clearError:D,cleanup:j}},U=()=>{const e=x();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async()=>{await v(e);const a=await e.userManager.signinCallback();if(!a)throw new Error("Authentication callback failed: no user returned");return{user:a,state:a.state}},processLogoutCallback:async()=>{await v(e);const a=await e.userManager.signoutCallback();return{state:a==null?void 0:a.userState}},processSilentCallback:async()=>{await v(e),await e.userManager.signinCallback()},isInitialized:e.isInitialized,isInitializing:e.isInitializing}},P=t.defineComponent({__name:"AuthCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:n}){const r=e,i=n,{processCallback:a,isInitializing:d}=U(),l=t.ref(!0),s=t.ref(null),E=async()=>{var m,o;try{const u=await a();(m=r.onSuccess)==null||m.call(r,u.user,u.state),i("success",u.user,u.state)}catch(u){const p=u instanceof Error?u:new Error("Callback processing failed");s.value=p,(o=r.onError)==null||o.call(r,p),i("error",p)}finally{l.value=!1}};return t.onMounted(()=>{E()}),(m,o)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[(t.unref(d)||l.value)&&!s.value?t.renderSlot(m.$slots,"default",{key:0},()=>[o[0]||(o[0]=t.createElementVNode("p",null,"Processing authentication...",-1))]):t.createCommentVNode("",!0),s.value?t.renderSlot(m.$slots,"error",{key:1,error:s.value},()=>[t.createElementVNode("div",null,[o[1]||(o[1]=t.createElementVNode("h2",null,"Authentication Error",-1)),t.createElementVNode("p",null,t.toDisplayString(s.value.message),1)])]):t.createCommentVNode("",!0)],64))}}),q=t.defineComponent({__name:"LogoutCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:n}){const r=e,i=n,{processLogoutCallback:a,isInitializing:d}=U(),l=t.ref(!0),s=t.ref(null),E=async()=>{var m,o;try{const u=await a();(m=r.onSuccess)==null||m.call(r,u.state),i("success",u.state)}catch(u){const p=u instanceof Error?u:new Error("Logout callback processing failed");s.value=p,(o=r.onError)==null||o.call(r,p),i("error",p)}finally{l.value=!1}};return t.onMounted(()=>{E()}),(m,o)=>(t.unref(d)||l.value)&&!s.value?t.renderSlot(m.$slots,"default",{key:0},()=>[o[0]||(o[0]=t.createElementVNode("p",null,"Processing logout...",-1))]):s.value?t.renderSlot(m.$slots,"error",{key:1,error:s.value},()=>[t.createElementVNode("div",null,[o[1]||(o[1]=t.createElementVNode("h2",null,"Logout Error",-1)),t.createElementVNode("p",null,t.toDisplayString(s.value.message),1)])]):t.renderSlot(m.$slots,"success",{key:2},()=>[o[2]||(o[2]=t.createElementVNode("div",null,[t.createElementVNode("h2",null,"Logout Successful"),t.createElementVNode("p",null,"You have been logged out successfully.")],-1))])}}),B=t.defineComponent({__name:"SilentCallback",props:{onError:{type:Function}},setup(e){const n=e,{processSilentCallback:r,isInitializing:i}=U(),a=t.ref(null),d=async()=>{var l;try{await r()}catch(s){const E=s instanceof Error?s:new Error("Silent callback processing failed");a.value=E,(l=n.onError)==null||l.call(n,E),console.error("Silent callback error:",E)}};return t.onMounted(()=>{d()}),(l,s)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.unref(i)&&!a.value?t.renderSlot(l.$slots,"default",{key:0},()=>[s[0]||(s[0]=t.createElementVNode("p",null,"Processing silent renewal...",-1))]):t.createCommentVNode("",!0),a.value?t.renderSlot(l.$slots,"error",{key:1,error:a.value},()=>[t.createElementVNode("p",null,"Silent renewal error: "+t.toDisplayString(a.value.message),1)]):t.createCommentVNode("",!0)],64))}});k.AuthCallback=P,k.LogoutCallback=q,k.SilentCallback=B,k.useAuth=F,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
|