vuethenticate 0.1.0 → 0.1.2

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/README.md ADDED
@@ -0,0 +1,317 @@
1
+ # Vuethenticate
2
+
3
+ A Vue 3 authentication state management library using oidc-client-ts.
4
+
5
+ ## Features
6
+
7
+ - 🔐 OIDC/OAuth2 authentication with automatic token management
8
+ - ⚡ Vue 3 Composition API with reactive state
9
+ - 🔄 Automatic token renewal
10
+ - 📦 TypeScript support
11
+ - 🎯 Minimal configuration required
12
+ - 🎨 Customizable callback component
13
+
14
+ ## Installation
15
+
16
+ ```bash
17
+ npm install vuethenticate
18
+ ```
19
+
20
+ ## Quick Start
21
+
22
+ > **Important Setup Order**: Make sure to initialize `useAuth()` in your main App component or a parent component before any callback routes are accessible. The callback components depend on this initialization.
23
+
24
+ ### 1. Configure Authentication
25
+
26
+ ```vue
27
+ <!-- App.vue - Main Application Component -->
28
+ <script setup>
29
+ import { useAuth } from 'vuethenticate'
30
+ import { RouterView } from 'vue-router'
31
+
32
+ // Initialize authentication in your main app component
33
+ const { user, isAuthenticated, signIn, signOut } = useAuth({
34
+ authority: 'https://your-oidc-provider.com',
35
+ clientId: 'your-client-id'
36
+ })
37
+ </script>
38
+
39
+ <template>
40
+ <div id="app">
41
+ <nav>
42
+ <div v-if="isAuthenticated">
43
+ <p>Welcome, {{ user.profile.name }}!</p>
44
+ <button @click="signOut">Sign Out</button>
45
+ </div>
46
+ <div v-else>
47
+ <button @click="signIn">Sign In</button>
48
+ </div>
49
+ </nav>
50
+
51
+ <!-- Router outlet - callback routes will work properly now -->
52
+ <RouterView />
53
+ </div>
54
+ </template>
55
+ ```
56
+
57
+ ### 2. Setup Callback Route
58
+
59
+ ```vue
60
+ <!-- CallbackPage.vue -->
61
+ <script setup>
62
+ import { AuthCallback } from 'vuethenticate'
63
+
64
+ function onSuccess(user, state) {
65
+ console.log('Authentication successful:', user)
66
+ console.log('State:', state)
67
+ // Redirect to app or show success message
68
+ window.location.href = '/dashboard'
69
+ }
70
+
71
+ function onError(error) {
72
+ console.error('Authentication failed:', error)
73
+ // Handle error - redirect to login or show error
74
+ window.location.href = '/login'
75
+ }
76
+ </script>
77
+
78
+ <template>
79
+ <AuthCallback
80
+ :onSuccess="onSuccess"
81
+ :onError="onError"
82
+ >
83
+ <div>Signing you in...</div>
84
+
85
+ <template #error="{ error }">
86
+ <div>
87
+ <h2>Authentication Failed</h2>
88
+ <p>{{ error.message }}</p>
89
+ </div>
90
+ </template>
91
+ </AuthCallback>
92
+ </template>
93
+ ```
94
+
95
+ ### 3. Add Route Configuration
96
+
97
+ ```javascript
98
+ // router.js
99
+ import { createRouter, createWebHistory } from 'vue-router'
100
+ import CallbackPage from './CallbackPage.vue'
101
+ import SilentCallbackPage from './SilentCallbackPage.vue'
102
+
103
+ const routes = [
104
+ {
105
+ path: '/auth/callback',
106
+ component: CallbackPage
107
+ },
108
+ {
109
+ path: '/auth/silent-callback',
110
+ component: SilentCallbackPage
111
+ },
112
+ // ... other routes
113
+ ]
114
+
115
+ export default createRouter({
116
+ history: createWebHistory(),
117
+ routes
118
+ })
119
+ ```
120
+
121
+ ### 4. Setup Silent Callback (for Token Renewal)
122
+
123
+ ```vue
124
+ <!-- SilentCallbackPage.vue -->
125
+ <script setup>
126
+ import { SilentCallback } from 'vuethenticate'
127
+
128
+ function onError(error) {
129
+ console.error('Silent renewal failed:', error)
130
+ }
131
+ </script>
132
+
133
+ <template>
134
+ <SilentCallback :onError="onError" />
135
+ </template>
136
+ ```
137
+
138
+ ## URL State Support
139
+
140
+ You can pass state through the authentication flow with full TypeScript support:
141
+
142
+ ```typescript
143
+ // Define your state type
144
+ interface MyAppState {
145
+ returnUrl: string;
146
+ theme: 'light' | 'dark';
147
+ userId?: string;
148
+ }
149
+
150
+ // Use with generic type parameter
151
+ const auth = useAuth<MyAppState>(config);
152
+
153
+ // Pass state during sign in
154
+ await auth.signIn({
155
+ returnUrl: '/dashboard',
156
+ theme: 'dark'
157
+ });
158
+
159
+ // Pass state during sign out
160
+ await auth.signOut({
161
+ returnUrl: '/goodbye',
162
+ theme: 'light'
163
+ });
164
+ ```
165
+
166
+ ### Receiving State in Callback
167
+
168
+ ```vue
169
+ <script setup lang="ts">
170
+ import { AuthCallback } from 'vuethenticate';
171
+
172
+ interface MyAppState {
173
+ returnUrl: string;
174
+ theme: 'light' | 'dark';
175
+ }
176
+
177
+ const handleSuccess = (user: User, state?: MyAppState) => {
178
+ if (state?.returnUrl) {
179
+ router.push(state.returnUrl);
180
+ }
181
+ if (state?.theme) {
182
+ setTheme(state.theme);
183
+ }
184
+ };
185
+ </script>
186
+
187
+ <template>
188
+ <AuthCallback<MyAppState>
189
+ @success="handleSuccess"
190
+ />
191
+ </template>
192
+ ```
193
+
194
+ > **Important**: Make sure to call `useAuth()` in your main App component or a parent component before rendering any callback components. The callback components rely on the authentication being initialized first.
195
+
196
+ ## API Reference
197
+
198
+ ### `useAuth(config)`
199
+
200
+ The main composable for authentication state management.
201
+
202
+ #### Configuration
203
+
204
+ | Property | Type | Required | Default | Description |
205
+ |----------|------|----------|---------|-------------|
206
+ | `authority` | `string` | ✓ | - | OIDC provider URL |
207
+ | `clientId` | `string` | ✓ | - | Application client ID |
208
+ | `redirectUri` | `string` | | `${origin}/auth/callback` | Callback URL |
209
+ | `scope` | `string` | | `'openid profile'` | OIDC scopes |
210
+ | `responseType` | `string` | | `'code'` | OAuth response type |
211
+ | `storage` | `'localStorage' \| 'sessionStorage' \| 'memory'` | | `'localStorage'` | Storage type |
212
+ | `automaticSilentRenew` | `boolean` | | `true` | Enable automatic token refresh |
213
+ | `silentRedirectUri` | `string` | | `${origin}/auth/silent-callback` | Silent refresh callback URL |
214
+ | `postLogoutRedirectUri` | `string` | | `${origin}` | Post-logout redirect URL |
215
+
216
+ #### Event Callbacks
217
+
218
+ | Property | Type | Description |
219
+ |----------|------|-------------|
220
+ | `onError` | `(error: Error) => void` | Called when an error occurs |
221
+ | `onUserLoaded` | `(user: User) => void` | Called when user is loaded |
222
+ | `onUserUnloaded` | `() => void` | Called when user is unloaded |
223
+ | `onAccessTokenExpired` | `() => void` | Called when access token expires |
224
+ | `onAccessTokenExpiring` | `() => void` | Called before access token expires |
225
+
226
+ #### Returns
227
+
228
+ | Property | Type | Description |
229
+ |----------|------|-------------|
230
+ | `user` | `Ref<User \| null>` | Current user object |
231
+ | `isAuthenticated` | `Ref<boolean>` | Authentication status |
232
+ | `isLoading` | `Ref<boolean>` | Loading state |
233
+ | `error` | `Ref<Error \| null>` | Current error |
234
+ | `accessToken` | `Ref<string \| null>` | Current access token |
235
+ | `isExpired` | `Ref<boolean>` | Token expiration status |
236
+ | `signIn` | `(state?: TState) => Promise<void>` | Initiate sign in with optional state |
237
+ | `signOut` | `(state?: TState) => Promise<void>` | Sign out user with optional state |
238
+ | `silentRenew` | `() => Promise<void>` | Manually renew token |
239
+ | `clearError` | `() => void` | Clear current error |
240
+ | `cleanup` | `() => void` | Manual cleanup of UserManager resources (rarely needed) |
241
+
242
+ ### `<AuthCallback>`
243
+
244
+ Component for handling OAuth callback. **Note**: This component requires `useAuth()` to be called in a parent component first.
245
+
246
+ #### Props
247
+
248
+ | Property | Type | Required | Description |
249
+ |----------|------|----------|-------------|
250
+ | `onSuccess` | `(user: User, state?: TState) => void` | | Success callback with typed state |
251
+ | `onError` | `(error: Error) => void` | | Error callback |
252
+
253
+ #### Slots
254
+
255
+ | Slot | Props | Description |
256
+ |------|-------|-------------|
257
+ | `default` | - | Loading content |
258
+ | `error` | `{ error: Error }` | Error content |
259
+
260
+ #### Events
261
+
262
+ | Event | Payload | Description |
263
+ |-------|---------|-------------|
264
+ | `success` | `User, state?: TState` | Emitted on successful authentication with typed state |
265
+ | `error` | `Error` | Emitted on authentication error |
266
+
267
+ ### `<SilentCallback>`
268
+
269
+ Component for handling silent token renewal callbacks. This component should be mounted on a separate route (typically `/auth/silent-callback`) and is used internally by the library for automatic token refresh. **Note**: This component requires `useAuth()` to be called in a parent component first.
270
+
271
+ #### Props
272
+
273
+ | Property | Type | Required | Description |
274
+ |----------|------|----------|-------------|
275
+ | `onError` | `(error: Error) => void` | | Error callback for silent renewal failures |
276
+
277
+ #### Usage
278
+
279
+ ```vue
280
+ <template>
281
+ <SilentCallback :onError="handleSilentError" />
282
+ </template>
283
+
284
+ <script setup>
285
+ import { SilentCallback } from 'vuethenticate'
286
+
287
+ function handleSilentError(error) {
288
+ console.error('Silent renewal failed:', error)
289
+ }
290
+ </script>
291
+ ```
292
+
293
+ > **Note**: This component is primarily used in an iframe or popup for silent token renewal. It should be placed on a minimal page with no other content.
294
+
295
+ ## Advanced Usage
296
+
297
+ ### Manual Cleanup
298
+
299
+ The `useAuth` composable includes a `cleanup()` function for manual resource cleanup. **This is rarely needed** as the library manages resources automatically.
300
+
301
+ ```typescript
302
+ const auth = useAuth(config);
303
+
304
+ // Only use in special scenarios like testing or custom cleanup requirements
305
+ auth.cleanup();
306
+ ```
307
+
308
+ **When you might need cleanup:**
309
+ - Unit testing scenarios where you need to reset state between tests
310
+ - Dynamic configuration changes (though creating a new instance is usually better)
311
+ - Custom cleanup logic in very specific edge cases
312
+
313
+ **Note:** The cleanup function removes event listeners and clears the UserManager instance from the internal registry. Normal application usage should never require calling this function.
314
+
315
+ ## License
316
+
317
+ MIT
@@ -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,EAEH,KAAK,GAAG,EAKX,MAAM,KAAK,CAAC;AACb,OAAO,EAAE,KAAK,IAAI,EAAe,MAAM,gBAAgB,CAAC;AA2KxD;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,OAAO,EACpC,QAAQ,UAAU,KACnB,aAAa,CAAC,MAAM,CAgMtB,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;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"}
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
- import { onUnmounted as K, ref as m, computed as f, watch as N, defineComponent as I, onMounted as U, createElementBlock as z, openBlock as M, Fragment as _, renderSlot as E, createCommentVNode as g, unref as R, createElementVNode as k, toDisplayString as x } from "vue";
2
- import { WebStorageStateStore as q, UserManager as B } from "oidc-client-ts";
3
- function O(e) {
1
+ import { ref as m, computed as I, watch as W, defineComponent as M, onMounted as R, createElementBlock as _, openBlock as L, Fragment as $, renderSlot as b, createCommentVNode as C, unref as F, createElementVNode as S, toDisplayString as P } from "vue";
2
+ import { WebStorageStateStore as j, UserManager as G } from "oidc-client-ts";
3
+ function H(e) {
4
4
  const r = typeof window < "u" ? window.location.origin : "";
5
5
  return {
6
6
  authority: e.authority,
@@ -10,7 +10,7 @@ function O(e) {
10
10
  redirect_uri: e.redirectUri ?? `${r}/auth/callback`,
11
11
  scope: e.scope ?? "openid profile",
12
12
  response_type: e.responseType ?? "code",
13
- userStore: e.storage ? new q({ store: V(e.storage) }) : void 0,
13
+ userStore: e.storage ? new j({ store: J(e.storage) }) : void 0,
14
14
  automaticSilentRenew: e.automaticSilentRenew ?? !0,
15
15
  silent_redirect_uri: e.silentRedirectUri ?? `${r}/auth/silent-callback`,
16
16
  post_logout_redirect_uri: e.postLogoutRedirectUri ?? r,
@@ -18,21 +18,21 @@ function O(e) {
18
18
  accessTokenExpiringNotificationTimeInSeconds: 60
19
19
  };
20
20
  }
21
- function V(e) {
21
+ function J(e) {
22
22
  if (typeof window > "u")
23
- return C();
23
+ return T();
24
24
  switch (e) {
25
25
  case "localStorage":
26
26
  return window.localStorage;
27
27
  case "sessionStorage":
28
28
  return window.sessionStorage;
29
29
  case "memory":
30
- return C();
30
+ return T();
31
31
  default:
32
32
  return window.localStorage;
33
33
  }
34
34
  }
35
- function C() {
35
+ function T() {
36
36
  const e = /* @__PURE__ */ new Map();
37
37
  return {
38
38
  getItem: (r) => e.get(r) ?? null,
@@ -45,37 +45,51 @@ function C() {
45
45
  key: (r) => Array.from(e.keys())[r] ?? null
46
46
  };
47
47
  }
48
- const p = /* @__PURE__ */ new Map(), T = (e) => `${e.authority}_${e.clientId}`, D = () => p.size === 0 ? null : (p.size === 1 || console.warn(
48
+ const E = /* @__PURE__ */ new Map(), Q = (e) => {
49
+ try {
50
+ const { userManager: r, eventCallbacks: t } = e;
51
+ t.userLoaded && r.events.removeUserLoaded(t.userLoaded), t.userUnloaded && r.events.removeUserUnloaded(t.userUnloaded), t.accessTokenExpired && r.events.removeAccessTokenExpired(
52
+ t.accessTokenExpired
53
+ ), t.accessTokenExpiring && r.events.removeAccessTokenExpiring(
54
+ t.accessTokenExpiring
55
+ ), t.silentRenewError && r.events.removeSilentRenewError(
56
+ t.silentRenewError
57
+ ), r.stopSilentRenew(), r.clearStaleState();
58
+ } catch (r) {
59
+ console.warn("Error during UserManager cleanup:", r);
60
+ }
61
+ }, K = (e) => `${e.authority}_${e.clientId}`, X = () => E.size === 0 ? null : (E.size === 1 || console.warn(
49
62
  "Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."
50
- ), Array.from(p.values())[0] || null), W = (e) => {
51
- const r = T(e), t = p.get(r);
63
+ ), Array.from(E.values())[0] || null), Y = (e) => {
64
+ const r = K(e), t = E.get(r);
52
65
  if (t)
53
66
  return t;
54
- const s = j(e), i = m(!1), o = m(!1), a = m(null), l = m(!1), w = m(null), v = f(() => !!a.value && !a.value.expired), u = f(() => {
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(() => {
55
68
  var h;
56
- return ((h = a.value) == null ? void 0 : h.access_token) || null;
57
- }), c = f(() => {
69
+ return ((h = n.value) == null ? void 0 : h.access_token) || null;
70
+ }), w = I(() => {
58
71
  var h;
59
- return !!((h = a.value) != null && h.expired);
60
- }), y = {
61
- userManager: s,
62
- isInitialized: i,
72
+ return !!((h = n.value) != null && h.expired);
73
+ }), k = {
74
+ userManager: l,
75
+ isInitialized: a,
63
76
  isInitializing: o,
64
- user: a,
65
- isLoading: l,
66
- error: w,
67
- isAuthenticated: v,
68
- accessToken: u,
69
- isExpired: c
77
+ user: n,
78
+ isLoading: s,
79
+ error: p,
80
+ isAuthenticated: y,
81
+ accessToken: d,
82
+ isExpired: w,
83
+ eventCallbacks: {}
70
84
  };
71
- return p.set(r, y), y;
72
- }, j = (e) => {
73
- const r = O(e);
74
- return new B(r);
75
- }, S = (e, r, t, s) => {
76
- const i = e instanceof Error ? e : new Error(r);
77
- return t.value = i, s == null || s(i), i;
78
- }, G = (e) => {
85
+ return E.set(r, k), k;
86
+ }, Z = (e) => {
87
+ const r = H(e);
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;
92
+ }, ee = (e) => {
79
93
  var r, t;
80
94
  if (!((r = e.authority) != null && r.trim()))
81
95
  throw new Error("AuthConfig: authority is required");
@@ -86,162 +100,168 @@ const p = /* @__PURE__ */ new Map(), T = (e) => `${e.authority}_${e.clientId}`,
86
100
  } catch {
87
101
  throw new Error("AuthConfig: authority must be a valid URL");
88
102
  }
89
- }, A = async (e, r = 1e4) => {
103
+ }, z = async (e, r = 1e4) => {
90
104
  if (!e.isInitialized.value)
91
- return new Promise((t, s) => {
92
- const i = setTimeout(() => {
93
- s(new Error("Authentication initialization timeout"));
94
- }, r), o = N(
105
+ return new Promise((t, l) => {
106
+ const a = setTimeout(() => {
107
+ l(new Error("Authentication initialization timeout"));
108
+ }, r), o = W(
95
109
  e.isInitialized,
96
- (a) => {
97
- a && (clearTimeout(i), o(), t());
110
+ (n) => {
111
+ n && (clearTimeout(a), o(), t());
98
112
  },
99
113
  { immediate: !0 }
100
114
  );
101
115
  });
102
- }, Q = (e) => {
103
- G(e);
104
- const r = W(e), {
116
+ }, ne = (e) => {
117
+ ee(e);
118
+ const r = Y(e), {
105
119
  userManager: t,
106
- isInitialized: s,
107
- isInitializing: i,
120
+ isInitialized: l,
121
+ isInitializing: a,
108
122
  user: o,
109
- isLoading: a,
110
- error: l,
111
- isAuthenticated: w,
112
- accessToken: v,
113
- isExpired: u
114
- } = r, c = T(e), y = async () => {
115
- if (!(i.value || s.value))
123
+ isLoading: n,
124
+ error: s,
125
+ isAuthenticated: p,
126
+ accessToken: y,
127
+ isExpired: d
128
+ } = r, w = K(e), k = async () => {
129
+ if (!(a.value || l.value))
116
130
  try {
117
- i.value = !0, a.value = !0, l.value = null;
118
- const n = await t.getUser();
119
- if (n)
120
- if (!n.expired)
121
- o.value = n;
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;
122
136
  else if (e.automaticSilentRenew !== !1)
123
137
  try {
124
- await b();
125
- } catch (d) {
138
+ await x();
139
+ } catch (i) {
126
140
  console.warn(
127
141
  "Silent renewal failed during initialization:",
128
- d
142
+ i
129
143
  ), await t.removeUser(), o.value = null;
130
144
  }
131
145
  else
132
146
  await t.removeUser(), o.value = null;
133
- } catch (n) {
134
- S(
135
- n,
147
+ } catch (c) {
148
+ f(
149
+ c,
136
150
  "Failed to initialize authentication",
137
- l,
151
+ s,
138
152
  e.onError
139
153
  );
140
154
  } finally {
141
- a.value = !1, i.value = !1, s.value = !0;
155
+ n.value = !1, a.value = !1, l.value = !0;
142
156
  }
143
- }, h = async (n) => {
157
+ }, h = async (c) => {
144
158
  try {
145
- a.value = !0, l.value = null, await t.signinRedirect({ state: n });
146
- } catch (d) {
147
- S(d, "Sign in failed", l, e.onError);
159
+ n.value = !0, s.value = null, await t.signinRedirect({ state: c });
160
+ } catch (i) {
161
+ f(i, "Sign in failed", s, e.onError);
148
162
  } finally {
149
- a.value = !1;
163
+ n.value = !1;
150
164
  }
151
- }, L = async (n) => {
165
+ }, q = async (c) => {
152
166
  try {
153
- a.value = !0, l.value = null, o.value = null, await t.signoutRedirect({ state: n });
154
- } catch (d) {
155
- S(d, "Sign out failed", l, e.onError);
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);
156
170
  } finally {
157
- a.value = !1;
171
+ n.value = !1;
158
172
  }
159
- }, b = async () => {
173
+ }, x = async () => {
160
174
  try {
161
- a.value = !0, l.value = null;
162
- const n = await t.signinSilent();
163
- o.value = n;
164
- } catch (n) {
165
- throw S(
166
- n,
175
+ n.value = !0, s.value = null;
176
+ const c = await t.signinSilent();
177
+ o.value = c;
178
+ } catch (c) {
179
+ throw f(
180
+ c,
167
181
  "Silent renewal failed",
168
- l,
182
+ s,
169
183
  e.onError
170
184
  );
171
185
  } finally {
172
- a.value = !1;
186
+ n.value = !1;
173
187
  }
174
- }, F = () => {
175
- l.value = null;
176
- }, P = () => {
177
- t.events.addUserLoaded((n) => {
178
- var d;
179
- o.value = n, (d = e.onUserLoaded) == null || d.call(e, n);
180
- }), t.events.addUserUnloaded(() => {
181
- var n;
182
- o.value = null, (n = e.onUserUnloaded) == null || n.call(e);
183
- }), t.events.addAccessTokenExpired(() => {
184
- var n;
185
- (n = e.onAccessTokenExpired) == null || n.call(e);
186
- }), t.events.addAccessTokenExpiring(() => {
187
- var n;
188
- (n = e.onAccessTokenExpiring) == null || n.call(e);
189
- }), t.events.addSilentRenewError(async (n) => {
190
- console.warn("Silent renewal failed:", n);
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) => {
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);
191
206
  try {
192
- await t.removeUser(), o.value = null;
193
- } catch (d) {
207
+ await g.removeUser(), A.value = null;
208
+ } catch (U) {
194
209
  console.error(
195
210
  "Failed to remove user after silent renewal error:",
196
- d
211
+ U
197
212
  );
198
213
  }
199
- S(
200
- n,
214
+ f(
215
+ u,
201
216
  "Silent renewal failed",
202
- l,
203
- e.onError
217
+ D,
218
+ i.onError
204
219
  );
205
- });
220
+ }, g.events.addUserLoaded(v.userLoaded), g.events.addUserUnloaded(v.userUnloaded), g.events.addAccessTokenExpired(
221
+ v.accessTokenExpired
222
+ ), g.events.addAccessTokenExpiring(
223
+ v.accessTokenExpiring
224
+ ), g.events.addSilentRenewError(v.silentRenewError);
225
+ }, V = () => {
226
+ Q(r), E.delete(w);
206
227
  };
207
- return !s.value && !i.value && (y(), P()), K(() => {
208
- p.delete(c);
209
- }), {
228
+ return !l.value && !a.value && (k(), O(r, e)), {
210
229
  user: o,
211
- isAuthenticated: w,
212
- isLoading: a,
213
- error: l,
214
- accessToken: v,
215
- isExpired: u,
230
+ isAuthenticated: p,
231
+ isLoading: n,
232
+ error: s,
233
+ accessToken: y,
234
+ isExpired: d,
216
235
  signIn: h,
217
- signOut: L,
218
- silentRenew: b,
219
- clearError: F
236
+ signOut: q,
237
+ silentRenew: x,
238
+ clearError: B,
239
+ cleanup: V
220
240
  };
221
- }, $ = () => {
222
- const e = D();
241
+ }, N = () => {
242
+ const e = X();
223
243
  if (!e)
224
244
  throw new Error(
225
245
  "Authentication not initialized. Make sure useAuth() is called in a parent component first."
226
246
  );
227
247
  return {
228
- processCallback: async (s) => {
229
- await A(e);
230
- const i = s || window.location.href, o = await e.userManager.signinRedirectCallback(i);
248
+ processCallback: async (l) => {
249
+ await z(e);
250
+ const a = l || window.location.href, o = await e.userManager.signinRedirectCallback(a);
231
251
  return {
232
252
  user: o,
233
253
  state: o.state
234
254
  };
235
255
  },
236
- processSilentCallback: async (s) => {
237
- await A(e);
238
- const i = s || window.location.href;
239
- await e.userManager.signinSilentCallback(i);
256
+ processSilentCallback: async (l) => {
257
+ await z(e);
258
+ const a = l || window.location.href;
259
+ await e.userManager.signinSilentCallback(a);
240
260
  },
241
261
  isInitialized: e.isInitialized,
242
262
  isInitializing: e.isInitializing
243
263
  };
244
- }, X = /* @__PURE__ */ I({
264
+ }, ae = /* @__PURE__ */ M({
245
265
  __name: "AuthCallback",
246
266
  props: {
247
267
  onSuccess: { type: Function },
@@ -249,67 +269,67 @@ const p = /* @__PURE__ */ new Map(), T = (e) => `${e.authority}_${e.clientId}`,
249
269
  },
250
270
  emits: ["success", "error"],
251
271
  setup(e, { emit: r }) {
252
- const t = e, s = r, { processCallback: i, isInitializing: o } = $(), a = m(!0), l = m(null), w = async () => {
253
- var v, u;
272
+ const t = e, l = r, { processCallback: a, isInitializing: o } = N(), n = m(!0), s = m(null), p = async () => {
273
+ var y, d;
254
274
  try {
255
- const c = await i();
256
- (v = t.onSuccess) == null || v.call(t, c.user, c.state), s("success", c.user, c.state);
257
- } catch (c) {
258
- const y = c instanceof Error ? c : new Error("Callback processing failed");
259
- l.value = y, (u = t.onError) == null || u.call(t, y), s("error", y);
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);
260
280
  } finally {
261
- a.value = !1;
281
+ n.value = !1;
262
282
  }
263
283
  };
264
- return U(() => {
265
- w();
266
- }), (v, u) => (M(), z(_, null, [
267
- (R(o) || a.value) && !l.value ? E(v.$slots, "default", { key: 0 }, () => [
268
- u[0] || (u[0] = k("p", null, "Processing authentication...", -1))
269
- ]) : g("", !0),
270
- l.value ? E(v.$slots, "error", {
284
+ return R(() => {
285
+ p();
286
+ }), (y, d) => (L(), _($, null, [
287
+ (F(o) || n.value) && !s.value ? b(y.$slots, "default", { key: 0 }, () => [
288
+ d[0] || (d[0] = S("p", null, "Processing authentication...", -1))
289
+ ]) : C("", !0),
290
+ s.value ? b(y.$slots, "error", {
271
291
  key: 1,
272
- error: l.value
292
+ error: s.value
273
293
  }, () => [
274
- k("div", null, [
275
- u[1] || (u[1] = k("h2", null, "Authentication Error", -1)),
276
- k("p", null, x(l.value.message), 1)
294
+ S("div", null, [
295
+ d[1] || (d[1] = S("h2", null, "Authentication Error", -1)),
296
+ S("p", null, P(s.value.message), 1)
277
297
  ])
278
- ]) : g("", !0)
298
+ ]) : C("", !0)
279
299
  ], 64));
280
300
  }
281
- }), Y = /* @__PURE__ */ I({
301
+ }), se = /* @__PURE__ */ M({
282
302
  __name: "SilentCallback",
283
303
  props: {
284
304
  onError: { type: Function }
285
305
  },
286
306
  setup(e) {
287
- const r = e, { processSilentCallback: t, isInitializing: s } = $(), i = m(null), o = async () => {
288
- var a;
307
+ const r = e, { processSilentCallback: t, isInitializing: l } = N(), a = m(null), o = async () => {
308
+ var n;
289
309
  try {
290
310
  await t();
291
- } catch (l) {
292
- const w = l instanceof Error ? l : new Error("Silent callback processing failed");
293
- i.value = w, (a = r.onError) == null || a.call(r, w), console.error("Silent callback error:", w);
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);
294
314
  }
295
315
  };
296
- return U(() => {
316
+ return R(() => {
297
317
  o();
298
- }), (a, l) => (M(), z(_, null, [
299
- R(s) && !i.value ? E(a.$slots, "default", { key: 0 }, () => [
300
- l[0] || (l[0] = k("p", null, "Processing silent renewal...", -1))
301
- ]) : g("", !0),
302
- i.value ? E(a.$slots, "error", {
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))
321
+ ]) : C("", !0),
322
+ a.value ? b(n.$slots, "error", {
303
323
  key: 1,
304
- error: i.value
324
+ error: a.value
305
325
  }, () => [
306
- k("p", null, "Silent renewal error: " + x(i.value.message), 1)
307
- ]) : g("", !0)
326
+ S("p", null, "Silent renewal error: " + P(a.value.message), 1)
327
+ ]) : C("", !0)
308
328
  ], 64));
309
329
  }
310
330
  });
311
331
  export {
312
- X as AuthCallback,
313
- Y as SilentCallback,
314
- Q as useAuth
332
+ ae as AuthCallback,
333
+ se as SilentCallback,
334
+ ne as useAuth
315
335
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(w,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):(w=typeof globalThis<"u"?globalThis:w||self,t(w.Vuethenticate={},w.Vue,w.OidcClientTs))})(this,function(w,t,E){"use strict";function I(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??"client_secret_basic",redirect_uri:e.redirectUri??`${n}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new E.WebStorageStateStore({store:U(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${n}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??n,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function U(e){if(typeof window>"u")return g();switch(e){case"localStorage":return window.localStorage;case"sessionStorage":return window.sessionStorage;case"memory":return g();default:return window.localStorage}}function g(){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 f=new Map,C=e=>`${e.authority}_${e.clientId}`,z=()=>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),M=e=>{const n=C(e),r=f.get(n);if(r)return r;const o=_(e),s=t.ref(!1),c=t.ref(!1),i=t.ref(null),l=t.ref(!1),y=t.ref(null),p=t.computed(()=>!!i.value&&!i.value.expired),u=t.computed(()=>{var k;return((k=i.value)==null?void 0:k.access_token)||null}),d=t.computed(()=>{var k;return!!((k=i.value)!=null&&k.expired)}),h={userManager:o,isInitialized:s,isInitializing:c,user:i,isLoading:l,error:y,isAuthenticated:p,accessToken:u,isExpired:d};return f.set(n,h),h},_=e=>{const n=I(e);return new E.UserManager(n)},S=(e,n,r,o)=>{const s=e instanceof Error?e:new Error(n);return r.value=s,o==null||o(s),s},T=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")}},b=async(e,n=1e4)=>{if(!e.isInitialized.value)return new Promise((r,o)=>{const s=setTimeout(()=>{o(new Error("Authentication initialization timeout"))},n),c=t.watch(e.isInitialized,i=>{i&&(clearTimeout(s),c(),r())},{immediate:!0})})},R=e=>{T(e);const n=M(e),{userManager:r,isInitialized:o,isInitializing:s,user:c,isLoading:i,error:l,isAuthenticated:y,accessToken:p,isExpired:u}=n,d=C(e),h=async()=>{if(!(s.value||o.value))try{s.value=!0,i.value=!0,l.value=null;const a=await r.getUser();if(a)if(!a.expired)c.value=a;else if(e.automaticSilentRenew!==!1)try{await A()}catch(m){console.warn("Silent renewal failed during initialization:",m),await r.removeUser(),c.value=null}else await r.removeUser(),c.value=null}catch(a){S(a,"Failed to initialize authentication",l,e.onError)}finally{i.value=!1,s.value=!1,o.value=!0}},k=async a=>{try{i.value=!0,l.value=null,await r.signinRedirect({state:a})}catch(m){S(m,"Sign in failed",l,e.onError)}finally{i.value=!1}},N=async a=>{try{i.value=!0,l.value=null,c.value=null,await r.signoutRedirect({state:a})}catch(m){S(m,"Sign out failed",l,e.onError)}finally{i.value=!1}},A=async()=>{try{i.value=!0,l.value=null;const a=await r.signinSilent();c.value=a}catch(a){throw S(a,"Silent renewal failed",l,e.onError)}finally{i.value=!1}},$=()=>{l.value=null},F=()=>{r.events.addUserLoaded(a=>{var m;c.value=a,(m=e.onUserLoaded)==null||m.call(e,a)}),r.events.addUserUnloaded(()=>{var a;c.value=null,(a=e.onUserUnloaded)==null||a.call(e)}),r.events.addAccessTokenExpired(()=>{var a;(a=e.onAccessTokenExpired)==null||a.call(e)}),r.events.addAccessTokenExpiring(()=>{var a;(a=e.onAccessTokenExpiring)==null||a.call(e)}),r.events.addSilentRenewError(async a=>{console.warn("Silent renewal failed:",a);try{await r.removeUser(),c.value=null}catch(m){console.error("Failed to remove user after silent renewal error:",m)}S(a,"Silent renewal failed",l,e.onError)})};return!o.value&&!s.value&&(h(),F()),t.onUnmounted(()=>{f.delete(d)}),{user:c,isAuthenticated:y,isLoading:i,error:l,accessToken:p,isExpired:u,signIn:k,signOut:N,silentRenew:A,clearError:$}},v=()=>{const e=z();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async o=>{await b(e);const s=o||window.location.href,c=await e.userManager.signinRedirectCallback(s);return{user:c,state:c.state}},processSilentCallback:async o=>{await b(e);const s=o||window.location.href;await e.userManager.signinSilentCallback(s)},isInitialized:e.isInitialized,isInitializing:e.isInitializing}},V=t.defineComponent({__name:"AuthCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:n}){const r=e,o=n,{processCallback:s,isInitializing:c}=v(),i=t.ref(!0),l=t.ref(null),y=async()=>{var p,u;try{const d=await s();(p=r.onSuccess)==null||p.call(r,d.user,d.state),o("success",d.user,d.state)}catch(d){const h=d instanceof Error?d:new Error("Callback processing failed");l.value=h,(u=r.onError)==null||u.call(r,h),o("error",h)}finally{i.value=!1}};return t.onMounted(()=>{y()}),(p,u)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[(t.unref(c)||i.value)&&!l.value?t.renderSlot(p.$slots,"default",{key:0},()=>[u[0]||(u[0]=t.createElementVNode("p",null,"Processing authentication...",-1))]):t.createCommentVNode("",!0),l.value?t.renderSlot(p.$slots,"error",{key:1,error:l.value},()=>[t.createElementVNode("div",null,[u[1]||(u[1]=t.createElementVNode("h2",null,"Authentication Error",-1)),t.createElementVNode("p",null,t.toDisplayString(l.value.message),1)])]):t.createCommentVNode("",!0)],64))}}),x=t.defineComponent({__name:"SilentCallback",props:{onError:{type:Function}},setup(e){const n=e,{processSilentCallback:r,isInitializing:o}=v(),s=t.ref(null),c=async()=>{var i;try{await r()}catch(l){const y=l instanceof Error?l:new Error("Silent callback processing failed");s.value=y,(i=n.onError)==null||i.call(n,y),console.error("Silent callback error:",y)}};return t.onMounted(()=>{c()}),(i,l)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.unref(o)&&!s.value?t.renderSlot(i.$slots,"default",{key:0},()=>[l[0]||(l[0]=t.createElementVNode("p",null,"Processing silent renewal...",-1))]):t.createCommentVNode("",!0),s.value?t.renderSlot(i.$slots,"error",{key:1,error:s.value},()=>[t.createElementVNode("p",null,"Silent renewal error: "+t.toDisplayString(s.value.message),1)]):t.createCommentVNode("",!0)],64))}});w.AuthCallback=V,w.SilentCallback=x,w.useAuth=R,Object.defineProperty(w,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??"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"})});
@@ -31,6 +31,7 @@ export interface AuthMethods<TState = unknown> {
31
31
  signOut: (state?: TState) => Promise<void>;
32
32
  silentRenew: () => Promise<void>;
33
33
  clearError: () => void;
34
+ cleanup: () => void;
34
35
  }
35
36
  export interface AuthCallbackMethods<TState = unknown> {
36
37
  processCallback: (url?: string) => Promise<{
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC/B,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,WAAW,UAAU;IAEvB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,qBAAqB,GAAG,oBAAoB,CAAC;IAEpE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,OAAO,CAAC,EAAE,cAAc,GAAG,gBAAgB,GAAG,QAAQ,CAAC;IACvD,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IACjC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;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E,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjD,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,mBAAmB;IAChC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACpC;AAED,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vuethenticate",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "A Vue 3 authentication state management library using oidc-client-ts",
5
5
  "keywords": [
6
6
  "vue",