vuethenticate 0.1.9 → 0.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,sBAAsB,EACtB,aAAa,EAChB,MAAM,eAAe,CAAC;AAmRvB;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,OAAO,EACpC,QAAQ,UAAU,KACnB,aAAa,CAAC,MAAM,
|
1
|
+
{"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,sBAAsB,EACtB,aAAa,EAChB,MAAM,eAAe,CAAC;AAmRvB;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,OAAO,EACpC,QAAQ,UAAU,KACnB,aAAa,CAAC,MAAM,CAgPtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GACzB,MAAM,GAAG,OAAO,OACf,sBAAsB,CAAC,MAAM,CAgFjC,CAAC"}
|
package/dist/index.esm.js
CHANGED
package/dist/index.umd.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
(function(f,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("oidc-client-ts")):typeof define=="function"&&define.amd?define(["exports","vue","oidc-client-ts"],r):(f=typeof globalThis<"u"?globalThis:f||self,r(f.Vuethenticate={},f.Vue,f.OidcClientTs))})(this,function(f,r,p){"use strict";var b=(e=>(e[e.NONE=0]="NONE",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.DEBUG=4]="DEBUG",e))(b||{});const V={error:(e,...t)=>console.error(e,...t),warn:(e,...t)=>console.warn(e,...t),info:(e,...t)=>console.info(e,...t),debug:(e,...t)=>console.debug(e,...t)},I={error:()=>{},warn:()=>{},info:()=>{},debug:()=>{}},x=(e,t)=>({error:t>=1?e.error:()=>{},warn:t>=2?e.warn:()=>{},info:t>=3?e.info:()=>{},debug:t>=4?e.debug:()=>{}});function $(e){const t=typeof window<"u"?window.location.origin:"";return P(e),{authority:e.authority,client_id:e.clientId,client_secret:e.clientSecret,client_authentication:e.clientAuthentication,redirect_uri:e.redirectUri??`${t}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new p.WebStorageStateStore({store:F(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${t}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??`${t}/auth/logout-callback`,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function F(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:t=>e.get(t)??null,setItem:(t,n)=>e.set(t,n),removeItem:t=>e.delete(t),clear:()=>e.clear(),get length(){return e.size},key:t=>Array.from(e.keys())[t]??null}}const P=e=>{if(e.logLevel===void 0&&!e.logger)return;const t=e.logger??(e.logLevel!==void 0?V:void 0),n=e.logLevel??b.NONE;t&&(p.Log.setLogger({error:t.error,warn:t.warn,info:t.info,debug:t.debug}),p.Log.setLevel(_(n)))},_=e=>{switch(e){case b.NONE:return p.Log.NONE;case b.ERROR:return p.Log.ERROR;case b.WARN:return p.Log.WARN;case b.INFO:return p.Log.INFO;case b.DEBUG:return p.Log.DEBUG;default:return p.Log.NONE}},S=new Map,B=e=>{try{const{userManager:t,eventCallbacks:n}=e;n.userLoaded&&t.events.removeUserLoaded(n.userLoaded),n.userUnloaded&&t.events.removeUserUnloaded(n.userUnloaded),n.accessTokenExpired&&t.events.removeAccessTokenExpired(n.accessTokenExpired),n.accessTokenExpiring&&t.events.removeAccessTokenExpiring(n.accessTokenExpiring),n.silentRenewError&&t.events.removeSilentRenewError(n.silentRenewError),t.stopSilentRenew(),t.clearStaleState()}catch(t){console.warn("Error during UserManager cleanup:",t)}},z=e=>`${e.authority}_${e.clientId}`,W=()=>S.size===0?null:(S.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(S.values())[0]||null),D=e=>{const t=z(e),n=S.get(t);if(n)return n;const s=q(e),a=r.ref(!1),d=r.ref(!1),l=r.ref(null),o=r.ref(!1),i=r.ref(null),E=r.computed(()=>!!l.value&&!l.value.expired),h=r.computed(()=>{var A;return((A=l.value)==null?void 0:A.access_token)||null}),c=r.computed(()=>{var A;return!!((A=l.value)!=null&&A.expired)}),g=G(e),w={userManager:s,isInitialized:a,isInitializing:d,user:l,isLoading:o,error:i,isAuthenticated:E,accessToken:h,isExpired:c,logger:g,eventCallbacks:{}};return S.set(t,w),w},q=e=>{const t=$(e);return new p.UserManager(t)},G=e=>{if(!e.logger&&!e.logLevel)return I;const t=e.logger??V,n=e.logLevel??b.NONE;return x(t,n)},U=(e,t,n,s)=>{const a=e instanceof Error?e:new Error(t);return n.value=a,s==null||s(a),a},K=e=>{var t,n;if(!((t=e.authority)!=null&&t.trim()))throw new Error("AuthConfig: authority is required");if(!((n=e.clientId)!=null&&n.trim()))throw new Error("AuthConfig: clientId is required");try{new URL(e.authority)}catch{throw new Error("AuthConfig: authority must be a valid URL")}},N=async(e,t=1e4)=>{if(!e.isInitialized.value)return new Promise((n,s)=>{const a=setTimeout(()=>{s(new Error("Authentication initialization timeout"))},t),d=r.watch(e.isInitialized,l=>{l&&(clearTimeout(a),d(),n())},{immediate:!0})})},j=e=>{const t=window.location.href;return!!(e.silentRedirectUri&&t.startsWith(e.silentRedirectUri)||e.redirectUri&&t.startsWith(e.redirectUri)||e.postLogoutRedirectUri&&t.startsWith(e.postLogoutRedirectUri))},Y=e=>{K(e);const t=D(e),{userManager:n,isInitialized:s,isInitializing:a,user:d,isLoading:l,error:o,isAuthenticated:i,accessToken:E,isExpired:h}=t,c=z(e),g=async()=>{if(!(a.value||s.value))try{a.value=!0,l.value=!0,o.value=null;const k=await n.getUser();if(k)if(!k.expired)d.value=k,t.logger.info("[Vuethenticate] useAuth: User restored from storage");else if(e.automaticSilentRenew!==!1){t.logger.info("[Vuethenticate] useAuth: Token expired, attempting silent renewal");try{await O()}catch(u){t.logger.warn("[Vuethenticate] useAuth: Silent renewal failed during initialization",u),await n.removeUser(),d.value=null}}else await n.removeUser(),d.value=null;s.value=!0}catch(k){t.logger.error("[Vuethenticate] useAuth: Initialization failed",k),U(k,"Authentication initialization failed",o,e.onError)}finally{a.value=!1,l.value=!1}},w=async k=>{try{l.value=!0,o.value=null,t.logger.info("[Vuethenticate] useAuth: Starting sign-in flow"),await n.signinRedirect({state:k})}catch(u){t.logger.error("[Vuethenticate] useAuth: Sign-in failed",u),U(u,"Sign in failed",o,e.onError)}finally{l.value=!1}},A=async k=>{try{l.value=!0,o.value=null,d.value=null,t.logger.info("[Vuethenticate] useAuth: Starting sign-out flow"),await n.signoutRedirect({state:k})}catch(u){t.logger.error("[Vuethenticate] useAuth: Sign-out failed",u),U(u,"Sign out failed",o,e.onError)}finally{l.value=!1}},O=async()=>{try{l.value=!0,o.value=null;const k=await n.signinSilent();d.value=k}catch(k){throw U(k,"Silent renewal failed",o,e.onError)}finally{l.value=!1}},X=()=>{o.value=null},T=(k,u)=>{const{userManager:C,user:R,error:ee,eventCallbacks:y}=k;y.userLoaded=m=>{var v;R.value=m,(v=u.onUserLoaded)==null||v.call(u,m)},y.userUnloaded=()=>{var m;R.value=null,(m=u.onUserUnloaded)==null||m.call(u)},y.accessTokenExpired=()=>{var m;(m=u.onAccessTokenExpired)==null||m.call(u)},y.accessTokenExpiring=()=>{var m;(m=u.onAccessTokenExpiring)==null||m.call(u)},y.silentRenewError=async m=>{console.warn("Silent renewal failed:",m);try{await C.removeUser(),R.value=null}catch(v){console.error("Failed to remove user after silent renewal error:",v)}U(m,"Silent renewal failed",ee,u.onError)},C.events.addUserLoaded(y.userLoaded),C.events.addUserUnloaded(y.userUnloaded),C.events.addAccessTokenExpired(y.accessTokenExpired),C.events.addAccessTokenExpiring(y.accessTokenExpiring),C.events.addSilentRenewError(y.silentRenewError)},Z=()=>{B(t),S.delete(c)};return!s.value&&!a.value&&!j(e)?(g(),T(t,e)):!s.value&&!a.value&&(T(t,e),s.value=!0),{user:d,isAuthenticated:i,isLoading:l,error:o,accessToken:E,isExpired:h,signIn:w,signOut:A,silentRenew:O,clearError:X,cleanup:Z}},L=()=>{const e=W();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async()=>{await N(e),e.logger.info("[Vuethenticate] useAuthCallbacks: Processing authentication callback");const a=await e.userManager.signinCallback();if(!a)throw new Error("Authentication callback failed: no user returned");return e.logger.info("[Vuethenticate] useAuthCallbacks: Authentication callback successful"),{user:a,state:a.state}},processLogoutCallback:async()=>{await N(e),e.logger.debug("[Vuethenticate] useAuthCallbacks: Processing logout callback");const a=await e.userManager.signoutCallback();return e.logger.info("[Vuethenticate] useAuthCallbacks: Logout callback completed successfully"),{state:a==null?void 0:a.userState}},processSilentCallback:async()=>{await N(e),e.logger.debug("[Vuethenticate] useAuthCallbacks: Processing silent callback"),await e.userManager.signinCallback(),e.logger.debug("[Vuethenticate] useAuthCallbacks: Silent callback completed successfully")},isInitialized:e.isInitialized,isInitializing:e.isInitializing,logger:e.logger}},H=r.defineComponent({__name:"AuthCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:t}){const n=e,s=t,{processCallback:a,isInitializing:d,logger:l}=L(),o=r.ref(!0),i=r.ref(null),E=async()=>{var h,c;try{l.info("[Vuethenticate] AuthCallback: Processing authentication callback");const g=await a();l.info("[Vuethenticate] AuthCallback: Authentication callback completed successfully"),(h=n.onSuccess)==null||h.call(n,g.user,g.state),s("success",g.user,g.state)}catch(g){const w=g instanceof Error?g:new Error("Callback processing failed");l.error("[Vuethenticate] AuthCallback: Authentication callback failed",w),i.value=w,(c=n.onError)==null||c.call(n,w),s("error",w)}finally{o.value=!1}};return r.onMounted(()=>{E()}),(h,c)=>(r.openBlock(),r.createElementBlock(r.Fragment,null,[(r.unref(d)||o.value)&&!i.value?r.renderSlot(h.$slots,"default",{key:0},()=>[c[0]||(c[0]=r.createElementVNode("p",null,"Processing authentication...",-1))]):r.createCommentVNode("",!0),i.value?r.renderSlot(h.$slots,"error",{key:1,error:i.value},()=>[r.createElementVNode("div",null,[c[1]||(c[1]=r.createElementVNode("h2",null,"Authentication Error",-1)),r.createElementVNode("p",null,r.toDisplayString(i.value.message),1)])]):r.createCommentVNode("",!0)],64))}}),J=r.defineComponent({__name:"LogoutCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:t}){const n=e,s=t,{processLogoutCallback:a,isInitializing:d,logger:l}=L(),o=r.ref(!0),i=r.ref(null),E=async()=>{var h,c;try{l.info("[Vuethenticate] LogoutCallback: Processing logout callback");const g=await a();l.info("[Vuethenticate] LogoutCallback: Logout callback completed successfully"),(h=n.onSuccess)==null||h.call(n,g.state),s("success",g.state)}catch(g){const w=g instanceof Error?g:new Error("Logout callback processing failed");l.error("[Vuethenticate] LogoutCallback: Logout callback failed",w),i.value=w,(c=n.onError)==null||c.call(n,w),s("error",w)}finally{o.value=!1}};return r.onMounted(()=>{E()}),(h,c)=>(r.unref(d)||o.value)&&!i.value?r.renderSlot(h.$slots,"default",{key:0},()=>[c[0]||(c[0]=r.createElementVNode("p",null,"Processing logout...",-1))]):i.value?r.renderSlot(h.$slots,"error",{key:1,error:i.value},()=>[r.createElementVNode("div",null,[c[1]||(c[1]=r.createElementVNode("h2",null,"Logout Error",-1)),r.createElementVNode("p",null,r.toDisplayString(i.value.message),1)])]):r.renderSlot(h.$slots,"success",{key:2},()=>[c[2]||(c[2]=r.createElementVNode("div",null,[r.createElementVNode("h2",null,"Logout Successful"),r.createElementVNode("p",null,"You have been logged out successfully.")],-1))])}}),Q=r.defineComponent({__name:"SilentCallback",props:{onError:{type:Function}},setup(e){const t=e,{processSilentCallback:n,isInitializing:s,logger:a}=L(),d=r.ref(null),l=async()=>{var o;try{a.debug("[Vuethenticate] SilentCallback: Processing silent callback"),await n()}catch(i){const E=i instanceof Error?i:new Error("Silent callback processing failed");a.error("[Vuethenticate] SilentCallback: Silent callback failed",E),d.value=E,(o=t.onError)==null||o.call(t,E)}};return r.onMounted(()=>{l()}),(o,i)=>(r.openBlock(),r.createElementBlock(r.Fragment,null,[r.unref(s)&&!d.value?r.renderSlot(o.$slots,"default",{key:0},()=>[i[0]||(i[0]=r.createElementVNode("p",null,"Processing silent renewal...",-1))]):r.createCommentVNode("",!0),d.value?r.renderSlot(o.$slots,"error",{key:1,error:d.value},()=>[r.createElementVNode("p",null,"Silent renewal error: "+r.toDisplayString(d.value.message),1)]):r.createCommentVNode("",!0)],64))}});f.AuthCallback=H,f.LogLevel=b,f.LogoutCallback=J,f.SilentCallback=Q,f.consoleLogger=V,f.silentLogger=I,f.useAuth=Y,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
1
|
+
(function(f,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("oidc-client-ts")):typeof define=="function"&&define.amd?define(["exports","vue","oidc-client-ts"],r):(f=typeof globalThis<"u"?globalThis:f||self,r(f.Vuethenticate={},f.Vue,f.OidcClientTs))})(this,function(f,r,p){"use strict";var b=(e=>(e[e.NONE=0]="NONE",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.DEBUG=4]="DEBUG",e))(b||{});const V={error:(e,...t)=>console.error(e,...t),warn:(e,...t)=>console.warn(e,...t),info:(e,...t)=>console.info(e,...t),debug:(e,...t)=>console.debug(e,...t)},I={error:()=>{},warn:()=>{},info:()=>{},debug:()=>{}},x=(e,t)=>({error:t>=1?e.error:()=>{},warn:t>=2?e.warn:()=>{},info:t>=3?e.info:()=>{},debug:t>=4?e.debug:()=>{}});function $(e){const t=typeof window<"u"?window.location.origin:"";return P(e),{authority:e.authority,client_id:e.clientId,client_secret:e.clientSecret,client_authentication:e.clientAuthentication,redirect_uri:e.redirectUri??`${t}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new p.WebStorageStateStore({store:F(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${t}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??`${t}/auth/logout-callback`,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function F(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:t=>e.get(t)??null,setItem:(t,n)=>e.set(t,n),removeItem:t=>e.delete(t),clear:()=>e.clear(),get length(){return e.size},key:t=>Array.from(e.keys())[t]??null}}const P=e=>{if(e.logLevel===void 0&&!e.logger)return;const t=e.logger??(e.logLevel!==void 0?V:void 0),n=e.logLevel??b.NONE;t&&(p.Log.setLogger({error:t.error,warn:t.warn,info:t.info,debug:t.debug}),p.Log.setLevel(_(n)))},_=e=>{switch(e){case b.NONE:return p.Log.NONE;case b.ERROR:return p.Log.ERROR;case b.WARN:return p.Log.WARN;case b.INFO:return p.Log.INFO;case b.DEBUG:return p.Log.DEBUG;default:return p.Log.NONE}},S=new Map,B=e=>{try{const{userManager:t,eventCallbacks:n}=e;n.userLoaded&&t.events.removeUserLoaded(n.userLoaded),n.userUnloaded&&t.events.removeUserUnloaded(n.userUnloaded),n.accessTokenExpired&&t.events.removeAccessTokenExpired(n.accessTokenExpired),n.accessTokenExpiring&&t.events.removeAccessTokenExpiring(n.accessTokenExpiring),n.silentRenewError&&t.events.removeSilentRenewError(n.silentRenewError),t.stopSilentRenew(),t.clearStaleState()}catch(t){console.warn("Error during UserManager cleanup:",t)}},z=e=>`${e.authority}_${e.clientId}`,W=()=>S.size===0?null:(S.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(S.values())[0]||null),D=e=>{const t=z(e),n=S.get(t);if(n)return n;const s=q(e),a=r.ref(!1),d=r.ref(!1),l=r.ref(null),o=r.ref(!1),i=r.ref(null),E=r.computed(()=>!!l.value&&!l.value.expired),h=r.computed(()=>{var A;return((A=l.value)==null?void 0:A.access_token)||null}),c=r.computed(()=>{var A;return!!((A=l.value)!=null&&A.expired)}),g=G(e),w={userManager:s,isInitialized:a,isInitializing:d,user:l,isLoading:o,error:i,isAuthenticated:E,accessToken:h,isExpired:c,logger:g,eventCallbacks:{}};return S.set(t,w),w},q=e=>{const t=$(e);return new p.UserManager(t)},G=e=>{if(!e.logger&&!e.logLevel)return I;const t=e.logger??V,n=e.logLevel??b.NONE;return x(t,n)},U=(e,t,n,s)=>{const a=e instanceof Error?e:new Error(t);return n.value=a,s==null||s(a),a},K=e=>{var t,n;if(!((t=e.authority)!=null&&t.trim()))throw new Error("AuthConfig: authority is required");if(!((n=e.clientId)!=null&&n.trim()))throw new Error("AuthConfig: clientId is required");try{new URL(e.authority)}catch{throw new Error("AuthConfig: authority must be a valid URL")}},N=async(e,t=1e4)=>{if(!e.isInitialized.value)return new Promise((n,s)=>{const a=setTimeout(()=>{s(new Error("Authentication initialization timeout"))},t),d=r.watch(e.isInitialized,l=>{l&&(clearTimeout(a),d(),n())},{immediate:!0})})},j=e=>{const t=window.location.href;return!!(e.silentRedirectUri&&t.startsWith(e.silentRedirectUri)||e.redirectUri&&t.startsWith(e.redirectUri)||e.postLogoutRedirectUri&&t.startsWith(e.postLogoutRedirectUri))},Y=e=>{K(e);const t=D(e),{userManager:n,isInitialized:s,isInitializing:a,user:d,isLoading:l,error:o,isAuthenticated:i,accessToken:E,isExpired:h}=t,c=z(e),g=async()=>{if(!(a.value||s.value))try{a.value=!0,l.value=!0,o.value=null;const k=await n.getUser();if(k)if(!k.expired)d.value=k,t.logger.info("[Vuethenticate] useAuth: User restored from storage");else if(e.automaticSilentRenew!==!1){t.logger.info("[Vuethenticate] useAuth: Token expired, attempting silent renewal");try{await O()}catch(u){t.logger.warn("[Vuethenticate] useAuth: Silent renewal failed during initialization",u),await n.removeUser(),d.value=null}}else await n.removeUser(),d.value=null;s.value=!0}catch(k){t.logger.error("[Vuethenticate] useAuth: Initialization failed",k),U(k,"Authentication initialization failed",o,e.onError)}finally{a.value=!1,l.value=!1}},w=async k=>{try{l.value=!0,o.value=null,t.logger.info("[Vuethenticate] useAuth: Starting sign-in flow"),await n.signinRedirect({state:k})}catch(u){t.logger.error("[Vuethenticate] useAuth: Sign-in failed",u),U(u,"Sign in failed",o,e.onError)}finally{l.value=!1}},A=async k=>{try{l.value=!0,o.value=null,d.value=null,t.logger.info("[Vuethenticate] useAuth: Starting sign-out flow"),await n.signoutRedirect({state:k})}catch(u){t.logger.error("[Vuethenticate] useAuth: Sign-out failed",u),U(u,"Sign out failed",o,e.onError)}finally{l.value=!1}},O=async()=>{try{l.value=!0,o.value=null;const k=await n.signinSilent();d.value=k}catch(k){throw U(k,"Silent renewal failed",o,e.onError)}finally{l.value=!1}},X=()=>{o.value=null},T=(k,u)=>{const{userManager:C,user:R,error:ee,eventCallbacks:y}=k;y.userLoaded=m=>{var v;R.value=m,(v=u.onUserLoaded)==null||v.call(u,m)},y.userUnloaded=()=>{var m;R.value=null,(m=u.onUserUnloaded)==null||m.call(u)},y.accessTokenExpired=()=>{var m;(m=u.onAccessTokenExpired)==null||m.call(u)},y.accessTokenExpiring=()=>{var m;(m=u.onAccessTokenExpiring)==null||m.call(u)},y.silentRenewError=async m=>{console.warn("Silent renewal failed:",m);try{await C.removeUser(),R.value=null}catch(v){console.error("Failed to remove user after silent renewal error:",v)}U(m,"Silent renewal failed",ee,u.onError)},C.events.addUserLoaded(y.userLoaded),C.events.addUserUnloaded(y.userUnloaded),C.events.addAccessTokenExpired(y.accessTokenExpired),C.events.addAccessTokenExpiring(y.accessTokenExpiring),C.events.addSilentRenewError(y.silentRenewError)},Z=()=>{B(t),S.delete(c)};return!s.value&&!a.value&&!j(e)?(g(),T(t,e)):!s.value&&!a.value&&(T(t,e),s.value=!0),{user:d,isAuthenticated:i,isLoading:l,isInitialized:s,error:o,accessToken:E,isExpired:h,signIn:w,signOut:A,silentRenew:O,clearError:X,cleanup:Z}},L=()=>{const e=W();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async()=>{await N(e),e.logger.info("[Vuethenticate] useAuthCallbacks: Processing authentication callback");const a=await e.userManager.signinCallback();if(!a)throw new Error("Authentication callback failed: no user returned");return e.logger.info("[Vuethenticate] useAuthCallbacks: Authentication callback successful"),{user:a,state:a.state}},processLogoutCallback:async()=>{await N(e),e.logger.debug("[Vuethenticate] useAuthCallbacks: Processing logout callback");const a=await e.userManager.signoutCallback();return e.logger.info("[Vuethenticate] useAuthCallbacks: Logout callback completed successfully"),{state:a==null?void 0:a.userState}},processSilentCallback:async()=>{await N(e),e.logger.debug("[Vuethenticate] useAuthCallbacks: Processing silent callback"),await e.userManager.signinCallback(),e.logger.debug("[Vuethenticate] useAuthCallbacks: Silent callback completed successfully")},isInitialized:e.isInitialized,isInitializing:e.isInitializing,logger:e.logger}},H=r.defineComponent({__name:"AuthCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:t}){const n=e,s=t,{processCallback:a,isInitializing:d,logger:l}=L(),o=r.ref(!0),i=r.ref(null),E=async()=>{var h,c;try{l.info("[Vuethenticate] AuthCallback: Processing authentication callback");const g=await a();l.info("[Vuethenticate] AuthCallback: Authentication callback completed successfully"),(h=n.onSuccess)==null||h.call(n,g.user,g.state),s("success",g.user,g.state)}catch(g){const w=g instanceof Error?g:new Error("Callback processing failed");l.error("[Vuethenticate] AuthCallback: Authentication callback failed",w),i.value=w,(c=n.onError)==null||c.call(n,w),s("error",w)}finally{o.value=!1}};return r.onMounted(()=>{E()}),(h,c)=>(r.openBlock(),r.createElementBlock(r.Fragment,null,[(r.unref(d)||o.value)&&!i.value?r.renderSlot(h.$slots,"default",{key:0},()=>[c[0]||(c[0]=r.createElementVNode("p",null,"Processing authentication...",-1))]):r.createCommentVNode("",!0),i.value?r.renderSlot(h.$slots,"error",{key:1,error:i.value},()=>[r.createElementVNode("div",null,[c[1]||(c[1]=r.createElementVNode("h2",null,"Authentication Error",-1)),r.createElementVNode("p",null,r.toDisplayString(i.value.message),1)])]):r.createCommentVNode("",!0)],64))}}),J=r.defineComponent({__name:"LogoutCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:t}){const n=e,s=t,{processLogoutCallback:a,isInitializing:d,logger:l}=L(),o=r.ref(!0),i=r.ref(null),E=async()=>{var h,c;try{l.info("[Vuethenticate] LogoutCallback: Processing logout callback");const g=await a();l.info("[Vuethenticate] LogoutCallback: Logout callback completed successfully"),(h=n.onSuccess)==null||h.call(n,g.state),s("success",g.state)}catch(g){const w=g instanceof Error?g:new Error("Logout callback processing failed");l.error("[Vuethenticate] LogoutCallback: Logout callback failed",w),i.value=w,(c=n.onError)==null||c.call(n,w),s("error",w)}finally{o.value=!1}};return r.onMounted(()=>{E()}),(h,c)=>(r.unref(d)||o.value)&&!i.value?r.renderSlot(h.$slots,"default",{key:0},()=>[c[0]||(c[0]=r.createElementVNode("p",null,"Processing logout...",-1))]):i.value?r.renderSlot(h.$slots,"error",{key:1,error:i.value},()=>[r.createElementVNode("div",null,[c[1]||(c[1]=r.createElementVNode("h2",null,"Logout Error",-1)),r.createElementVNode("p",null,r.toDisplayString(i.value.message),1)])]):r.renderSlot(h.$slots,"success",{key:2},()=>[c[2]||(c[2]=r.createElementVNode("div",null,[r.createElementVNode("h2",null,"Logout Successful"),r.createElementVNode("p",null,"You have been logged out successfully.")],-1))])}}),Q=r.defineComponent({__name:"SilentCallback",props:{onError:{type:Function}},setup(e){const t=e,{processSilentCallback:n,isInitializing:s,logger:a}=L(),d=r.ref(null),l=async()=>{var o;try{a.debug("[Vuethenticate] SilentCallback: Processing silent callback"),await n()}catch(i){const E=i instanceof Error?i:new Error("Silent callback processing failed");a.error("[Vuethenticate] SilentCallback: Silent callback failed",E),d.value=E,(o=t.onError)==null||o.call(t,E)}};return r.onMounted(()=>{l()}),(o,i)=>(r.openBlock(),r.createElementBlock(r.Fragment,null,[r.unref(s)&&!d.value?r.renderSlot(o.$slots,"default",{key:0},()=>[i[0]||(i[0]=r.createElementVNode("p",null,"Processing silent renewal...",-1))]):r.createCommentVNode("",!0),d.value?r.renderSlot(o.$slots,"error",{key:1,error:d.value},()=>[r.createElementVNode("p",null,"Silent renewal error: "+r.toDisplayString(d.value.message),1)]):r.createCommentVNode("",!0)],64))}});f.AuthCallback=H,f.LogLevel=b,f.LogoutCallback=J,f.SilentCallback=Q,f.consoleLogger=V,f.silentLogger=I,f.useAuth=Y,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
|
package/dist/types/auth.d.ts
CHANGED
@@ -24,6 +24,7 @@ export interface AuthConfig {
|
|
24
24
|
export interface AuthState {
|
25
25
|
user: Ref<User | null>;
|
26
26
|
isLoading: Ref<boolean>;
|
27
|
+
isInitialized: Ref<boolean>;
|
27
28
|
error: Ref<Error | null>;
|
28
29
|
isAuthenticated: ComputedRef<boolean>;
|
29
30
|
accessToken: ComputedRef<string | null>;
|
package/dist/types/auth.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC5C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,WAAW,UAA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