vuethenticate 0.1.2 → 0.1.4

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.
@@ -13,11 +13,11 @@ export declare const useAuth: <TState = unknown>(config: AuthConfig) => UseAuthR
13
13
  * @returns Callback processing methods and initialization state
14
14
  */
15
15
  export declare const useAuthCallbacks: <TState = unknown>() => {
16
- processCallback: (url?: string) => Promise<{
16
+ processCallback: () => Promise<{
17
17
  user: User;
18
18
  state?: TState;
19
19
  }>;
20
- processSilentCallback: (url?: string) => Promise<void>;
20
+ processSilentCallback: () => Promise<void>;
21
21
  isInitialized: Ref<boolean, boolean>;
22
22
  isInitializing: Ref<boolean, boolean>;
23
23
  };
@@ -1 +1 @@
1
- {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAoB,KAAK,GAAG,EAAwB,MAAM,KAAK,CAAC;AACvE,OAAO,EAAE,KAAK,IAAI,EAAe,MAAM,gBAAgB,CAAC;AAwNxD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,OAAO,EACpC,QAAQ,UAAU,KACnB,aAAa,CAAC,MAAM,CAsNtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,OAAO;4BAenC,MAAM,KACb,OAAO,CAAC;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;kCAiBC,MAAM,KAAG,OAAO,CAAC,IAAI,CAAC;;;CAapE,CAAC"}
1
+ {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAoB,KAAK,GAAG,EAAwB,MAAM,KAAK,CAAC;AACvE,OAAO,EAAE,KAAK,IAAI,EAAe,MAAM,gBAAgB,CAAC;AAwNxD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,OAAO,EACpC,QAAQ,UAAU,KACnB,aAAa,CAAC,MAAM,CAsNtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,GAAG,OAAO;2BAaX,OAAO,CAAC;QACtC,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;iCAiBsC,OAAO,CAAC,IAAI,CAAC;;;CAYxD,CAAC"}
package/dist/index.esm.js CHANGED
@@ -6,7 +6,7 @@ function H(e) {
6
6
  authority: e.authority,
7
7
  client_id: e.clientId,
8
8
  client_secret: e.clientSecret,
9
- client_authentication: e.clientAuthentication ?? "client_secret_basic",
9
+ client_authentication: e.clientAuthentication,
10
10
  redirect_uri: e.redirectUri ?? `${r}/auth/callback`,
11
11
  scope: e.scope ?? "openid profile",
12
12
  response_type: e.responseType ?? "code",
@@ -45,7 +45,7 @@ function T() {
45
45
  key: (r) => Array.from(e.keys())[r] ?? null
46
46
  };
47
47
  }
48
- const E = /* @__PURE__ */ new Map(), Q = (e) => {
48
+ const h = /* @__PURE__ */ new Map(), Q = (e) => {
49
49
  try {
50
50
  const { userManager: r, eventCallbacks: t } = e;
51
51
  t.userLoaded && r.events.removeUserLoaded(t.userLoaded), t.userUnloaded && r.events.removeUserUnloaded(t.userUnloaded), t.accessTokenExpired && r.events.removeAccessTokenExpired(
@@ -58,37 +58,37 @@ const E = /* @__PURE__ */ new Map(), Q = (e) => {
58
58
  } catch (r) {
59
59
  console.warn("Error during UserManager cleanup:", r);
60
60
  }
61
- }, K = (e) => `${e.authority}_${e.clientId}`, X = () => E.size === 0 ? null : (E.size === 1 || console.warn(
61
+ }, K = (e) => `${e.authority}_${e.clientId}`, X = () => h.size === 0 ? null : (h.size === 1 || console.warn(
62
62
  "Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."
63
- ), Array.from(E.values())[0] || null), Y = (e) => {
64
- const r = K(e), t = E.get(r);
63
+ ), Array.from(h.values())[0] || null), Y = (e) => {
64
+ const r = K(e), t = h.get(r);
65
65
  if (t)
66
66
  return t;
67
- const l = Z(e), a = m(!1), o = m(!1), n = m(null), s = m(!1), p = m(null), y = I(() => !!n.value && !n.value.expired), d = I(() => {
68
- var h;
69
- return ((h = n.value) == null ? void 0 : h.access_token) || null;
70
- }), w = I(() => {
71
- var h;
72
- return !!((h = n.value) != null && h.expired);
67
+ const s = Z(e), i = m(!1), u = m(!1), n = m(null), a = m(!1), p = m(null), y = I(() => !!n.value && !n.value.expired), d = I(() => {
68
+ var E;
69
+ return ((E = n.value) == null ? void 0 : E.access_token) || null;
70
+ }), v = I(() => {
71
+ var E;
72
+ return !!((E = n.value) != null && E.expired);
73
73
  }), k = {
74
- userManager: l,
75
- isInitialized: a,
76
- isInitializing: o,
74
+ userManager: s,
75
+ isInitialized: i,
76
+ isInitializing: u,
77
77
  user: n,
78
- isLoading: s,
78
+ isLoading: a,
79
79
  error: p,
80
80
  isAuthenticated: y,
81
81
  accessToken: d,
82
- isExpired: w,
82
+ isExpired: v,
83
83
  eventCallbacks: {}
84
84
  };
85
- return E.set(r, k), k;
85
+ return h.set(r, k), k;
86
86
  }, Z = (e) => {
87
87
  const r = H(e);
88
88
  return new G(r);
89
- }, f = (e, r, t, l) => {
90
- const a = e instanceof Error ? e : new Error(r);
91
- return t.value = a, l == null || l(a), a;
89
+ }, f = (e, r, t, s) => {
90
+ const i = e instanceof Error ? e : new Error(r);
91
+ return t.value = i, s == null || s(i), i;
92
92
  }, ee = (e) => {
93
93
  var r, t;
94
94
  if (!((r = e.authority) != null && r.trim()))
@@ -102,13 +102,13 @@ const E = /* @__PURE__ */ new Map(), Q = (e) => {
102
102
  }
103
103
  }, z = async (e, r = 1e4) => {
104
104
  if (!e.isInitialized.value)
105
- return new Promise((t, l) => {
106
- const a = setTimeout(() => {
107
- l(new Error("Authentication initialization timeout"));
108
- }, r), o = W(
105
+ return new Promise((t, s) => {
106
+ const i = setTimeout(() => {
107
+ s(new Error("Authentication initialization timeout"));
108
+ }, r), u = W(
109
109
  e.isInitialized,
110
110
  (n) => {
111
- n && (clearTimeout(a), o(), t());
111
+ n && (clearTimeout(i), u(), t());
112
112
  },
113
113
  { immediate: !0 }
114
114
  );
@@ -117,92 +117,92 @@ const E = /* @__PURE__ */ new Map(), Q = (e) => {
117
117
  ee(e);
118
118
  const r = Y(e), {
119
119
  userManager: t,
120
- isInitialized: l,
121
- isInitializing: a,
122
- user: o,
120
+ isInitialized: s,
121
+ isInitializing: i,
122
+ user: u,
123
123
  isLoading: n,
124
- error: s,
124
+ error: a,
125
125
  isAuthenticated: p,
126
126
  accessToken: y,
127
127
  isExpired: d
128
- } = r, w = K(e), k = async () => {
129
- if (!(a.value || l.value))
128
+ } = r, v = K(e), k = async () => {
129
+ if (!(i.value || s.value))
130
130
  try {
131
- a.value = !0, n.value = !0, s.value = null;
132
- const c = await t.getUser();
133
- if (c)
134
- if (!c.expired)
135
- o.value = c;
131
+ i.value = !0, n.value = !0, a.value = null;
132
+ const o = await t.getUser();
133
+ if (o)
134
+ if (!o.expired)
135
+ u.value = o;
136
136
  else if (e.automaticSilentRenew !== !1)
137
137
  try {
138
138
  await x();
139
- } catch (i) {
139
+ } catch (l) {
140
140
  console.warn(
141
141
  "Silent renewal failed during initialization:",
142
- i
143
- ), await t.removeUser(), o.value = null;
142
+ l
143
+ ), await t.removeUser(), u.value = null;
144
144
  }
145
145
  else
146
- await t.removeUser(), o.value = null;
147
- } catch (c) {
146
+ await t.removeUser(), u.value = null;
147
+ } catch (o) {
148
148
  f(
149
- c,
149
+ o,
150
150
  "Failed to initialize authentication",
151
- s,
151
+ a,
152
152
  e.onError
153
153
  );
154
154
  } finally {
155
- n.value = !1, a.value = !1, l.value = !0;
155
+ n.value = !1, i.value = !1, s.value = !0;
156
156
  }
157
- }, h = async (c) => {
157
+ }, E = async (o) => {
158
158
  try {
159
- n.value = !0, s.value = null, await t.signinRedirect({ state: c });
160
- } catch (i) {
161
- f(i, "Sign in failed", s, e.onError);
159
+ n.value = !0, a.value = null, await t.signinRedirect({ state: o });
160
+ } catch (l) {
161
+ f(l, "Sign in failed", a, e.onError);
162
162
  } finally {
163
163
  n.value = !1;
164
164
  }
165
- }, q = async (c) => {
165
+ }, q = async (o) => {
166
166
  try {
167
- n.value = !0, s.value = null, o.value = null, await t.signoutRedirect({ state: c });
168
- } catch (i) {
169
- f(i, "Sign out failed", s, e.onError);
167
+ n.value = !0, a.value = null, u.value = null, await t.signoutRedirect({ state: o });
168
+ } catch (l) {
169
+ f(l, "Sign out failed", a, e.onError);
170
170
  } finally {
171
171
  n.value = !1;
172
172
  }
173
173
  }, x = async () => {
174
174
  try {
175
- n.value = !0, s.value = null;
176
- const c = await t.signinSilent();
177
- o.value = c;
178
- } catch (c) {
175
+ n.value = !0, a.value = null;
176
+ const o = await t.signinSilent();
177
+ u.value = o;
178
+ } catch (o) {
179
179
  throw f(
180
- c,
180
+ o,
181
181
  "Silent renewal failed",
182
- s,
182
+ a,
183
183
  e.onError
184
184
  );
185
185
  } finally {
186
186
  n.value = !1;
187
187
  }
188
188
  }, B = () => {
189
- s.value = null;
190
- }, O = (c, i) => {
191
- const { userManager: g, user: A, error: D, eventCallbacks: v } = c;
192
- v.userLoaded = (u) => {
189
+ a.value = null;
190
+ }, O = (o, l) => {
191
+ const { userManager: g, user: A, error: D, eventCallbacks: w } = o;
192
+ w.userLoaded = (c) => {
193
193
  var U;
194
- A.value = u, (U = i.onUserLoaded) == null || U.call(i, u);
195
- }, v.userUnloaded = () => {
196
- var u;
197
- A.value = null, (u = i.onUserUnloaded) == null || u.call(i);
198
- }, v.accessTokenExpired = () => {
199
- var u;
200
- (u = i.onAccessTokenExpired) == null || u.call(i);
201
- }, v.accessTokenExpiring = () => {
202
- var u;
203
- (u = i.onAccessTokenExpiring) == null || u.call(i);
204
- }, v.silentRenewError = async (u) => {
205
- console.warn("Silent renewal failed:", u);
194
+ A.value = c, (U = l.onUserLoaded) == null || U.call(l, c);
195
+ }, w.userUnloaded = () => {
196
+ var c;
197
+ A.value = null, (c = l.onUserUnloaded) == null || c.call(l);
198
+ }, w.accessTokenExpired = () => {
199
+ var c;
200
+ (c = l.onAccessTokenExpired) == null || c.call(l);
201
+ }, w.accessTokenExpiring = () => {
202
+ var c;
203
+ (c = l.onAccessTokenExpiring) == null || c.call(l);
204
+ }, w.silentRenewError = async (c) => {
205
+ console.warn("Silent renewal failed:", c);
206
206
  try {
207
207
  await g.removeUser(), A.value = null;
208
208
  } catch (U) {
@@ -212,27 +212,27 @@ const E = /* @__PURE__ */ new Map(), Q = (e) => {
212
212
  );
213
213
  }
214
214
  f(
215
- u,
215
+ c,
216
216
  "Silent renewal failed",
217
217
  D,
218
- i.onError
218
+ l.onError
219
219
  );
220
- }, g.events.addUserLoaded(v.userLoaded), g.events.addUserUnloaded(v.userUnloaded), g.events.addAccessTokenExpired(
221
- v.accessTokenExpired
220
+ }, g.events.addUserLoaded(w.userLoaded), g.events.addUserUnloaded(w.userUnloaded), g.events.addAccessTokenExpired(
221
+ w.accessTokenExpired
222
222
  ), g.events.addAccessTokenExpiring(
223
- v.accessTokenExpiring
224
- ), g.events.addSilentRenewError(v.silentRenewError);
223
+ w.accessTokenExpiring
224
+ ), g.events.addSilentRenewError(w.silentRenewError);
225
225
  }, V = () => {
226
- Q(r), E.delete(w);
226
+ Q(r), h.delete(v);
227
227
  };
228
- return !l.value && !a.value && (k(), O(r, e)), {
229
- user: o,
228
+ return !s.value && !i.value && (k(), O(r, e)), {
229
+ user: u,
230
230
  isAuthenticated: p,
231
231
  isLoading: n,
232
- error: s,
232
+ error: a,
233
233
  accessToken: y,
234
234
  isExpired: d,
235
- signIn: h,
235
+ signIn: E,
236
236
  signOut: q,
237
237
  silentRenew: x,
238
238
  clearError: B,
@@ -245,18 +245,18 @@ const E = /* @__PURE__ */ new Map(), Q = (e) => {
245
245
  "Authentication not initialized. Make sure useAuth() is called in a parent component first."
246
246
  );
247
247
  return {
248
- processCallback: async (l) => {
248
+ processCallback: async () => {
249
249
  await z(e);
250
- const a = l || window.location.href, o = await e.userManager.signinRedirectCallback(a);
250
+ const s = await e.userManager.signinCallback();
251
+ if (!s)
252
+ throw new Error("Authentication callback failed: no user returned");
251
253
  return {
252
- user: o,
253
- state: o.state
254
+ user: s,
255
+ state: s.state
254
256
  };
255
257
  },
256
- processSilentCallback: async (l) => {
257
- await z(e);
258
- const a = l || window.location.href;
259
- await e.userManager.signinSilentCallback(a);
258
+ processSilentCallback: async () => {
259
+ await z(e), await e.userManager.signinCallback();
260
260
  },
261
261
  isInitialized: e.isInitialized,
262
262
  isInitializing: e.isInitializing
@@ -269,14 +269,14 @@ const E = /* @__PURE__ */ new Map(), Q = (e) => {
269
269
  },
270
270
  emits: ["success", "error"],
271
271
  setup(e, { emit: r }) {
272
- const t = e, l = r, { processCallback: a, isInitializing: o } = N(), n = m(!0), s = m(null), p = async () => {
272
+ const t = e, s = r, { processCallback: i, isInitializing: u } = N(), n = m(!0), a = m(null), p = async () => {
273
273
  var y, d;
274
274
  try {
275
- const w = await a();
276
- (y = t.onSuccess) == null || y.call(t, w.user, w.state), l("success", w.user, w.state);
277
- } catch (w) {
278
- const k = w instanceof Error ? w : new Error("Callback processing failed");
279
- s.value = k, (d = t.onError) == null || d.call(t, k), l("error", k);
275
+ const v = await i();
276
+ (y = t.onSuccess) == null || y.call(t, v.user, v.state), s("success", v.user, v.state);
277
+ } catch (v) {
278
+ const k = v instanceof Error ? v : new Error("Callback processing failed");
279
+ a.value = k, (d = t.onError) == null || d.call(t, k), s("error", k);
280
280
  } finally {
281
281
  n.value = !1;
282
282
  }
@@ -284,16 +284,16 @@ const E = /* @__PURE__ */ new Map(), Q = (e) => {
284
284
  return R(() => {
285
285
  p();
286
286
  }), (y, d) => (L(), _($, null, [
287
- (F(o) || n.value) && !s.value ? b(y.$slots, "default", { key: 0 }, () => [
287
+ (F(u) || n.value) && !a.value ? b(y.$slots, "default", { key: 0 }, () => [
288
288
  d[0] || (d[0] = S("p", null, "Processing authentication...", -1))
289
289
  ]) : C("", !0),
290
- s.value ? b(y.$slots, "error", {
290
+ a.value ? b(y.$slots, "error", {
291
291
  key: 1,
292
- error: s.value
292
+ error: a.value
293
293
  }, () => [
294
294
  S("div", null, [
295
295
  d[1] || (d[1] = S("h2", null, "Authentication Error", -1)),
296
- S("p", null, P(s.value.message), 1)
296
+ S("p", null, P(a.value.message), 1)
297
297
  ])
298
298
  ]) : C("", !0)
299
299
  ], 64));
@@ -304,26 +304,26 @@ const E = /* @__PURE__ */ new Map(), Q = (e) => {
304
304
  onError: { type: Function }
305
305
  },
306
306
  setup(e) {
307
- const r = e, { processSilentCallback: t, isInitializing: l } = N(), a = m(null), o = async () => {
307
+ const r = e, { processSilentCallback: t, isInitializing: s } = N(), i = m(null), u = async () => {
308
308
  var n;
309
309
  try {
310
310
  await t();
311
- } catch (s) {
312
- const p = s instanceof Error ? s : new Error("Silent callback processing failed");
313
- a.value = p, (n = r.onError) == null || n.call(r, p), console.error("Silent callback error:", p);
311
+ } catch (a) {
312
+ const p = a instanceof Error ? a : new Error("Silent callback processing failed");
313
+ i.value = p, (n = r.onError) == null || n.call(r, p), console.error("Silent callback error:", p);
314
314
  }
315
315
  };
316
316
  return R(() => {
317
- o();
318
- }), (n, s) => (L(), _($, null, [
319
- F(l) && !a.value ? b(n.$slots, "default", { key: 0 }, () => [
320
- s[0] || (s[0] = S("p", null, "Processing silent renewal...", -1))
317
+ u();
318
+ }), (n, a) => (L(), _($, null, [
319
+ F(s) && !i.value ? b(n.$slots, "default", { key: 0 }, () => [
320
+ a[0] || (a[0] = S("p", null, "Processing silent renewal...", -1))
321
321
  ]) : C("", !0),
322
- a.value ? b(n.$slots, "error", {
322
+ i.value ? b(n.$slots, "error", {
323
323
  key: 1,
324
- error: a.value
324
+ error: i.value
325
325
  }, () => [
326
- S("p", null, "Silent renewal error: " + P(a.value.message), 1)
326
+ S("p", null, "Silent renewal error: " + P(i.value.message), 1)
327
327
  ]) : C("", !0)
328
328
  ], 64));
329
329
  }
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(m,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):(m=typeof globalThis<"u"?globalThis:m||self,t(m.Vuethenticate={},m.Vue,m.OidcClientTs))})(this,function(m,t,U){"use strict";function z(e){const r=typeof window<"u"?window.location.origin:"";return{authority:e.authority,client_id:e.clientId,client_secret:e.clientSecret,client_authentication:e.clientAuthentication??"client_secret_basic",redirect_uri:e.redirectUri??`${r}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new U.WebStorageStateStore({store:R(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${r}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??r,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function R(e){if(typeof window>"u")return A();switch(e){case"localStorage":return window.localStorage;case"sessionStorage":return window.sessionStorage;case"memory":return A();default:return window.localStorage}}function A(){const e=new Map;return{getItem:r=>e.get(r)??null,setItem:(r,n)=>e.set(r,n),removeItem:r=>e.delete(r),clear:()=>e.clear(),get length(){return e.size},key:r=>Array.from(e.keys())[r]??null}}const f=new Map,_=e=>{try{const{userManager:r,eventCallbacks:n}=e;n.userLoaded&&r.events.removeUserLoaded(n.userLoaded),n.userUnloaded&&r.events.removeUserUnloaded(n.userUnloaded),n.accessTokenExpired&&r.events.removeAccessTokenExpired(n.accessTokenExpired),n.accessTokenExpiring&&r.events.removeAccessTokenExpiring(n.accessTokenExpiring),n.silentRenewError&&r.events.removeSilentRenewError(n.silentRenewError),r.stopSilentRenew(),r.clearStaleState()}catch(r){console.warn("Error during UserManager cleanup:",r)}},T=e=>`${e.authority}_${e.clientId}`,L=()=>f.size===0?null:(f.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(f.values())[0]||null),V=e=>{const r=T(e),n=f.get(r);if(n)return n;const l=N(e),s=t.ref(!1),c=t.ref(!1),a=t.ref(null),i=t.ref(!1),k=t.ref(null),E=t.computed(()=>!!a.value&&!a.value.expired),w=t.computed(()=>{var S;return((S=a.value)==null?void 0:S.access_token)||null}),p=t.computed(()=>{var S;return!!((S=a.value)!=null&&S.expired)}),h={userManager:l,isInitialized:s,isInitializing:c,user:a,isLoading:i,error:k,isAuthenticated:E,accessToken:w,isExpired:p,eventCallbacks:{}};return f.set(r,h),h},N=e=>{const r=z(e);return new U.UserManager(r)},v=(e,r,n,l)=>{const s=e instanceof Error?e:new Error(r);return n.value=s,l==null||l(s),s},$=e=>{var r,n;if(!((r=e.authority)!=null&&r.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")}},I=async(e,r=1e4)=>{if(!e.isInitialized.value)return new Promise((n,l)=>{const s=setTimeout(()=>{l(new Error("Authentication initialization timeout"))},r),c=t.watch(e.isInitialized,a=>{a&&(clearTimeout(s),c(),n())},{immediate:!0})})},F=e=>{$(e);const r=V(e),{userManager:n,isInitialized:l,isInitializing:s,user:c,isLoading:a,error:i,isAuthenticated:k,accessToken:E,isExpired:w}=r,p=T(e),h=async()=>{if(!(s.value||l.value))try{s.value=!0,a.value=!0,i.value=null;const u=await n.getUser();if(u)if(!u.expired)c.value=u;else if(e.automaticSilentRenew!==!1)try{await x()}catch(o){console.warn("Silent renewal failed during initialization:",o),await n.removeUser(),c.value=null}else await n.removeUser(),c.value=null}catch(u){v(u,"Failed to initialize authentication",i,e.onError)}finally{a.value=!1,s.value=!1,l.value=!0}},S=async u=>{try{a.value=!0,i.value=null,await n.signinRedirect({state:u})}catch(o){v(o,"Sign in failed",i,e.onError)}finally{a.value=!1}},B=async u=>{try{a.value=!0,i.value=null,c.value=null,await n.signoutRedirect({state:u})}catch(o){v(o,"Sign out failed",i,e.onError)}finally{a.value=!1}},x=async()=>{try{a.value=!0,i.value=null;const u=await n.signinSilent();c.value=u}catch(u){throw v(u,"Silent renewal failed",i,e.onError)}finally{a.value=!1}},O=()=>{i.value=null},K=(u,o)=>{const{userManager:g,user:b,error:D,eventCallbacks:y}=u;y.userLoaded=d=>{var C;b.value=d,(C=o.onUserLoaded)==null||C.call(o,d)},y.userUnloaded=()=>{var d;b.value=null,(d=o.onUserUnloaded)==null||d.call(o)},y.accessTokenExpired=()=>{var d;(d=o.onAccessTokenExpired)==null||d.call(o)},y.accessTokenExpiring=()=>{var d;(d=o.onAccessTokenExpiring)==null||d.call(o)},y.silentRenewError=async d=>{console.warn("Silent renewal failed:",d);try{await g.removeUser(),b.value=null}catch(C){console.error("Failed to remove user after silent renewal error:",C)}v(d,"Silent renewal failed",D,o.onError)},g.events.addUserLoaded(y.userLoaded),g.events.addUserUnloaded(y.userUnloaded),g.events.addAccessTokenExpired(y.accessTokenExpired),g.events.addAccessTokenExpiring(y.accessTokenExpiring),g.events.addSilentRenewError(y.silentRenewError)},j=()=>{_(r),f.delete(p)};return!l.value&&!s.value&&(h(),K(r,e)),{user:c,isAuthenticated:k,isLoading:a,error:i,accessToken:E,isExpired:w,signIn:S,signOut:B,silentRenew:x,clearError:O,cleanup:j}},M=()=>{const e=L();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async l=>{await I(e);const s=l||window.location.href,c=await e.userManager.signinRedirectCallback(s);return{user:c,state:c.state}},processSilentCallback:async l=>{await I(e);const s=l||window.location.href;await e.userManager.signinSilentCallback(s)},isInitialized:e.isInitialized,isInitializing:e.isInitializing}},P=t.defineComponent({__name:"AuthCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:r}){const n=e,l=r,{processCallback:s,isInitializing:c}=M(),a=t.ref(!0),i=t.ref(null),k=async()=>{var E,w;try{const p=await s();(E=n.onSuccess)==null||E.call(n,p.user,p.state),l("success",p.user,p.state)}catch(p){const h=p instanceof Error?p:new Error("Callback processing failed");i.value=h,(w=n.onError)==null||w.call(n,h),l("error",h)}finally{a.value=!1}};return t.onMounted(()=>{k()}),(E,w)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[(t.unref(c)||a.value)&&!i.value?t.renderSlot(E.$slots,"default",{key:0},()=>[w[0]||(w[0]=t.createElementVNode("p",null,"Processing authentication...",-1))]):t.createCommentVNode("",!0),i.value?t.renderSlot(E.$slots,"error",{key:1,error:i.value},()=>[t.createElementVNode("div",null,[w[1]||(w[1]=t.createElementVNode("h2",null,"Authentication Error",-1)),t.createElementVNode("p",null,t.toDisplayString(i.value.message),1)])]):t.createCommentVNode("",!0)],64))}}),q=t.defineComponent({__name:"SilentCallback",props:{onError:{type:Function}},setup(e){const r=e,{processSilentCallback:n,isInitializing:l}=M(),s=t.ref(null),c=async()=>{var a;try{await n()}catch(i){const k=i instanceof Error?i:new Error("Silent callback processing failed");s.value=k,(a=r.onError)==null||a.call(r,k),console.error("Silent callback error:",k)}};return t.onMounted(()=>{c()}),(a,i)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.unref(l)&&!s.value?t.renderSlot(a.$slots,"default",{key:0},()=>[i[0]||(i[0]=t.createElementVNode("p",null,"Processing silent renewal...",-1))]):t.createCommentVNode("",!0),s.value?t.renderSlot(a.$slots,"error",{key:1,error:s.value},()=>[t.createElementVNode("p",null,"Silent renewal error: "+t.toDisplayString(s.value.message),1)]):t.createCommentVNode("",!0)],64))}});m.AuthCallback=P,m.SilentCallback=q,m.useAuth=F,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
1
+ (function(m,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):(m=typeof globalThis<"u"?globalThis:m||self,t(m.Vuethenticate={},m.Vue,m.OidcClientTs))})(this,function(m,t,U){"use strict";function z(e){const r=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??`${r}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new U.WebStorageStateStore({store:R(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${r}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??r,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function R(e){if(typeof window>"u")return A();switch(e){case"localStorage":return window.localStorage;case"sessionStorage":return window.sessionStorage;case"memory":return A();default:return window.localStorage}}function A(){const e=new Map;return{getItem:r=>e.get(r)??null,setItem:(r,n)=>e.set(r,n),removeItem:r=>e.delete(r),clear:()=>e.clear(),get length(){return e.size},key:r=>Array.from(e.keys())[r]??null}}const f=new Map,_=e=>{try{const{userManager:r,eventCallbacks:n}=e;n.userLoaded&&r.events.removeUserLoaded(n.userLoaded),n.userUnloaded&&r.events.removeUserUnloaded(n.userUnloaded),n.accessTokenExpired&&r.events.removeAccessTokenExpired(n.accessTokenExpired),n.accessTokenExpiring&&r.events.removeAccessTokenExpiring(n.accessTokenExpiring),n.silentRenewError&&r.events.removeSilentRenewError(n.silentRenewError),r.stopSilentRenew(),r.clearStaleState()}catch(r){console.warn("Error during UserManager cleanup:",r)}},T=e=>`${e.authority}_${e.clientId}`,L=()=>f.size===0?null:(f.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(f.values())[0]||null),V=e=>{const r=T(e),n=f.get(r);if(n)return n;const i=N(e),l=t.ref(!1),u=t.ref(!1),a=t.ref(null),s=t.ref(!1),k=t.ref(null),E=t.computed(()=>!!a.value&&!a.value.expired),w=t.computed(()=>{var S;return((S=a.value)==null?void 0:S.access_token)||null}),p=t.computed(()=>{var S;return!!((S=a.value)!=null&&S.expired)}),h={userManager:i,isInitialized:l,isInitializing:u,user:a,isLoading:s,error:k,isAuthenticated:E,accessToken:w,isExpired:p,eventCallbacks:{}};return f.set(r,h),h},N=e=>{const r=z(e);return new U.UserManager(r)},v=(e,r,n,i)=>{const l=e instanceof Error?e:new Error(r);return n.value=l,i==null||i(l),l},$=e=>{var r,n;if(!((r=e.authority)!=null&&r.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")}},I=async(e,r=1e4)=>{if(!e.isInitialized.value)return new Promise((n,i)=>{const l=setTimeout(()=>{i(new Error("Authentication initialization timeout"))},r),u=t.watch(e.isInitialized,a=>{a&&(clearTimeout(l),u(),n())},{immediate:!0})})},F=e=>{$(e);const r=V(e),{userManager:n,isInitialized:i,isInitializing:l,user:u,isLoading:a,error:s,isAuthenticated:k,accessToken:E,isExpired:w}=r,p=T(e),h=async()=>{if(!(l.value||i.value))try{l.value=!0,a.value=!0,s.value=null;const c=await n.getUser();if(c)if(!c.expired)u.value=c;else if(e.automaticSilentRenew!==!1)try{await x()}catch(o){console.warn("Silent renewal failed during initialization:",o),await n.removeUser(),u.value=null}else await n.removeUser(),u.value=null}catch(c){v(c,"Failed to initialize authentication",s,e.onError)}finally{a.value=!1,l.value=!1,i.value=!0}},S=async c=>{try{a.value=!0,s.value=null,await n.signinRedirect({state:c})}catch(o){v(o,"Sign in failed",s,e.onError)}finally{a.value=!1}},B=async c=>{try{a.value=!0,s.value=null,u.value=null,await n.signoutRedirect({state:c})}catch(o){v(o,"Sign out failed",s,e.onError)}finally{a.value=!1}},x=async()=>{try{a.value=!0,s.value=null;const c=await n.signinSilent();u.value=c}catch(c){throw v(c,"Silent renewal failed",s,e.onError)}finally{a.value=!1}},O=()=>{s.value=null},K=(c,o)=>{const{userManager:g,user:b,error:D,eventCallbacks:y}=c;y.userLoaded=d=>{var C;b.value=d,(C=o.onUserLoaded)==null||C.call(o,d)},y.userUnloaded=()=>{var d;b.value=null,(d=o.onUserUnloaded)==null||d.call(o)},y.accessTokenExpired=()=>{var d;(d=o.onAccessTokenExpired)==null||d.call(o)},y.accessTokenExpiring=()=>{var d;(d=o.onAccessTokenExpiring)==null||d.call(o)},y.silentRenewError=async d=>{console.warn("Silent renewal failed:",d);try{await g.removeUser(),b.value=null}catch(C){console.error("Failed to remove user after silent renewal error:",C)}v(d,"Silent renewal failed",D,o.onError)},g.events.addUserLoaded(y.userLoaded),g.events.addUserUnloaded(y.userUnloaded),g.events.addAccessTokenExpired(y.accessTokenExpired),g.events.addAccessTokenExpiring(y.accessTokenExpiring),g.events.addSilentRenewError(y.silentRenewError)},j=()=>{_(r),f.delete(p)};return!i.value&&!l.value&&(h(),K(r,e)),{user:u,isAuthenticated:k,isLoading:a,error:s,accessToken:E,isExpired:w,signIn:S,signOut:B,silentRenew:x,clearError:O,cleanup:j}},M=()=>{const e=L();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async()=>{await I(e);const i=await e.userManager.signinCallback();if(!i)throw new Error("Authentication callback failed: no user returned");return{user:i,state:i.state}},processSilentCallback:async()=>{await I(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:r}){const n=e,i=r,{processCallback:l,isInitializing:u}=M(),a=t.ref(!0),s=t.ref(null),k=async()=>{var E,w;try{const p=await l();(E=n.onSuccess)==null||E.call(n,p.user,p.state),i("success",p.user,p.state)}catch(p){const h=p instanceof Error?p:new Error("Callback processing failed");s.value=h,(w=n.onError)==null||w.call(n,h),i("error",h)}finally{a.value=!1}};return t.onMounted(()=>{k()}),(E,w)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[(t.unref(u)||a.value)&&!s.value?t.renderSlot(E.$slots,"default",{key:0},()=>[w[0]||(w[0]=t.createElementVNode("p",null,"Processing authentication...",-1))]):t.createCommentVNode("",!0),s.value?t.renderSlot(E.$slots,"error",{key:1,error:s.value},()=>[t.createElementVNode("div",null,[w[1]||(w[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:"SilentCallback",props:{onError:{type:Function}},setup(e){const r=e,{processSilentCallback:n,isInitializing:i}=M(),l=t.ref(null),u=async()=>{var a;try{await n()}catch(s){const k=s instanceof Error?s:new Error("Silent callback processing failed");l.value=k,(a=r.onError)==null||a.call(r,k),console.error("Silent callback error:",k)}};return t.onMounted(()=>{u()}),(a,s)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.unref(i)&&!l.value?t.renderSlot(a.$slots,"default",{key:0},()=>[s[0]||(s[0]=t.createElementVNode("p",null,"Processing silent renewal...",-1))]):t.createCommentVNode("",!0),l.value?t.renderSlot(a.$slots,"error",{key:1,error:l.value},()=>[t.createElementVNode("p",null,"Silent renewal error: "+t.toDisplayString(l.value.message),1)]):t.createCommentVNode("",!0)],64))}});m.AuthCallback=P,m.SilentCallback=q,m.useAuth=F,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
@@ -1 +1 @@
1
- {"version":3,"file":"configHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/configHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D;;;;GAIG;AACH,wBAAgB,yBAAyB,CACrC,MAAM,EAAE,UAAU,GACnB,mBAAmB,CAsBrB"}
1
+ {"version":3,"file":"configHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/configHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D;;;;GAIG;AACH,wBAAgB,yBAAyB,CACrC,MAAM,EAAE,UAAU,GACnB,mBAAmB,CAqBrB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vuethenticate",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A Vue 3 authentication state management library using oidc-client-ts",
5
5
  "keywords": [
6
6
  "vue",