vuethenticate 0.1.6 → 0.1.8

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 CHANGED
@@ -217,6 +217,8 @@ The main composable for authentication state management.
217
217
  | `automaticSilentRenew` | `boolean` | | `true` | Enable automatic token refresh |
218
218
  | `silentRedirectUri` | `string` | | `${origin}/auth/silent-callback` | Silent refresh callback URL |
219
219
  | `postLogoutRedirectUri` | `string` | | `${origin}` | Post-logout redirect URL |
220
+ | `logLevel` | `LogLevel` | | `LogLevel.NONE` | Logging level for debug information |
221
+ | `logger` | `Logger` | | `silentLogger` | Custom logger implementation |
220
222
 
221
223
  #### Event Callbacks
222
224
 
@@ -367,6 +369,257 @@ function handleSilentError(error) {
367
369
 
368
370
  > **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.
369
371
 
372
+ ## Logging and Debugging
373
+
374
+ Vuethenticate provides comprehensive logging capabilities to help debug authentication flows and monitor authentication events. The logging system supports both internal library logging and configurable `oidc-client-ts` debug output.
375
+
376
+ ### Log Levels
377
+
378
+ ```typescript
379
+ import { LogLevel } from 'vuethenticate';
380
+
381
+ enum LogLevel {
382
+ NONE = 0, // No logging
383
+ ERROR = 1, // Only errors
384
+ WARN = 2, // Warnings and errors
385
+ INFO = 3, // Info, warnings, and errors
386
+ DEBUG = 4, // All messages including debug info
387
+ }
388
+ ```
389
+
390
+ ### Basic Logging Setup
391
+
392
+ ```typescript
393
+ import { useAuth, LogLevel, consoleLogger } from 'vuethenticate';
394
+
395
+ // Enable debug logging with console output
396
+ const auth = useAuth({
397
+ authority: 'https://your-oidc-provider.com',
398
+ clientId: 'your-client-id',
399
+ logLevel: LogLevel.DEBUG,
400
+ logger: consoleLogger
401
+ });
402
+ ```
403
+
404
+ ### Custom Logger Implementation
405
+
406
+ ```typescript
407
+ import { useAuth, LogLevel, type Logger } from 'vuethenticate';
408
+
409
+ const customLogger: Logger = {
410
+ error: (message: string, ...args: unknown[]) => {
411
+ // Send to your error tracking service
412
+ console.error('[AUTH ERROR]', message, ...args);
413
+ // Sentry.captureException(new Error(message));
414
+ },
415
+ warn: (message: string, ...args: unknown[]) => {
416
+ console.warn('[AUTH WARN]', message, ...args);
417
+ },
418
+ info: (message: string, ...args: unknown[]) => {
419
+ console.info('[AUTH INFO]', message, ...args);
420
+ },
421
+ debug: (message: string, ...args: unknown[]) => {
422
+ if (process.env.NODE_ENV === 'development') {
423
+ console.debug('[AUTH DEBUG]', message, ...args);
424
+ }
425
+ },
426
+ };
427
+
428
+ const auth = useAuth({
429
+ authority: 'https://your-oidc-provider.com',
430
+ clientId: 'your-client-id',
431
+ logLevel: LogLevel.INFO,
432
+ logger: customLogger
433
+ });
434
+ ```
435
+
436
+ ### Environment-Based Logging
437
+
438
+ ```typescript
439
+ import { useAuth, LogLevel, consoleLogger } from 'vuethenticate';
440
+
441
+ const getLogConfig = () => {
442
+ switch (process.env.NODE_ENV) {
443
+ case 'development':
444
+ return { logLevel: LogLevel.DEBUG, logger: consoleLogger };
445
+ case 'test':
446
+ return { logLevel: LogLevel.NONE };
447
+ case 'production':
448
+ return { logLevel: LogLevel.ERROR, logger: productionLogger };
449
+ default:
450
+ return { logLevel: LogLevel.WARN, logger: consoleLogger };
451
+ }
452
+ };
453
+
454
+ const auth = useAuth({
455
+ authority: 'https://your-oidc-provider.com',
456
+ clientId: 'your-client-id',
457
+ ...getLogConfig()
458
+ });
459
+ ```
460
+
461
+ ### Available Loggers
462
+
463
+ #### `consoleLogger`
464
+ Standard console output logger suitable for development.
465
+
466
+ #### `silentLogger`
467
+ No-op logger that suppresses all output (default when no logger is specified).
468
+
469
+ #### `createLevelLogger(baseLogger, level)`
470
+ Creates a filtered logger that only outputs messages at or above the specified level.
471
+
472
+ ```typescript
473
+ import { createLevelLogger, consoleLogger, LogLevel } from 'vuethenticate';
474
+
475
+ const warnOnlyLogger = createLevelLogger(consoleLogger, LogLevel.WARN);
476
+ ```
477
+
478
+ ### What Gets Logged
479
+
480
+ When logging is enabled, you'll see output for:
481
+
482
+ - **Authentication initialization** - Setup and configuration validation
483
+ - **Token operations** - Token acquisition, renewal, and expiration
484
+ - **User state changes** - Login, logout, and user profile updates
485
+ - **Silent renewal** - Background token refresh attempts
486
+ - **OIDC protocol flows** - Detailed protocol-level debugging (when DEBUG level)
487
+ - **Error conditions** - All authentication-related errors with context
488
+
489
+ ### OIDC Client Debug Logs
490
+
491
+ The underlying `oidc-client-ts` library has extensive debug logging. When you configure logging in Vuethenticate, it automatically configures the OIDC client logging as well, so you'll see detailed protocol-level information including:
492
+
493
+ - HTTP requests and responses
494
+ - Token validation steps
495
+ - Silent renewal iframe operations
496
+ - OIDC discovery document processing
497
+
498
+ ### Production Considerations
499
+
500
+ For production environments, consider:
501
+
502
+ - Setting `logLevel` to `LogLevel.ERROR` or `LogLevel.NONE`
503
+ - Using a custom logger that sends errors to your monitoring service
504
+ - Avoiding debug-level logging to prevent performance impact
505
+ - Implementing log sampling for high-traffic applications
506
+
507
+ ```typescript
508
+ // Production-safe logging configuration
509
+ const auth = useAuth({
510
+ authority: 'https://your-oidc-provider.com',
511
+ clientId: 'your-client-id',
512
+ logLevel: LogLevel.ERROR,
513
+ logger: {
514
+ error: (message, ...args) => {
515
+ // Send to monitoring service
516
+ monitoringService.error(message, args);
517
+ },
518
+ warn: () => {}, // Suppress in production
519
+ info: () => {}, // Suppress in production
520
+ debug: () => {}, // Suppress in production
521
+ }
522
+ });
523
+ ```
524
+
525
+ ## Logging
526
+
527
+ Vuethenticate provides comprehensive logging support for debugging authentication flows and OIDC protocol interactions. **Logging is silent by default** - you must explicitly configure it to see output.
528
+
529
+ ### Configuration
530
+
531
+ Add logging configuration to your auth config:
532
+
533
+ ```typescript
534
+ import { useAuth, LogLevel, consoleLogger } from 'vuethenticate'
535
+
536
+ const auth = useAuth({
537
+ authority: 'https://your-oidc-provider.com',
538
+ clientId: 'your-client-id',
539
+
540
+ // Enable debug logging
541
+ logLevel: LogLevel.DEBUG,
542
+ // logger: consoleLogger, // Optional: defaults to console when logLevel is set
543
+ })
544
+ ```
545
+
546
+ ### Log Levels
547
+
548
+ | Level | Value | Description |
549
+ |-------|-------|-------------|
550
+ | `LogLevel.NONE` | 0 | No logging (default) |
551
+ | `LogLevel.ERROR` | 1 | Error messages only |
552
+ | `LogLevel.WARN` | 2 | Warnings and errors |
553
+ | `LogLevel.INFO` | 3 | Info, warnings, and errors |
554
+ | `LogLevel.DEBUG` | 4 | All messages including debug info |
555
+
556
+ ### Built-in Loggers
557
+
558
+ | Logger | Description |
559
+ |--------|-------------|
560
+ | `consoleLogger` | Logs to browser console (used automatically when logLevel is set) |
561
+ | `silentLogger` | No output - useful for explicitly disabling logs |
562
+
563
+ ### Behavior
564
+
565
+ - **Silent by default**: No logging occurs unless explicitly configured
566
+ - **Smart defaults**: When you set a `logLevel`, `consoleLogger` is used automatically
567
+ - **Custom loggers**: Provide your own `logger` for custom logging behavior
568
+ - **OIDC integration**: Both internal auth logs and underlying OIDC client logs are controlled by the same configuration
569
+
570
+ ### Custom Logger
571
+
572
+ Implement the `Logger` interface for custom logging:
573
+
574
+ ```typescript
575
+ import type { Logger } from 'vuethenticate'
576
+
577
+ const customLogger: Logger = {
578
+ error: (message, ...args) => {
579
+ // Send to error reporting service
580
+ errorService.log(message, args)
581
+ },
582
+ warn: (message, ...args) => console.warn(message, ...args),
583
+ info: (message, ...args) => console.info(message, ...args),
584
+ debug: (message, ...args) => {
585
+ if (process.env.NODE_ENV === 'development') {
586
+ console.debug(message, ...args)
587
+ }
588
+ },
589
+ }
590
+
591
+ const auth = useAuth({
592
+ authority: 'https://your-oidc-provider.com',
593
+ clientId: 'your-client-id',
594
+ logLevel: LogLevel.INFO,
595
+ logger: customLogger,
596
+ })
597
+ ```
598
+
599
+ ### What Gets Logged
600
+
601
+ With logging enabled, you'll see detailed information about:
602
+
603
+ - **Authentication flows**: Sign-in, sign-out, and callback processing
604
+ - **Token management**: Token refresh, expiration, and renewal
605
+ - **OIDC protocol**: Requests, responses, and protocol-level details
606
+ - **Error handling**: Detailed error information with stack traces
607
+ - **State management**: User loading/unloading events
608
+
609
+ ### Development vs Production
610
+
611
+ ```typescript
612
+ const auth = useAuth({
613
+ authority: 'https://your-oidc-provider.com',
614
+ clientId: 'your-client-id',
615
+
616
+ // Enable detailed logging only in development
617
+ logLevel: process.env.NODE_ENV === 'development'
618
+ ? LogLevel.DEBUG
619
+ : LogLevel.ERROR,
620
+ })
621
+ ```
622
+
370
623
  ## Advanced Usage
371
624
 
372
625
  ### Manual Cleanup
@@ -1 +1 @@
1
- {"version":3,"file":"AuthCallback.vue.d.ts","sourceRoot":"","sources":["../../src/components/AuthCallback.vue"],"names":[],"mappings":"AAgBA;AAyEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;yBAG1B,MAAM,GAAG,OAAO,EAChC,aAAa,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,EAC9D,YAAY,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,EAC3G,eAAe,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,EACjE;WAiHO,mBAAmB,CAAC;;;uLAAkE,CAAC,4BAA2B;oBACzG,OAAO,KAAK,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,IAAI;WAClD,GAAG;;yBAhCkB,GAAG;;;YACL,GAAG;;;EAmC1B,KACQ,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAE;AA5HzE,wBA4H4E;AAC5E,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
1
+ {"version":3,"file":"AuthCallback.vue.d.ts","sourceRoot":"","sources":["../../src/components/AuthCallback.vue"],"names":[],"mappings":"AAgBA;AAmFA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;yBAG1B,MAAM,GAAG,OAAO,EAChC,aAAa,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,EAC9D,YAAY,mBAAmB,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC,EAC3G,eAAe,WAAW,CAAC,OAAO,CAAC,OAAO,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,EACjE;WA2HO,mBAAmB,CAAC;;;uLAAkE,CAAC,4BAA2B;oBACzG,OAAO,KAAK,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,IAAI;WAClD,GAAG;;yBAhCkB,GAAG;;;YACL,GAAG;;;EAmC1B,KACQ,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAE;AAtIzE,wBAsI4E;AAC5E,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"LogoutCallback.vue.d.ts","sourceRoot":"","sources":["../../src/components/LogoutCallback.vue"],"names":[],"mappings":"AAyBA;AAiFA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;yBAGxC,MAAM,GAAG,OAAO,EAChC,aAAa,WAAW,C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ACzG,OAAO,KAAK,EAAE,gBAAgB,CAAC,EAAE,CAAC,GAAG,IAAI;WAClD,GAAG;;yBAjCkB,GAAG;;;YACL,GAAG;yBACD,GAAG;;;EAmC5B,KACQ,OAAO,KAAK,EAAE,KAAK,GAAG;IAAE,KAAK,CAAC,EAAE,OAAO,CAAC,OAAO,WAAW,CAAC,CAAA;CAAE;AAlJzE,wBAkJ4E;AAC5E,KAAK,mBAAmB,CAAC,CAAC,IAAI;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAAG,GAAG,EAAE,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SilentCallback.vue.d.ts","sourceRoot":"","sources":["../../src/components/SilentCallback.vue"],"names":[],"mappings":"AAaA;AA6DA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AA6CzD,iBAAS,cAAc;WAiCT,OAAO,IAA6B;;yBAXrB,GAAG;;;YACL,GAAG;;;;EAe7B;AAUD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe,kTAMnB,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAQpG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
1
+ {"version":3,"file":"SilentCallback.vue.d.ts","sourceRoot":"","sources":["../../src/components/SilentCallback.vue"],"names":[],"mappings":"AAaA;AAiEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAiDzD,iBAAS,cAAc;WAiCT,OAAO,IAA6B;;yBAXrB,GAAG;;;YACL,GAAG;;;;EAe7B;AAUD,KAAK,oBAAoB,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AAC9D,QAAA,MAAM,eAAe,kTAMnB,CAAC;wBACkB,uBAAuB,CAAC,OAAO,eAAe,EAAE,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAAnG,wBAAoG;AAQpG,KAAK,uBAAuB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IACxC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KAEV,CAAA;CACD,CAAC"}
@@ -1,6 +1,4 @@
1
- import { AuthConfig, UseAuthReturn } from '../types/auth';
2
- import { Ref } from 'vue';
3
- import { User } from 'oidc-client-ts';
1
+ import { AuthConfig, UseAuthCallbacksReturn, UseAuthReturn } from '../types/auth';
4
2
  /**
5
3
  * Vue composable for authentication state management using OIDC
6
4
  * @param config - Authentication configuration
@@ -12,16 +10,5 @@ export declare const useAuth: <TState = unknown>(config: AuthConfig) => UseAuthR
12
10
  * Automatically finds the active UserManager instance and waits for initialization
13
11
  * @returns Callback processing methods and initialization state
14
12
  */
15
- export declare const useAuthCallbacks: <TState = unknown>() => {
16
- processCallback: () => Promise<{
17
- user: User;
18
- state?: TState;
19
- }>;
20
- processLogoutCallback: () => Promise<{
21
- state?: TState;
22
- }>;
23
- processSilentCallback: () => Promise<void>;
24
- isInitialized: Ref<boolean, boolean>;
25
- isInitializing: Ref<boolean, boolean>;
26
- };
13
+ export declare const useAuthCallbacks: <TState = unknown>() => UseAuthCallbacksReturn<TState>;
27
14
  //# sourceMappingURL=useAuth.d.ts.map
@@ -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;2BAaX,OAAO,CAAC;QACtC,IAAI,EAAE,IAAI,CAAC;QACX,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;iCAkBsC,OAAO,CAAC;QAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;iCAYsC,OAAO,CAAC,IAAI,CAAC;;;CAaxD,CAAC"}
1
+ {"version":3,"file":"useAuth.d.ts","sourceRoot":"","sources":["../../src/composables/useAuth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,UAAU,EACV,sBAAsB,EACtB,aAAa,EAChB,MAAM,eAAe,CAAC;AAsPvB;;;;GAIG;AACH,eAAO,MAAM,OAAO,GAAI,MAAM,GAAG,OAAO,EACpC,QAAQ,UAAU,KACnB,aAAa,CAAC,MAAM,CAwOtB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GACzB,MAAM,GAAG,OAAO,OACf,sBAAsB,CAAC,MAAM,CAgFjC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { useAuth } from './composables/useAuth';
2
2
  export { AuthCallback, LogoutCallback, SilentCallback } from './components';
3
- export type { AuthConfig, AuthState, AuthMethods, AuthCallbackMethods, UseAuthReturn, AuthCallbackProps, SilentCallbackProps, LogoutCallbackProps, User, } from './types/auth';
3
+ export { LogLevel, type Logger, consoleLogger, silentLogger, } from './utils/logger';
4
+ export type { AuthConfig, AuthState, AuthMethods, AuthCallbackMethods, UseAuthReturn, UseAuthCallbacksReturn, AuthCallbackProps, SilentCallbackProps, LogoutCallbackProps, User, } from './types/auth';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG5E,YAAY,EACR,UAAU,EACV,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,IAAI,GACP,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG5E,OAAO,EACH,QAAQ,EACR,KAAK,MAAM,EACX,aAAa,EACb,YAAY,GACf,MAAM,gBAAgB,CAAC;AAGxB,YAAY,EACR,UAAU,EACV,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,aAAa,EACb,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,IAAI,GACP,MAAM,cAAc,CAAC"}
package/dist/index.esm.js CHANGED
@@ -1,8 +1,33 @@
1
- import { ref as m, computed as I, watch as W, defineComponent as M, onMounted as T, createElementBlock as F, openBlock as P, Fragment as K, renderSlot as S, createCommentVNode as U, unref as L, createElementVNode as y, toDisplayString as x } from "vue";
2
- import { WebStorageStateStore as Y, UserManager as j } from "oidc-client-ts";
3
- function G(e) {
1
+ import { ref as y, computed as N, watch as j, defineComponent as V, onMounted as z, createElementBlock as P, openBlock as _, Fragment as B, renderSlot as S, createCommentVNode as I, unref as M, createElementVNode as v, toDisplayString as x } from "vue";
2
+ import { WebStorageStateStore as H, Log as E, UserManager as J } from "oidc-client-ts";
3
+ var f = /* @__PURE__ */ ((e) => (e[e.NONE = 0] = "NONE", e[e.ERROR = 1] = "ERROR", e[e.WARN = 2] = "WARN", e[e.INFO = 3] = "INFO", e[e.DEBUG = 4] = "DEBUG", e))(f || {});
4
+ const D = {
5
+ error: (e, ...t) => console.error(e, ...t),
6
+ warn: (e, ...t) => console.warn(e, ...t),
7
+ info: (e, ...t) => console.info(e, ...t),
8
+ debug: (e, ...t) => console.debug(e, ...t)
9
+ }, Q = {
10
+ error: () => {
11
+ },
12
+ warn: () => {
13
+ },
14
+ info: () => {
15
+ },
16
+ debug: () => {
17
+ }
18
+ }, X = (e, t) => ({
19
+ error: t >= 1 ? e.error : () => {
20
+ },
21
+ warn: t >= 2 ? e.warn : () => {
22
+ },
23
+ info: t >= 3 ? e.info : () => {
24
+ },
25
+ debug: t >= 4 ? e.debug : () => {
26
+ }
27
+ });
28
+ function Z(e) {
4
29
  const t = typeof window < "u" ? window.location.origin : "";
5
- return {
30
+ return te(e), {
6
31
  authority: e.authority,
7
32
  client_id: e.clientId,
8
33
  client_secret: e.clientSecret,
@@ -10,7 +35,7 @@ function G(e) {
10
35
  redirect_uri: e.redirectUri ?? `${t}/auth/callback`,
11
36
  scope: e.scope ?? "openid profile",
12
37
  response_type: e.responseType ?? "code",
13
- userStore: e.storage ? new Y({ store: H(e.storage) }) : void 0,
38
+ userStore: e.storage ? new H({ store: ee(e.storage) }) : void 0,
14
39
  automaticSilentRenew: e.automaticSilentRenew ?? !0,
15
40
  silent_redirect_uri: e.silentRedirectUri ?? `${t}/auth/silent-callback`,
16
41
  post_logout_redirect_uri: e.postLogoutRedirectUri ?? `${t}/auth/logout-callback`,
@@ -18,21 +43,21 @@ function G(e) {
18
43
  accessTokenExpiringNotificationTimeInSeconds: 60
19
44
  };
20
45
  }
21
- function H(e) {
46
+ function ee(e) {
22
47
  if (typeof window > "u")
23
- return _();
48
+ return F();
24
49
  switch (e) {
25
50
  case "localStorage":
26
51
  return window.localStorage;
27
52
  case "sessionStorage":
28
53
  return window.sessionStorage;
29
54
  case "memory":
30
- return _();
55
+ return F();
31
56
  default:
32
57
  return window.localStorage;
33
58
  }
34
59
  }
35
- function _() {
60
+ function F() {
36
61
  const e = /* @__PURE__ */ new Map();
37
62
  return {
38
63
  getItem: (t) => e.get(t) ?? null,
@@ -45,7 +70,32 @@ function _() {
45
70
  key: (t) => Array.from(e.keys())[t] ?? null
46
71
  };
47
72
  }
48
- const h = /* @__PURE__ */ new Map(), J = (e) => {
73
+ const te = (e) => {
74
+ if (e.logLevel === void 0 && !e.logger)
75
+ return;
76
+ const t = e.logger ?? (e.logLevel !== void 0 ? D : void 0), r = e.logLevel ?? f.NONE;
77
+ t && (E.setLogger({
78
+ error: t.error,
79
+ warn: t.warn,
80
+ info: t.info,
81
+ debug: t.debug
82
+ }), E.setLevel(re(r)));
83
+ }, re = (e) => {
84
+ switch (e) {
85
+ case f.NONE:
86
+ return E.NONE;
87
+ case f.ERROR:
88
+ return E.ERROR;
89
+ case f.WARN:
90
+ return E.WARN;
91
+ case f.INFO:
92
+ return E.INFO;
93
+ case f.DEBUG:
94
+ return E.DEBUG;
95
+ default:
96
+ return E.NONE;
97
+ }
98
+ }, A = /* @__PURE__ */ new Map(), ne = (e) => {
49
99
  try {
50
100
  const { userManager: t, eventCallbacks: r } = e;
51
101
  r.userLoaded && t.events.removeUserLoaded(r.userLoaded), r.userUnloaded && t.events.removeUserUnloaded(r.userUnloaded), r.accessTokenExpired && t.events.removeAccessTokenExpired(
@@ -58,38 +108,44 @@ const h = /* @__PURE__ */ new Map(), J = (e) => {
58
108
  } catch (t) {
59
109
  console.warn("Error during UserManager cleanup:", t);
60
110
  }
61
- }, N = (e) => `${e.authority}_${e.clientId}`, Q = () => h.size === 0 ? null : (h.size === 1 || console.warn(
111
+ }, W = (e) => `${e.authority}_${e.clientId}`, ae = () => A.size === 0 ? null : (A.size === 1 || console.warn(
62
112
  "Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."
63
- ), Array.from(h.values())[0] || null), X = (e) => {
64
- const t = N(e), r = h.get(t);
113
+ ), Array.from(A.values())[0] || null), le = (e) => {
114
+ const t = W(e), r = A.get(t);
65
115
  if (r)
66
116
  return r;
67
- const o = Z(e), n = m(!1), c = m(!1), s = m(null), a = m(!1), p = m(null), d = I(() => !!s.value && !s.value.expired), l = I(() => {
68
- var E;
69
- return ((E = s.value) == null ? void 0 : E.access_token) || null;
70
- }), u = I(() => {
71
- var E;
72
- return !!((E = s.value) != null && E.expired);
73
- }), k = {
74
- userManager: o,
117
+ const u = se(e), n = y(!1), c = y(!1), a = y(null), l = y(!1), s = y(null), b = N(() => !!a.value && !a.value.expired), g = N(() => {
118
+ var m;
119
+ return ((m = a.value) == null ? void 0 : m.access_token) || null;
120
+ }), o = N(() => {
121
+ var m;
122
+ return !!((m = a.value) != null && m.expired);
123
+ }), d = oe(e), k = {
124
+ userManager: u,
75
125
  isInitialized: n,
76
126
  isInitializing: c,
77
- user: s,
78
- isLoading: a,
79
- error: p,
80
- isAuthenticated: d,
81
- accessToken: l,
82
- isExpired: u,
127
+ user: a,
128
+ isLoading: l,
129
+ error: s,
130
+ isAuthenticated: b,
131
+ accessToken: g,
132
+ isExpired: o,
133
+ logger: d,
83
134
  eventCallbacks: {}
84
135
  };
85
- return h.set(t, k), k;
86
- }, Z = (e) => {
87
- const t = G(e);
88
- return new j(t);
89
- }, b = (e, t, r, o) => {
136
+ return A.set(t, k), k;
137
+ }, se = (e) => {
138
+ const t = Z(e);
139
+ return new J(t);
140
+ }, oe = (e) => {
141
+ if (!e.logger && !e.logLevel)
142
+ return Q;
143
+ const t = e.logger ?? D, r = e.logLevel ?? f.NONE;
144
+ return X(t, r);
145
+ }, R = (e, t, r, u) => {
90
146
  const n = e instanceof Error ? e : new Error(t);
91
- return r.value = n, o == null || o(n), n;
92
- }, ee = (e) => {
147
+ return r.value = n, u == null || u(n), n;
148
+ }, ie = (e) => {
93
149
  var t, r;
94
150
  if (!((t = e.authority) != null && t.trim()))
95
151
  throw new Error("AuthConfig: authority is required");
@@ -100,175 +156,199 @@ const h = /* @__PURE__ */ new Map(), J = (e) => {
100
156
  } catch {
101
157
  throw new Error("AuthConfig: authority must be a valid URL");
102
158
  }
103
- }, z = async (e, t = 1e4) => {
159
+ }, T = async (e, t = 1e4) => {
104
160
  if (!e.isInitialized.value)
105
- return new Promise((r, o) => {
161
+ return new Promise((r, u) => {
106
162
  const n = setTimeout(() => {
107
- o(new Error("Authentication initialization timeout"));
108
- }, t), c = W(
163
+ u(new Error("Authentication initialization timeout"));
164
+ }, t), c = j(
109
165
  e.isInitialized,
110
- (s) => {
111
- s && (clearTimeout(n), c(), r());
166
+ (a) => {
167
+ a && (clearTimeout(n), c(), r());
112
168
  },
113
169
  { immediate: !0 }
114
170
  );
115
171
  });
116
- }, ne = (e) => {
117
- ee(e);
118
- const t = X(e), {
172
+ }, de = (e) => {
173
+ ie(e);
174
+ const t = le(e), {
119
175
  userManager: r,
120
- isInitialized: o,
176
+ isInitialized: u,
121
177
  isInitializing: n,
122
178
  user: c,
123
- isLoading: s,
124
- error: a,
125
- isAuthenticated: p,
126
- accessToken: d,
127
- isExpired: l
128
- } = t, u = N(e), k = async () => {
129
- if (!(n.value || o.value))
179
+ isLoading: a,
180
+ error: l,
181
+ isAuthenticated: s,
182
+ accessToken: b,
183
+ isExpired: g
184
+ } = t, o = W(e), d = async () => {
185
+ if (!(n.value || u.value))
130
186
  try {
131
- n.value = !0, s.value = !0, a.value = null;
132
- const v = await r.getUser();
133
- if (v)
134
- if (!v.expired)
135
- c.value = v;
136
- else if (e.automaticSilentRenew !== !1)
187
+ n.value = !0, a.value = !0, l.value = null;
188
+ const h = await r.getUser();
189
+ if (h)
190
+ if (!h.expired)
191
+ c.value = h, t.logger.info(
192
+ "[Vuethenticate] useAuth: User restored from storage"
193
+ );
194
+ else if (e.automaticSilentRenew !== !1) {
195
+ t.logger.info(
196
+ "[Vuethenticate] useAuth: Token expired, attempting silent renewal"
197
+ );
137
198
  try {
138
199
  await $();
139
200
  } catch (i) {
140
- console.warn(
141
- "Silent renewal failed during initialization:",
201
+ t.logger.warn(
202
+ "[Vuethenticate] useAuth: Silent renewal failed during initialization",
142
203
  i
143
204
  ), await r.removeUser(), c.value = null;
144
205
  }
145
- else
206
+ } else
146
207
  await r.removeUser(), c.value = null;
147
- } catch (v) {
148
- b(
149
- v,
150
- "Failed to initialize authentication",
151
- a,
208
+ u.value = !0;
209
+ } catch (h) {
210
+ t.logger.error(
211
+ "[Vuethenticate] useAuth: Initialization failed",
212
+ h
213
+ ), R(
214
+ h,
215
+ "Authentication initialization failed",
216
+ l,
152
217
  e.onError
153
218
  );
154
219
  } finally {
155
- s.value = !1, n.value = !1, o.value = !0;
220
+ n.value = !1, a.value = !1;
156
221
  }
157
- }, E = async (v) => {
222
+ }, k = async (h) => {
158
223
  try {
159
- s.value = !0, a.value = null, await r.signinRedirect({ state: v });
224
+ a.value = !0, l.value = null, t.logger.info("[Vuethenticate] useAuth: Starting sign-in flow"), await r.signinRedirect({ state: h });
160
225
  } catch (i) {
161
- b(i, "Sign in failed", a, e.onError);
226
+ t.logger.error("[Vuethenticate] useAuth: Sign-in failed", i), R(i, "Sign in failed", l, e.onError);
162
227
  } finally {
163
- s.value = !1;
228
+ a.value = !1;
164
229
  }
165
- }, q = async (v) => {
230
+ }, m = async (h) => {
166
231
  try {
167
- s.value = !0, a.value = null, c.value = null, await r.signoutRedirect({ state: v });
232
+ a.value = !0, l.value = null, c.value = null, t.logger.info(
233
+ "[Vuethenticate] useAuth: Starting sign-out flow"
234
+ ), await r.signoutRedirect({ state: h });
168
235
  } catch (i) {
169
- b(i, "Sign out failed", a, e.onError);
236
+ t.logger.error("[Vuethenticate] useAuth: Sign-out failed", i), R(i, "Sign out failed", l, e.onError);
170
237
  } finally {
171
- s.value = !1;
238
+ a.value = !1;
172
239
  }
173
240
  }, $ = async () => {
174
241
  try {
175
- s.value = !0, a.value = null;
176
- const v = await r.signinSilent();
177
- c.value = v;
178
- } catch (v) {
179
- throw b(
180
- v,
242
+ a.value = !0, l.value = null;
243
+ const h = await r.signinSilent();
244
+ c.value = h;
245
+ } catch (h) {
246
+ throw R(
247
+ h,
181
248
  "Silent renewal failed",
182
- a,
249
+ l,
183
250
  e.onError
184
251
  );
185
252
  } finally {
186
- s.value = !1;
253
+ a.value = !1;
187
254
  }
188
- }, B = () => {
189
- a.value = null;
190
- }, O = (v, i) => {
191
- const { userManager: f, user: A, error: D, eventCallbacks: g } = v;
192
- g.userLoaded = (w) => {
193
- var C;
194
- A.value = w, (C = i.onUserLoaded) == null || C.call(i, w);
195
- }, g.userUnloaded = () => {
255
+ }, G = () => {
256
+ l.value = null;
257
+ }, K = (h, i) => {
258
+ const { userManager: C, user: L, error: Y, eventCallbacks: p } = h;
259
+ p.userLoaded = (w) => {
260
+ var U;
261
+ L.value = w, (U = i.onUserLoaded) == null || U.call(i, w);
262
+ }, p.userUnloaded = () => {
196
263
  var w;
197
- A.value = null, (w = i.onUserUnloaded) == null || w.call(i);
198
- }, g.accessTokenExpired = () => {
264
+ L.value = null, (w = i.onUserUnloaded) == null || w.call(i);
265
+ }, p.accessTokenExpired = () => {
199
266
  var w;
200
267
  (w = i.onAccessTokenExpired) == null || w.call(i);
201
- }, g.accessTokenExpiring = () => {
268
+ }, p.accessTokenExpiring = () => {
202
269
  var w;
203
270
  (w = i.onAccessTokenExpiring) == null || w.call(i);
204
- }, g.silentRenewError = async (w) => {
271
+ }, p.silentRenewError = async (w) => {
205
272
  console.warn("Silent renewal failed:", w);
206
273
  try {
207
- await f.removeUser(), A.value = null;
208
- } catch (C) {
274
+ await C.removeUser(), L.value = null;
275
+ } catch (U) {
209
276
  console.error(
210
277
  "Failed to remove user after silent renewal error:",
211
- C
278
+ U
212
279
  );
213
280
  }
214
- b(
281
+ R(
215
282
  w,
216
283
  "Silent renewal failed",
217
- D,
284
+ Y,
218
285
  i.onError
219
286
  );
220
- }, f.events.addUserLoaded(g.userLoaded), f.events.addUserUnloaded(g.userUnloaded), f.events.addAccessTokenExpired(
221
- g.accessTokenExpired
222
- ), f.events.addAccessTokenExpiring(
223
- g.accessTokenExpiring
224
- ), f.events.addSilentRenewError(g.silentRenewError);
225
- }, V = () => {
226
- J(t), h.delete(u);
287
+ }, C.events.addUserLoaded(p.userLoaded), C.events.addUserUnloaded(p.userUnloaded), C.events.addAccessTokenExpired(
288
+ p.accessTokenExpired
289
+ ), C.events.addAccessTokenExpiring(
290
+ p.accessTokenExpiring
291
+ ), C.events.addSilentRenewError(p.silentRenewError);
292
+ }, q = () => {
293
+ ne(t), A.delete(o);
227
294
  };
228
- return !o.value && !n.value && (k(), O(t, e)), {
295
+ return !u.value && !n.value && (d(), K(t, e)), {
229
296
  user: c,
230
- isAuthenticated: p,
231
- isLoading: s,
232
- error: a,
233
- accessToken: d,
234
- isExpired: l,
235
- signIn: E,
236
- signOut: q,
297
+ isAuthenticated: s,
298
+ isLoading: a,
299
+ error: l,
300
+ accessToken: b,
301
+ isExpired: g,
302
+ signIn: k,
303
+ signOut: m,
237
304
  silentRenew: $,
238
- clearError: B,
239
- cleanup: V
305
+ clearError: G,
306
+ cleanup: q
240
307
  };
241
- }, R = () => {
242
- const e = Q();
308
+ }, O = () => {
309
+ const e = ae();
243
310
  if (!e)
244
311
  throw new Error(
245
312
  "Authentication not initialized. Make sure useAuth() is called in a parent component first."
246
313
  );
247
314
  return {
248
315
  processCallback: async () => {
249
- await z(e);
316
+ await T(e), e.logger.info(
317
+ "[Vuethenticate] useAuthCallbacks: Processing authentication callback"
318
+ );
250
319
  const n = await e.userManager.signinCallback();
251
320
  if (!n)
252
321
  throw new Error("Authentication callback failed: no user returned");
253
- return {
322
+ return e.logger.info(
323
+ "[Vuethenticate] useAuthCallbacks: Authentication callback successful"
324
+ ), {
254
325
  user: n,
255
326
  state: n.state
256
327
  };
257
328
  },
258
329
  processLogoutCallback: async () => {
259
- await z(e);
330
+ await T(e), e.logger.debug(
331
+ "[Vuethenticate] useAuthCallbacks: Processing logout callback"
332
+ );
260
333
  const n = await e.userManager.signoutCallback();
261
- return {
262
- state: n == null ? void 0 : n.state
334
+ return e.logger.info(
335
+ "[Vuethenticate] useAuthCallbacks: Logout callback completed successfully"
336
+ ), {
337
+ state: n == null ? void 0 : n.userState
263
338
  };
264
339
  },
265
340
  processSilentCallback: async () => {
266
- await z(e), await e.userManager.signinCallback();
341
+ await T(e), e.logger.debug(
342
+ "[Vuethenticate] useAuthCallbacks: Processing silent callback"
343
+ ), await e.userManager.signinCallback(), e.logger.debug(
344
+ "[Vuethenticate] useAuthCallbacks: Silent callback completed successfully"
345
+ );
267
346
  },
268
347
  isInitialized: e.isInitialized,
269
- isInitializing: e.isInitializing
348
+ isInitializing: e.isInitializing,
349
+ logger: e.logger
270
350
  };
271
- }, ae = /* @__PURE__ */ M({
351
+ }, ge = /* @__PURE__ */ V({
272
352
  __name: "AuthCallback",
273
353
  props: {
274
354
  onSuccess: { type: Function },
@@ -276,36 +356,44 @@ const h = /* @__PURE__ */ new Map(), J = (e) => {
276
356
  },
277
357
  emits: ["success", "error"],
278
358
  setup(e, { emit: t }) {
279
- const r = e, o = t, { processCallback: n, isInitializing: c } = R(), s = m(!0), a = m(null), p = async () => {
280
- var d, l;
359
+ const r = e, u = t, { processCallback: n, isInitializing: c, logger: a } = O(), l = y(!0), s = y(null), b = async () => {
360
+ var g, o;
281
361
  try {
282
- const u = await n();
283
- (d = r.onSuccess) == null || d.call(r, u.user, u.state), o("success", u.user, u.state);
284
- } catch (u) {
285
- const k = u instanceof Error ? u : new Error("Callback processing failed");
286
- a.value = k, (l = r.onError) == null || l.call(r, k), o("error", k);
362
+ a.info(
363
+ "[Vuethenticate] AuthCallback: Processing authentication callback"
364
+ );
365
+ const d = await n();
366
+ a.info(
367
+ "[Vuethenticate] AuthCallback: Authentication callback completed successfully"
368
+ ), (g = r.onSuccess) == null || g.call(r, d.user, d.state), u("success", d.user, d.state);
369
+ } catch (d) {
370
+ const k = d instanceof Error ? d : new Error("Callback processing failed");
371
+ a.error(
372
+ "[Vuethenticate] AuthCallback: Authentication callback failed",
373
+ k
374
+ ), s.value = k, (o = r.onError) == null || o.call(r, k), u("error", k);
287
375
  } finally {
288
- s.value = !1;
376
+ l.value = !1;
289
377
  }
290
378
  };
291
- return T(() => {
292
- p();
293
- }), (d, l) => (P(), F(K, null, [
294
- (L(c) || s.value) && !a.value ? S(d.$slots, "default", { key: 0 }, () => [
295
- l[0] || (l[0] = y("p", null, "Processing authentication...", -1))
296
- ]) : U("", !0),
297
- a.value ? S(d.$slots, "error", {
379
+ return z(() => {
380
+ b();
381
+ }), (g, o) => (_(), P(B, null, [
382
+ (M(c) || l.value) && !s.value ? S(g.$slots, "default", { key: 0 }, () => [
383
+ o[0] || (o[0] = v("p", null, "Processing authentication...", -1))
384
+ ]) : I("", !0),
385
+ s.value ? S(g.$slots, "error", {
298
386
  key: 1,
299
- error: a.value
387
+ error: s.value
300
388
  }, () => [
301
- y("div", null, [
302
- l[1] || (l[1] = y("h2", null, "Authentication Error", -1)),
303
- y("p", null, x(a.value.message), 1)
389
+ v("div", null, [
390
+ o[1] || (o[1] = v("h2", null, "Authentication Error", -1)),
391
+ v("p", null, x(s.value.message), 1)
304
392
  ])
305
- ]) : U("", !0)
393
+ ]) : I("", !0)
306
394
  ], 64));
307
395
  }
308
- }), se = /* @__PURE__ */ M({
396
+ }), he = /* @__PURE__ */ V({
309
397
  __name: "LogoutCallback",
310
398
  props: {
311
399
  onSuccess: { type: Function },
@@ -313,70 +401,86 @@ const h = /* @__PURE__ */ new Map(), J = (e) => {
313
401
  },
314
402
  emits: ["success", "error"],
315
403
  setup(e, { emit: t }) {
316
- const r = e, o = t, { processLogoutCallback: n, isInitializing: c } = R(), s = m(!0), a = m(null), p = async () => {
317
- var d, l;
404
+ const r = e, u = t, { processLogoutCallback: n, isInitializing: c, logger: a } = O(), l = y(!0), s = y(null), b = async () => {
405
+ var g, o;
318
406
  try {
319
- const u = await n();
320
- (d = r.onSuccess) == null || d.call(r, u.state), o("success", u.state);
321
- } catch (u) {
322
- const k = u instanceof Error ? u : new Error("Logout callback processing failed");
323
- a.value = k, (l = r.onError) == null || l.call(r, k), o("error", k);
407
+ a.info(
408
+ "[Vuethenticate] LogoutCallback: Processing logout callback"
409
+ );
410
+ const d = await n();
411
+ a.info(
412
+ "[Vuethenticate] LogoutCallback: Logout callback completed successfully"
413
+ ), (g = r.onSuccess) == null || g.call(r, d.state), u("success", d.state);
414
+ } catch (d) {
415
+ const k = d instanceof Error ? d : new Error("Logout callback processing failed");
416
+ a.error(
417
+ "[Vuethenticate] LogoutCallback: Logout callback failed",
418
+ k
419
+ ), s.value = k, (o = r.onError) == null || o.call(r, k), u("error", k);
324
420
  } finally {
325
- s.value = !1;
421
+ l.value = !1;
326
422
  }
327
423
  };
328
- return T(() => {
329
- p();
330
- }), (d, l) => (L(c) || s.value) && !a.value ? S(d.$slots, "default", { key: 0 }, () => [
331
- l[0] || (l[0] = y("p", null, "Processing logout...", -1))
332
- ]) : a.value ? S(d.$slots, "error", {
424
+ return z(() => {
425
+ b();
426
+ }), (g, o) => (M(c) || l.value) && !s.value ? S(g.$slots, "default", { key: 0 }, () => [
427
+ o[0] || (o[0] = v("p", null, "Processing logout...", -1))
428
+ ]) : s.value ? S(g.$slots, "error", {
333
429
  key: 1,
334
- error: a.value
430
+ error: s.value
335
431
  }, () => [
336
- y("div", null, [
337
- l[1] || (l[1] = y("h2", null, "Logout Error", -1)),
338
- y("p", null, x(a.value.message), 1)
432
+ v("div", null, [
433
+ o[1] || (o[1] = v("h2", null, "Logout Error", -1)),
434
+ v("p", null, x(s.value.message), 1)
339
435
  ])
340
- ]) : S(d.$slots, "success", { key: 2 }, () => [
341
- l[2] || (l[2] = y("div", null, [
342
- y("h2", null, "Logout Successful"),
343
- y("p", null, "You have been logged out successfully.")
436
+ ]) : S(g.$slots, "success", { key: 2 }, () => [
437
+ o[2] || (o[2] = v("div", null, [
438
+ v("h2", null, "Logout Successful"),
439
+ v("p", null, "You have been logged out successfully.")
344
440
  ], -1))
345
441
  ]);
346
442
  }
347
- }), le = /* @__PURE__ */ M({
443
+ }), ke = /* @__PURE__ */ V({
348
444
  __name: "SilentCallback",
349
445
  props: {
350
446
  onError: { type: Function }
351
447
  },
352
448
  setup(e) {
353
- const t = e, { processSilentCallback: r, isInitializing: o } = R(), n = m(null), c = async () => {
354
- var s;
449
+ const t = e, { processSilentCallback: r, isInitializing: u, logger: n } = O(), c = y(null), a = async () => {
450
+ var l;
355
451
  try {
356
- await r();
357
- } catch (a) {
358
- const p = a instanceof Error ? a : new Error("Silent callback processing failed");
359
- n.value = p, (s = t.onError) == null || s.call(t, p), console.error("Silent callback error:", p);
452
+ n.debug(
453
+ "[Vuethenticate] SilentCallback: Processing silent callback"
454
+ ), await r();
455
+ } catch (s) {
456
+ const b = s instanceof Error ? s : new Error("Silent callback processing failed");
457
+ n.error(
458
+ "[Vuethenticate] SilentCallback: Silent callback failed",
459
+ b
460
+ ), c.value = b, (l = t.onError) == null || l.call(t, b);
360
461
  }
361
462
  };
362
- return T(() => {
363
- c();
364
- }), (s, a) => (P(), F(K, null, [
365
- L(o) && !n.value ? S(s.$slots, "default", { key: 0 }, () => [
366
- a[0] || (a[0] = y("p", null, "Processing silent renewal...", -1))
367
- ]) : U("", !0),
368
- n.value ? S(s.$slots, "error", {
463
+ return z(() => {
464
+ a();
465
+ }), (l, s) => (_(), P(B, null, [
466
+ M(u) && !c.value ? S(l.$slots, "default", { key: 0 }, () => [
467
+ s[0] || (s[0] = v("p", null, "Processing silent renewal...", -1))
468
+ ]) : I("", !0),
469
+ c.value ? S(l.$slots, "error", {
369
470
  key: 1,
370
- error: n.value
471
+ error: c.value
371
472
  }, () => [
372
- y("p", null, "Silent renewal error: " + x(n.value.message), 1)
373
- ]) : U("", !0)
473
+ v("p", null, "Silent renewal error: " + x(c.value.message), 1)
474
+ ]) : I("", !0)
374
475
  ], 64));
375
476
  }
376
477
  });
377
478
  export {
378
- ae as AuthCallback,
379
- se as LogoutCallback,
380
- le as SilentCallback,
381
- ne as useAuth
479
+ ge as AuthCallback,
480
+ f as LogLevel,
481
+ he as LogoutCallback,
482
+ ke as SilentCallback,
483
+ D as consoleLogger,
484
+ Q as silentLogger,
485
+ de as useAuth
382
486
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(k,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue"),require("oidc-client-ts")):typeof define=="function"&&define.amd?define(["exports","vue","oidc-client-ts"],t):(k=typeof globalThis<"u"?globalThis:k||self,t(k.Vuethenticate={},k.Vue,k.OidcClientTs))})(this,function(k,t,I){"use strict";function L(e){const n=typeof window<"u"?window.location.origin:"";return{authority:e.authority,client_id:e.clientId,client_secret:e.clientSecret,client_authentication:e.clientAuthentication,redirect_uri:e.redirectUri??`${n}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new I.WebStorageStateStore({store:R(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${n}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??`${n}/auth/logout-callback`,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function R(e){if(typeof window>"u")return M();switch(e){case"localStorage":return window.localStorage;case"sessionStorage":return window.sessionStorage;case"memory":return M();default:return window.localStorage}}function M(){const e=new Map;return{getItem:n=>e.get(n)??null,setItem:(n,r)=>e.set(n,r),removeItem:n=>e.delete(n),clear:()=>e.clear(),get length(){return e.size},key:n=>Array.from(e.keys())[n]??null}}const g=new Map,V=e=>{try{const{userManager:n,eventCallbacks:r}=e;r.userLoaded&&n.events.removeUserLoaded(r.userLoaded),r.userUnloaded&&n.events.removeUserUnloaded(r.userUnloaded),r.accessTokenExpired&&n.events.removeAccessTokenExpired(r.accessTokenExpired),r.accessTokenExpiring&&n.events.removeAccessTokenExpiring(r.accessTokenExpiring),r.silentRenewError&&n.events.removeSilentRenewError(r.silentRenewError),n.stopSilentRenew(),n.clearStaleState()}catch(n){console.warn("Error during UserManager cleanup:",n)}},T=e=>`${e.authority}_${e.clientId}`,x=()=>g.size===0?null:(g.size===1||console.warn("Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."),Array.from(g.values())[0]||null),N=e=>{const n=T(e),r=g.get(n);if(r)return r;const i=$(e),a=t.ref(!1),d=t.ref(!1),l=t.ref(null),s=t.ref(!1),E=t.ref(null),m=t.computed(()=>!!l.value&&!l.value.expired),o=t.computed(()=>{var h;return((h=l.value)==null?void 0:h.access_token)||null}),u=t.computed(()=>{var h;return!!((h=l.value)!=null&&h.expired)}),p={userManager:i,isInitialized:a,isInitializing:d,user:l,isLoading:s,error:E,isAuthenticated:m,accessToken:o,isExpired:u,eventCallbacks:{}};return g.set(n,p),p},$=e=>{const n=L(e);return new I.UserManager(n)},b=(e,n,r,i)=>{const a=e instanceof Error?e:new Error(n);return r.value=a,i==null||i(a),a},_=e=>{var n,r;if(!((n=e.authority)!=null&&n.trim()))throw new Error("AuthConfig: authority is required");if(!((r=e.clientId)!=null&&r.trim()))throw new Error("AuthConfig: clientId is required");try{new URL(e.authority)}catch{throw new Error("AuthConfig: authority must be a valid URL")}},v=async(e,n=1e4)=>{if(!e.isInitialized.value)return new Promise((r,i)=>{const a=setTimeout(()=>{i(new Error("Authentication initialization timeout"))},n),d=t.watch(e.isInitialized,l=>{l&&(clearTimeout(a),d(),r())},{immediate:!0})})},F=e=>{_(e);const n=N(e),{userManager:r,isInitialized:i,isInitializing:a,user:d,isLoading:l,error:s,isAuthenticated:E,accessToken:m,isExpired:o}=n,u=T(e),p=async()=>{if(!(a.value||i.value))try{a.value=!0,l.value=!0,s.value=null;const w=await r.getUser();if(w)if(!w.expired)d.value=w;else if(e.automaticSilentRenew!==!1)try{await z()}catch(c){console.warn("Silent renewal failed during initialization:",c),await r.removeUser(),d.value=null}else await r.removeUser(),d.value=null}catch(w){b(w,"Failed to initialize authentication",s,e.onError)}finally{l.value=!1,a.value=!1,i.value=!0}},h=async w=>{try{l.value=!0,s.value=null,await r.signinRedirect({state:w})}catch(c){b(c,"Sign in failed",s,e.onError)}finally{l.value=!1}},O=async w=>{try{l.value=!0,s.value=null,d.value=null,await r.signoutRedirect({state:w})}catch(c){b(c,"Sign out failed",s,e.onError)}finally{l.value=!1}},z=async()=>{try{l.value=!0,s.value=null;const w=await r.signinSilent();d.value=w}catch(w){throw b(w,"Silent renewal failed",s,e.onError)}finally{l.value=!1}},D=()=>{s.value=null},K=(w,c)=>{const{userManager:S,user:A,error:W,eventCallbacks:f}=w;f.userLoaded=y=>{var C;A.value=y,(C=c.onUserLoaded)==null||C.call(c,y)},f.userUnloaded=()=>{var y;A.value=null,(y=c.onUserUnloaded)==null||y.call(c)},f.accessTokenExpired=()=>{var y;(y=c.onAccessTokenExpired)==null||y.call(c)},f.accessTokenExpiring=()=>{var y;(y=c.onAccessTokenExpiring)==null||y.call(c)},f.silentRenewError=async y=>{console.warn("Silent renewal failed:",y);try{await S.removeUser(),A.value=null}catch(C){console.error("Failed to remove user after silent renewal error:",C)}b(y,"Silent renewal failed",W,c.onError)},S.events.addUserLoaded(f.userLoaded),S.events.addUserUnloaded(f.userUnloaded),S.events.addAccessTokenExpired(f.accessTokenExpired),S.events.addAccessTokenExpiring(f.accessTokenExpiring),S.events.addSilentRenewError(f.silentRenewError)},j=()=>{V(n),g.delete(u)};return!i.value&&!a.value&&(p(),K(n,e)),{user:d,isAuthenticated:E,isLoading:l,error:s,accessToken:m,isExpired:o,signIn:h,signOut:O,silentRenew:z,clearError:D,cleanup:j}},U=()=>{const e=x();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async()=>{await v(e);const a=await e.userManager.signinCallback();if(!a)throw new Error("Authentication callback failed: no user returned");return{user:a,state:a.state}},processLogoutCallback:async()=>{await v(e);const a=await e.userManager.signoutCallback();return{state:a==null?void 0:a.state}},processSilentCallback:async()=>{await v(e),await e.userManager.signinCallback()},isInitialized:e.isInitialized,isInitializing:e.isInitializing}},P=t.defineComponent({__name:"AuthCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:n}){const r=e,i=n,{processCallback:a,isInitializing:d}=U(),l=t.ref(!0),s=t.ref(null),E=async()=>{var m,o;try{const u=await a();(m=r.onSuccess)==null||m.call(r,u.user,u.state),i("success",u.user,u.state)}catch(u){const p=u instanceof Error?u:new Error("Callback processing failed");s.value=p,(o=r.onError)==null||o.call(r,p),i("error",p)}finally{l.value=!1}};return t.onMounted(()=>{E()}),(m,o)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[(t.unref(d)||l.value)&&!s.value?t.renderSlot(m.$slots,"default",{key:0},()=>[o[0]||(o[0]=t.createElementVNode("p",null,"Processing authentication...",-1))]):t.createCommentVNode("",!0),s.value?t.renderSlot(m.$slots,"error",{key:1,error:s.value},()=>[t.createElementVNode("div",null,[o[1]||(o[1]=t.createElementVNode("h2",null,"Authentication Error",-1)),t.createElementVNode("p",null,t.toDisplayString(s.value.message),1)])]):t.createCommentVNode("",!0)],64))}}),q=t.defineComponent({__name:"LogoutCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:n}){const r=e,i=n,{processLogoutCallback:a,isInitializing:d}=U(),l=t.ref(!0),s=t.ref(null),E=async()=>{var m,o;try{const u=await a();(m=r.onSuccess)==null||m.call(r,u.state),i("success",u.state)}catch(u){const p=u instanceof Error?u:new Error("Logout callback processing failed");s.value=p,(o=r.onError)==null||o.call(r,p),i("error",p)}finally{l.value=!1}};return t.onMounted(()=>{E()}),(m,o)=>(t.unref(d)||l.value)&&!s.value?t.renderSlot(m.$slots,"default",{key:0},()=>[o[0]||(o[0]=t.createElementVNode("p",null,"Processing logout...",-1))]):s.value?t.renderSlot(m.$slots,"error",{key:1,error:s.value},()=>[t.createElementVNode("div",null,[o[1]||(o[1]=t.createElementVNode("h2",null,"Logout Error",-1)),t.createElementVNode("p",null,t.toDisplayString(s.value.message),1)])]):t.renderSlot(m.$slots,"success",{key:2},()=>[o[2]||(o[2]=t.createElementVNode("div",null,[t.createElementVNode("h2",null,"Logout Successful"),t.createElementVNode("p",null,"You have been logged out successfully.")],-1))])}}),B=t.defineComponent({__name:"SilentCallback",props:{onError:{type:Function}},setup(e){const n=e,{processSilentCallback:r,isInitializing:i}=U(),a=t.ref(null),d=async()=>{var l;try{await r()}catch(s){const E=s instanceof Error?s:new Error("Silent callback processing failed");a.value=E,(l=n.onError)==null||l.call(n,E),console.error("Silent callback error:",E)}};return t.onMounted(()=>{d()}),(l,s)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.unref(i)&&!a.value?t.renderSlot(l.$slots,"default",{key:0},()=>[s[0]||(s[0]=t.createElementVNode("p",null,"Processing silent renewal...",-1))]):t.createCommentVNode("",!0),a.value?t.renderSlot(l.$slots,"error",{key:1,error:a.value},()=>[t.createElementVNode("p",null,"Silent renewal error: "+t.toDisplayString(a.value.message),1)]):t.createCommentVNode("",!0)],64))}});k.AuthCallback=P,k.LogoutCallback=q,k.SilentCallback=B,k.useAuth=F,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
1
+ (function(f,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("oidc-client-ts")):typeof define=="function"&&define.amd?define(["exports","vue","oidc-client-ts"],r):(f=typeof globalThis<"u"?globalThis:f||self,r(f.Vuethenticate={},f.Vue,f.OidcClientTs))})(this,function(f,r,y){"use strict";var b=(e=>(e[e.NONE=0]="NONE",e[e.ERROR=1]="ERROR",e[e.WARN=2]="WARN",e[e.INFO=3]="INFO",e[e.DEBUG=4]="DEBUG",e))(b||{});const v={error:(e,...t)=>console.error(e,...t),warn:(e,...t)=>console.warn(e,...t),info:(e,...t)=>console.info(e,...t),debug:(e,...t)=>console.debug(e,...t)},I={error:()=>{},warn:()=>{},info:()=>{},debug:()=>{}},T=(e,t)=>({error:t>=1?e.error:()=>{},warn:t>=2?e.warn:()=>{},info:t>=3?e.info:()=>{},debug:t>=4?e.debug:()=>{}});function x(e){const t=typeof window<"u"?window.location.origin:"";return F(e),{authority:e.authority,client_id:e.clientId,client_secret:e.clientSecret,client_authentication:e.clientAuthentication,redirect_uri:e.redirectUri??`${t}/auth/callback`,scope:e.scope??"openid profile",response_type:e.responseType??"code",userStore:e.storage?new y.WebStorageStateStore({store:$(e.storage)}):void 0,automaticSilentRenew:e.automaticSilentRenew??!0,silent_redirect_uri:e.silentRedirectUri??`${t}/auth/silent-callback`,post_logout_redirect_uri:e.postLogoutRedirectUri??`${t}/auth/logout-callback`,includeIdTokenInSilentRenew:!0,accessTokenExpiringNotificationTimeInSeconds:60}}function $(e){if(typeof window>"u")return M();switch(e){case"localStorage":return window.localStorage;case"sessionStorage":return window.sessionStorage;case"memory":return M();default:return window.localStorage}}function M(){const e=new Map;return{getItem:t=>e.get(t)??null,setItem:(t,n)=>e.set(t,n),removeItem:t=>e.delete(t),clear:()=>e.clear(),get length(){return e.size},key:t=>Array.from(e.keys())[t]??null}}const F=e=>{if(e.logLevel===void 0&&!e.logger)return;const t=e.logger??(e.logLevel!==void 0?v:void 0),n=e.logLevel??b.NONE;t&&(y.Log.setLogger({error:t.error,warn:t.warn,info:t.info,debug:t.debug}),y.Log.setLevel(P(n)))},P=e=>{switch(e){case b.NONE:return y.Log.NONE;case b.ERROR:return y.Log.ERROR;case b.WARN:return y.Log.WARN;case b.INFO:return y.Log.INFO;case b.DEBUG:return y.Log.DEBUG;default:return y.Log.NONE}},S=new Map,_=e=>{try{const{userManager:t,eventCallbacks:n}=e;n.userLoaded&&t.events.removeUserLoaded(n.userLoaded),n.userUnloaded&&t.events.removeUserUnloaded(n.userUnloaded),n.accessTokenExpired&&t.events.removeAccessTokenExpired(n.accessTokenExpired),n.accessTokenExpiring&&t.events.removeAccessTokenExpiring(n.accessTokenExpiring),n.silentRenewError&&t.events.removeSilentRenewError(n.silentRenewError),t.stopSilentRenew(),t.clearStaleState()}catch(t){console.warn("Error during UserManager cleanup:",t)}},z=e=>`${e.authority}_${e.clientId}`,B=()=>S.size===0?null:(S.size===1||console.warn("Multiple auth instances detected. Callback components may not work as expected. Consider using a single auth instance or specify config explicitly."),Array.from(S.values())[0]||null),D=e=>{const t=z(e),n=S.get(t);if(n)return n;const u=W(e),a=r.ref(!1),d=r.ref(!1),l=r.ref(null),o=r.ref(!1),s=r.ref(null),E=r.computed(()=>!!l.value&&!l.value.expired),h=r.computed(()=>{var A;return((A=l.value)==null?void 0:A.access_token)||null}),i=r.computed(()=>{var A;return!!((A=l.value)!=null&&A.expired)}),g=q(e),m={userManager:u,isInitialized:a,isInitializing:d,user:l,isLoading:o,error:s,isAuthenticated:E,accessToken:h,isExpired:i,logger:g,eventCallbacks:{}};return S.set(t,m),m},W=e=>{const t=x(e);return new y.UserManager(t)},q=e=>{if(!e.logger&&!e.logLevel)return I;const t=e.logger??v,n=e.logLevel??b.NONE;return T(t,n)},V=(e,t,n,u)=>{const a=e instanceof Error?e:new Error(t);return n.value=a,u==null||u(a),a},G=e=>{var t,n;if(!((t=e.authority)!=null&&t.trim()))throw new Error("AuthConfig: authority is required");if(!((n=e.clientId)!=null&&n.trim()))throw new Error("AuthConfig: clientId is required");try{new URL(e.authority)}catch{throw new Error("AuthConfig: authority must be a valid URL")}},L=async(e,t=1e4)=>{if(!e.isInitialized.value)return new Promise((n,u)=>{const a=setTimeout(()=>{u(new Error("Authentication initialization timeout"))},t),d=r.watch(e.isInitialized,l=>{l&&(clearTimeout(a),d(),n())},{immediate:!0})})},K=e=>{G(e);const t=D(e),{userManager:n,isInitialized:u,isInitializing:a,user:d,isLoading:l,error:o,isAuthenticated:s,accessToken:E,isExpired:h}=t,i=z(e),g=async()=>{if(!(a.value||u.value))try{a.value=!0,l.value=!0,o.value=null;const k=await n.getUser();if(k)if(!k.expired)d.value=k,t.logger.info("[Vuethenticate] useAuth: User restored from storage");else if(e.automaticSilentRenew!==!1){t.logger.info("[Vuethenticate] useAuth: Token expired, attempting silent renewal");try{await O()}catch(c){t.logger.warn("[Vuethenticate] useAuth: Silent renewal failed during initialization",c),await n.removeUser(),d.value=null}}else await n.removeUser(),d.value=null;u.value=!0}catch(k){t.logger.error("[Vuethenticate] useAuth: Initialization failed",k),V(k,"Authentication initialization failed",o,e.onError)}finally{a.value=!1,l.value=!1}},m=async k=>{try{l.value=!0,o.value=null,t.logger.info("[Vuethenticate] useAuth: Starting sign-in flow"),await n.signinRedirect({state:k})}catch(c){t.logger.error("[Vuethenticate] useAuth: Sign-in failed",c),V(c,"Sign in failed",o,e.onError)}finally{l.value=!1}},A=async k=>{try{l.value=!0,o.value=null,d.value=null,t.logger.info("[Vuethenticate] useAuth: Starting sign-out flow"),await n.signoutRedirect({state:k})}catch(c){t.logger.error("[Vuethenticate] useAuth: Sign-out failed",c),V(c,"Sign out failed",o,e.onError)}finally{l.value=!1}},O=async()=>{try{l.value=!0,o.value=null;const k=await n.signinSilent();d.value=k}catch(k){throw V(k,"Silent renewal failed",o,e.onError)}finally{l.value=!1}},J=()=>{o.value=null},Q=(k,c)=>{const{userManager:C,user:U,error:Z,eventCallbacks:p}=k;p.userLoaded=w=>{var N;U.value=w,(N=c.onUserLoaded)==null||N.call(c,w)},p.userUnloaded=()=>{var w;U.value=null,(w=c.onUserUnloaded)==null||w.call(c)},p.accessTokenExpired=()=>{var w;(w=c.onAccessTokenExpired)==null||w.call(c)},p.accessTokenExpiring=()=>{var w;(w=c.onAccessTokenExpiring)==null||w.call(c)},p.silentRenewError=async w=>{console.warn("Silent renewal failed:",w);try{await C.removeUser(),U.value=null}catch(N){console.error("Failed to remove user after silent renewal error:",N)}V(w,"Silent renewal failed",Z,c.onError)},C.events.addUserLoaded(p.userLoaded),C.events.addUserUnloaded(p.userUnloaded),C.events.addAccessTokenExpired(p.accessTokenExpired),C.events.addAccessTokenExpiring(p.accessTokenExpiring),C.events.addSilentRenewError(p.silentRenewError)},X=()=>{_(t),S.delete(i)};return!u.value&&!a.value&&(g(),Q(t,e)),{user:d,isAuthenticated:s,isLoading:l,error:o,accessToken:E,isExpired:h,signIn:m,signOut:A,silentRenew:O,clearError:J,cleanup:X}},R=()=>{const e=B();if(!e)throw new Error("Authentication not initialized. Make sure useAuth() is called in a parent component first.");return{processCallback:async()=>{await L(e),e.logger.info("[Vuethenticate] useAuthCallbacks: Processing authentication callback");const a=await e.userManager.signinCallback();if(!a)throw new Error("Authentication callback failed: no user returned");return e.logger.info("[Vuethenticate] useAuthCallbacks: Authentication callback successful"),{user:a,state:a.state}},processLogoutCallback:async()=>{await L(e),e.logger.debug("[Vuethenticate] useAuthCallbacks: Processing logout callback");const a=await e.userManager.signoutCallback();return e.logger.info("[Vuethenticate] useAuthCallbacks: Logout callback completed successfully"),{state:a==null?void 0:a.userState}},processSilentCallback:async()=>{await L(e),e.logger.debug("[Vuethenticate] useAuthCallbacks: Processing silent callback"),await e.userManager.signinCallback(),e.logger.debug("[Vuethenticate] useAuthCallbacks: Silent callback completed successfully")},isInitialized:e.isInitialized,isInitializing:e.isInitializing,logger:e.logger}},j=r.defineComponent({__name:"AuthCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:t}){const n=e,u=t,{processCallback:a,isInitializing:d,logger:l}=R(),o=r.ref(!0),s=r.ref(null),E=async()=>{var h,i;try{l.info("[Vuethenticate] AuthCallback: Processing authentication callback");const g=await a();l.info("[Vuethenticate] AuthCallback: Authentication callback completed successfully"),(h=n.onSuccess)==null||h.call(n,g.user,g.state),u("success",g.user,g.state)}catch(g){const m=g instanceof Error?g:new Error("Callback processing failed");l.error("[Vuethenticate] AuthCallback: Authentication callback failed",m),s.value=m,(i=n.onError)==null||i.call(n,m),u("error",m)}finally{o.value=!1}};return r.onMounted(()=>{E()}),(h,i)=>(r.openBlock(),r.createElementBlock(r.Fragment,null,[(r.unref(d)||o.value)&&!s.value?r.renderSlot(h.$slots,"default",{key:0},()=>[i[0]||(i[0]=r.createElementVNode("p",null,"Processing authentication...",-1))]):r.createCommentVNode("",!0),s.value?r.renderSlot(h.$slots,"error",{key:1,error:s.value},()=>[r.createElementVNode("div",null,[i[1]||(i[1]=r.createElementVNode("h2",null,"Authentication Error",-1)),r.createElementVNode("p",null,r.toDisplayString(s.value.message),1)])]):r.createCommentVNode("",!0)],64))}}),Y=r.defineComponent({__name:"LogoutCallback",props:{onSuccess:{type:Function},onError:{type:Function}},emits:["success","error"],setup(e,{emit:t}){const n=e,u=t,{processLogoutCallback:a,isInitializing:d,logger:l}=R(),o=r.ref(!0),s=r.ref(null),E=async()=>{var h,i;try{l.info("[Vuethenticate] LogoutCallback: Processing logout callback");const g=await a();l.info("[Vuethenticate] LogoutCallback: Logout callback completed successfully"),(h=n.onSuccess)==null||h.call(n,g.state),u("success",g.state)}catch(g){const m=g instanceof Error?g:new Error("Logout callback processing failed");l.error("[Vuethenticate] LogoutCallback: Logout callback failed",m),s.value=m,(i=n.onError)==null||i.call(n,m),u("error",m)}finally{o.value=!1}};return r.onMounted(()=>{E()}),(h,i)=>(r.unref(d)||o.value)&&!s.value?r.renderSlot(h.$slots,"default",{key:0},()=>[i[0]||(i[0]=r.createElementVNode("p",null,"Processing logout...",-1))]):s.value?r.renderSlot(h.$slots,"error",{key:1,error:s.value},()=>[r.createElementVNode("div",null,[i[1]||(i[1]=r.createElementVNode("h2",null,"Logout Error",-1)),r.createElementVNode("p",null,r.toDisplayString(s.value.message),1)])]):r.renderSlot(h.$slots,"success",{key:2},()=>[i[2]||(i[2]=r.createElementVNode("div",null,[r.createElementVNode("h2",null,"Logout Successful"),r.createElementVNode("p",null,"You have been logged out successfully.")],-1))])}}),H=r.defineComponent({__name:"SilentCallback",props:{onError:{type:Function}},setup(e){const t=e,{processSilentCallback:n,isInitializing:u,logger:a}=R(),d=r.ref(null),l=async()=>{var o;try{a.debug("[Vuethenticate] SilentCallback: Processing silent callback"),await n()}catch(s){const E=s instanceof Error?s:new Error("Silent callback processing failed");a.error("[Vuethenticate] SilentCallback: Silent callback failed",E),d.value=E,(o=t.onError)==null||o.call(t,E)}};return r.onMounted(()=>{l()}),(o,s)=>(r.openBlock(),r.createElementBlock(r.Fragment,null,[r.unref(u)&&!d.value?r.renderSlot(o.$slots,"default",{key:0},()=>[s[0]||(s[0]=r.createElementVNode("p",null,"Processing silent renewal...",-1))]):r.createCommentVNode("",!0),d.value?r.renderSlot(o.$slots,"error",{key:1,error:d.value},()=>[r.createElementVNode("p",null,"Silent renewal error: "+r.toDisplayString(d.value.message),1)]):r.createCommentVNode("",!0)],64))}});f.AuthCallback=j,f.LogLevel=b,f.LogoutCallback=Y,f.SilentCallback=H,f.consoleLogger=v,f.silentLogger=I,f.useAuth=K,Object.defineProperty(f,Symbol.toStringTag,{value:"Module"})});
@@ -1,4 +1,5 @@
1
1
  import { ComputedRef, Ref } from 'vue';
2
+ import { LogLevel, Logger } from '../utils/logger';
2
3
  import { User } from 'oidc-client-ts';
3
4
  export interface AuthConfig {
4
5
  authority: string;
@@ -12,6 +13,8 @@ export interface AuthConfig {
12
13
  automaticSilentRenew?: boolean;
13
14
  silentRedirectUri?: string;
14
15
  postLogoutRedirectUri?: string;
16
+ logLevel?: LogLevel;
17
+ logger?: Logger;
15
18
  onError?: (error: Error) => void;
16
19
  onUserLoaded?: (user: User) => void;
17
20
  onUserUnloaded?: () => void;
@@ -40,6 +43,19 @@ export interface AuthCallbackMethods<TState = unknown> {
40
43
  }>;
41
44
  processSilentCallback: (url?: string) => Promise<void>;
42
45
  }
46
+ export interface UseAuthCallbacksReturn<TState = unknown> {
47
+ processCallback: () => Promise<{
48
+ user: User;
49
+ state?: TState;
50
+ }>;
51
+ processLogoutCallback: () => Promise<{
52
+ state?: TState;
53
+ }>;
54
+ processSilentCallback: () => Promise<void>;
55
+ isInitialized: Ref<boolean>;
56
+ isInitializing: Ref<boolean>;
57
+ logger: Logger;
58
+ }
43
59
  export type UseAuthReturn<TState = unknown> = AuthState & AuthMethods<TState>;
44
60
  export interface AuthCallbackProps<TState = unknown> {
45
61
  onSuccess?: (user: User, state?: TState) => void;
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/types/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAA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,GAAG,CAAC,OAAO,CAAC,CAAC;IAC5B,cAAc,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,aAAa,CAAC,MAAM,GAAG,OAAO,IAAI,SAAS,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;AAE9E,MAAM,WAAW,iBAAiB,CAAC,MAAM,GAAG,OAAO;IAC/C,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,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,MAAM,WAAW,mBAAmB,CAAC,MAAM,GAAG,OAAO;IACjD,SAAS,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACpC;AAED,OAAO,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC"}
@@ -1,5 +1,5 @@
1
- import { AuthConfig } from '../types/auth';
2
1
  import { UserManagerSettings } from 'oidc-client-ts';
2
+ import { AuthConfig } from '../types/auth';
3
3
  /**
4
4
  * Creates UserManager settings from auth configuration
5
5
  * @param config - The authentication configuration
@@ -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,EAEH,KAAK,mBAAmB,EAE3B,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;GAIG;AACH,wBAAgB,yBAAyB,CACrC,MAAM,EAAE,UAAU,GACnB,mBAAmB,CAyBrB"}
@@ -0,0 +1,3 @@
1
+ export * from './configHelpers';
2
+ export * from './logger';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,UAAU,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Log levels for authentication library
3
+ */
4
+ export declare enum LogLevel {
5
+ NONE = 0,
6
+ ERROR = 1,
7
+ WARN = 2,
8
+ INFO = 3,
9
+ DEBUG = 4
10
+ }
11
+ /**
12
+ * Logger interface for authentication library
13
+ */
14
+ export interface Logger {
15
+ error: (message: string, ...args: unknown[]) => void;
16
+ warn: (message: string, ...args: unknown[]) => void;
17
+ info: (message: string, ...args: unknown[]) => void;
18
+ debug: (message: string, ...args: unknown[]) => void;
19
+ }
20
+ /**
21
+ * Console logger implementation
22
+ */
23
+ export declare const consoleLogger: Logger;
24
+ /**
25
+ * Silent logger implementation that does nothing
26
+ */
27
+ export declare const silentLogger: Logger;
28
+ /**
29
+ * Creates a filtered logger based on log level
30
+ * @param logger - Base logger implementation
31
+ * @param level - Minimum log level to output
32
+ * @returns Filtered logger instance
33
+ */
34
+ export declare const createLevelLogger: (logger: Logger, level: LogLevel) => Logger;
35
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../src/utils/logger.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,QAAQ;IAChB,IAAI,IAAI;IACR,KAAK,IAAI;IACT,IAAI,IAAI;IACR,IAAI,IAAI;IACR,KAAK,IAAI;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,MAAM;IACnB,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACrD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpD,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;IACpD,KAAK,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,CAAC;CACxD;AAED;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,MAS3B,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,MAK1B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,MAAM,EAAE,OAAO,QAAQ,KAAG,MAOnE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vuethenticate",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "A Vue 3 authentication state management library using oidc-client-ts",
5
5
  "keywords": [
6
6
  "vue",
@@ -28,7 +28,7 @@
28
28
  "types": "dist/index.d.ts",
29
29
  "scripts": {
30
30
  "build": "vite build",
31
- "dev": "vite build --watch",
31
+ "dev": "cross-env CHOKIDAR_USEPOLLING=1 vite build --watch",
32
32
  "type-check": "vue-tsc --noEmit",
33
33
  "test": "echo \"Error: no test specified\" && exit 1"
34
34
  },