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: (
|
16
|
+
processCallback: () => Promise<{
|
17
17
|
user: User;
|
18
18
|
state?: TState;
|
19
19
|
}>;
|
20
|
-
processSilentCallback: (
|
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;
|
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
|
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
|
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 = () =>
|
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(
|
64
|
-
const r = K(e), t =
|
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
|
68
|
-
var
|
69
|
-
return ((
|
70
|
-
}),
|
71
|
-
var
|
72
|
-
return !!((
|
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:
|
75
|
-
isInitialized:
|
76
|
-
isInitializing:
|
74
|
+
userManager: s,
|
75
|
+
isInitialized: i,
|
76
|
+
isInitializing: u,
|
77
77
|
user: n,
|
78
|
-
isLoading:
|
78
|
+
isLoading: a,
|
79
79
|
error: p,
|
80
80
|
isAuthenticated: y,
|
81
81
|
accessToken: d,
|
82
|
-
isExpired:
|
82
|
+
isExpired: v,
|
83
83
|
eventCallbacks: {}
|
84
84
|
};
|
85
|
-
return
|
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,
|
90
|
-
const
|
91
|
-
return t.value =
|
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,
|
106
|
-
const
|
107
|
-
|
108
|
-
}, r),
|
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(
|
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:
|
121
|
-
isInitializing:
|
122
|
-
user:
|
120
|
+
isInitialized: s,
|
121
|
+
isInitializing: i,
|
122
|
+
user: u,
|
123
123
|
isLoading: n,
|
124
|
-
error:
|
124
|
+
error: a,
|
125
125
|
isAuthenticated: p,
|
126
126
|
accessToken: y,
|
127
127
|
isExpired: d
|
128
|
-
} = r,
|
129
|
-
if (!(
|
128
|
+
} = r, v = K(e), k = async () => {
|
129
|
+
if (!(i.value || s.value))
|
130
130
|
try {
|
131
|
-
|
132
|
-
const
|
133
|
-
if (
|
134
|
-
if (!
|
135
|
-
|
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 (
|
139
|
+
} catch (l) {
|
140
140
|
console.warn(
|
141
141
|
"Silent renewal failed during initialization:",
|
142
|
-
|
143
|
-
), await t.removeUser(),
|
142
|
+
l
|
143
|
+
), await t.removeUser(), u.value = null;
|
144
144
|
}
|
145
145
|
else
|
146
|
-
await t.removeUser(),
|
147
|
-
} catch (
|
146
|
+
await t.removeUser(), u.value = null;
|
147
|
+
} catch (o) {
|
148
148
|
f(
|
149
|
-
|
149
|
+
o,
|
150
150
|
"Failed to initialize authentication",
|
151
|
-
|
151
|
+
a,
|
152
152
|
e.onError
|
153
153
|
);
|
154
154
|
} finally {
|
155
|
-
n.value = !1,
|
155
|
+
n.value = !1, i.value = !1, s.value = !0;
|
156
156
|
}
|
157
|
-
},
|
157
|
+
}, E = async (o) => {
|
158
158
|
try {
|
159
|
-
n.value = !0,
|
160
|
-
} catch (
|
161
|
-
f(
|
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 (
|
165
|
+
}, q = async (o) => {
|
166
166
|
try {
|
167
|
-
n.value = !0,
|
168
|
-
} catch (
|
169
|
-
f(
|
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,
|
176
|
-
const
|
177
|
-
|
178
|
-
} catch (
|
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
|
-
|
180
|
+
o,
|
181
181
|
"Silent renewal failed",
|
182
|
-
|
182
|
+
a,
|
183
183
|
e.onError
|
184
184
|
);
|
185
185
|
} finally {
|
186
186
|
n.value = !1;
|
187
187
|
}
|
188
188
|
}, B = () => {
|
189
|
-
|
190
|
-
}, O = (
|
191
|
-
const { userManager: g, user: A, error: D, eventCallbacks:
|
192
|
-
|
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 =
|
195
|
-
},
|
196
|
-
var
|
197
|
-
A.value = null, (
|
198
|
-
},
|
199
|
-
var
|
200
|
-
(
|
201
|
-
},
|
202
|
-
var
|
203
|
-
(
|
204
|
-
},
|
205
|
-
console.warn("Silent renewal failed:",
|
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
|
-
|
215
|
+
c,
|
216
216
|
"Silent renewal failed",
|
217
217
|
D,
|
218
|
-
|
218
|
+
l.onError
|
219
219
|
);
|
220
|
-
}, g.events.addUserLoaded(
|
221
|
-
|
220
|
+
}, g.events.addUserLoaded(w.userLoaded), g.events.addUserUnloaded(w.userUnloaded), g.events.addAccessTokenExpired(
|
221
|
+
w.accessTokenExpired
|
222
222
|
), g.events.addAccessTokenExpiring(
|
223
|
-
|
224
|
-
), g.events.addSilentRenewError(
|
223
|
+
w.accessTokenExpiring
|
224
|
+
), g.events.addSilentRenewError(w.silentRenewError);
|
225
225
|
}, V = () => {
|
226
|
-
Q(r),
|
226
|
+
Q(r), h.delete(v);
|
227
227
|
};
|
228
|
-
return !
|
229
|
-
user:
|
228
|
+
return !s.value && !i.value && (k(), O(r, e)), {
|
229
|
+
user: u,
|
230
230
|
isAuthenticated: p,
|
231
231
|
isLoading: n,
|
232
|
-
error:
|
232
|
+
error: a,
|
233
233
|
accessToken: y,
|
234
234
|
isExpired: d,
|
235
|
-
signIn:
|
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 (
|
248
|
+
processCallback: async () => {
|
249
249
|
await z(e);
|
250
|
-
const
|
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:
|
253
|
-
state:
|
254
|
+
user: s,
|
255
|
+
state: s.state
|
254
256
|
};
|
255
257
|
},
|
256
|
-
processSilentCallback: async (
|
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,
|
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
|
276
|
-
(y = t.onSuccess) == null || y.call(t,
|
277
|
-
} catch (
|
278
|
-
const k =
|
279
|
-
|
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(
|
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
|
-
|
290
|
+
a.value ? b(y.$slots, "error", {
|
291
291
|
key: 1,
|
292
|
-
error:
|
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(
|
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:
|
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 (
|
312
|
-
const p =
|
313
|
-
|
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
|
-
|
318
|
-
}), (n,
|
319
|
-
F(
|
320
|
-
|
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
|
-
|
322
|
+
i.value ? b(n.$slots, "error", {
|
323
323
|
key: 1,
|
324
|
-
error:
|
324
|
+
error: i.value
|
325
325
|
}, () => [
|
326
|
-
S("p", null, "Silent renewal error: " + P(
|
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
|
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,
|
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"}
|