@opensourcekd/ng-common-libs 1.2.6 → 1.2.7
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 +10 -8
- package/dist/angular/index.cjs +150 -9
- package/dist/angular/index.cjs.map +1 -1
- package/dist/angular/index.d.ts +18 -2
- package/dist/angular/index.mjs +150 -9
- package/dist/angular/index.mjs.map +1 -1
- package/dist/index.cjs +150 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +18 -2
- package/dist/index.mjs +150 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -357,6 +357,10 @@ declare class AuthService {
|
|
|
357
357
|
/**
|
|
358
358
|
* Auth0 client configuration
|
|
359
359
|
* Override these values in your consuming application by setting them before importing AuthService
|
|
360
|
+
*
|
|
361
|
+
* Note: redirectUri defaults to window.location.origin (base URL without path).
|
|
362
|
+
* Auth0 will redirect back to this URL after authentication.
|
|
363
|
+
* You can override this to a specific callback URL (e.g., '/auth-callback') using configureAuth0().
|
|
360
364
|
*/
|
|
361
365
|
declare const AUTH0_CONFIG: {
|
|
362
366
|
domain: string;
|
|
@@ -407,17 +411,29 @@ declare function setStorageItem(key: string, value: string, storageType?: 'local
|
|
|
407
411
|
*/
|
|
408
412
|
declare function removeStorageItem(key: string, storageType?: 'localStorage' | 'sessionStorage'): void;
|
|
409
413
|
/**
|
|
410
|
-
* Configure Auth0 settings
|
|
411
|
-
* Call this function in your consuming application
|
|
414
|
+
* Configure Auth0 settings (OPTIONAL)
|
|
415
|
+
* Call this function in your consuming application to override default Auth0 configuration.
|
|
416
|
+
* Only the values you provide will be overridden; all other defaults remain unchanged.
|
|
417
|
+
*
|
|
418
|
+
* Note: This function is optional. If not called, default values will be used.
|
|
419
|
+
*
|
|
420
|
+
* @param config - Partial Auth0 configuration object with values to override
|
|
412
421
|
*
|
|
413
422
|
* @example
|
|
414
423
|
* ```typescript
|
|
415
424
|
* import { configureAuth0 } from '@opensourcekd/ng-common-libs';
|
|
416
425
|
*
|
|
426
|
+
* // Only override specific values - others keep their defaults
|
|
417
427
|
* configureAuth0({
|
|
418
428
|
* domain: 'your-domain.auth0.com',
|
|
419
429
|
* clientId: 'your-client-id',
|
|
420
430
|
* audience: 'https://your-api.com'
|
|
431
|
+
* // redirectUri, logoutUri, scope, etc. will use defaults
|
|
432
|
+
* });
|
|
433
|
+
*
|
|
434
|
+
* // Or override just redirectUri to use a specific callback page
|
|
435
|
+
* configureAuth0({
|
|
436
|
+
* redirectUri: window.location.origin + '/auth-callback'
|
|
421
437
|
* });
|
|
422
438
|
* ```
|
|
423
439
|
*/
|
package/dist/index.mjs
CHANGED
|
@@ -282,11 +282,15 @@ function jwtDecode(token, options) {
|
|
|
282
282
|
/**
|
|
283
283
|
* Auth0 client configuration
|
|
284
284
|
* Override these values in your consuming application by setting them before importing AuthService
|
|
285
|
+
*
|
|
286
|
+
* Note: redirectUri defaults to window.location.origin (base URL without path).
|
|
287
|
+
* Auth0 will redirect back to this URL after authentication.
|
|
288
|
+
* You can override this to a specific callback URL (e.g., '/auth-callback') using configureAuth0().
|
|
285
289
|
*/
|
|
286
290
|
const AUTH0_CONFIG = {
|
|
287
291
|
domain: '', // Set in consuming app: process.env['NX_AUTH0_DOMAIN'] || 'your-domain.auth0.com'
|
|
288
292
|
clientId: '', // Set in consuming app: process.env['NX_AUTH0_CLIENT_ID'] || 'your-client-id'
|
|
289
|
-
redirectUri: typeof window !== 'undefined' ? window.location.origin
|
|
293
|
+
redirectUri: typeof window !== 'undefined' ? window.location.origin : '',
|
|
290
294
|
logoutUri: typeof window !== 'undefined' ? window.location.origin : '',
|
|
291
295
|
audience: '', // Optional: Set in consuming app if using API authorization
|
|
292
296
|
scope: 'openid profile email', // Default scopes
|
|
@@ -347,22 +351,55 @@ function removeStorageItem(key, storageType = 'sessionStorage') {
|
|
|
347
351
|
storage.removeItem(key);
|
|
348
352
|
}
|
|
349
353
|
/**
|
|
350
|
-
* Configure Auth0 settings
|
|
351
|
-
* Call this function in your consuming application
|
|
354
|
+
* Configure Auth0 settings (OPTIONAL)
|
|
355
|
+
* Call this function in your consuming application to override default Auth0 configuration.
|
|
356
|
+
* Only the values you provide will be overridden; all other defaults remain unchanged.
|
|
357
|
+
*
|
|
358
|
+
* Note: This function is optional. If not called, default values will be used.
|
|
359
|
+
*
|
|
360
|
+
* @param config - Partial Auth0 configuration object with values to override
|
|
352
361
|
*
|
|
353
362
|
* @example
|
|
354
363
|
* ```typescript
|
|
355
364
|
* import { configureAuth0 } from '@opensourcekd/ng-common-libs';
|
|
356
365
|
*
|
|
366
|
+
* // Only override specific values - others keep their defaults
|
|
357
367
|
* configureAuth0({
|
|
358
368
|
* domain: 'your-domain.auth0.com',
|
|
359
369
|
* clientId: 'your-client-id',
|
|
360
370
|
* audience: 'https://your-api.com'
|
|
371
|
+
* // redirectUri, logoutUri, scope, etc. will use defaults
|
|
372
|
+
* });
|
|
373
|
+
*
|
|
374
|
+
* // Or override just redirectUri to use a specific callback page
|
|
375
|
+
* configureAuth0({
|
|
376
|
+
* redirectUri: window.location.origin + '/auth-callback'
|
|
361
377
|
* });
|
|
362
378
|
* ```
|
|
363
379
|
*/
|
|
364
380
|
function configureAuth0(config) {
|
|
381
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
382
|
+
console.log('[AuthConfig] 🔍 DEBUG: configureAuth0() called with config:', {
|
|
383
|
+
domain: config.domain || 'not provided',
|
|
384
|
+
clientId: config.clientId ? '[REDACTED]' : 'not provided',
|
|
385
|
+
redirectUri: config.redirectUri || 'not provided',
|
|
386
|
+
logoutUri: config.logoutUri || 'not provided',
|
|
387
|
+
audience: config.audience || 'not provided',
|
|
388
|
+
scope: config.scope || 'not provided',
|
|
389
|
+
connection: config.connection || 'not provided'
|
|
390
|
+
});
|
|
391
|
+
// Only override provided values, keeping defaults for others
|
|
365
392
|
Object.assign(AUTH0_CONFIG, config);
|
|
393
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
394
|
+
console.log('[AuthConfig] 🔍 DEBUG: AUTH0_CONFIG after merge:', {
|
|
395
|
+
domain: AUTH0_CONFIG.domain,
|
|
396
|
+
clientId: AUTH0_CONFIG.clientId ? '[REDACTED]' : undefined,
|
|
397
|
+
redirectUri: AUTH0_CONFIG.redirectUri,
|
|
398
|
+
logoutUri: AUTH0_CONFIG.logoutUri,
|
|
399
|
+
audience: AUTH0_CONFIG.audience || 'not set',
|
|
400
|
+
scope: AUTH0_CONFIG.scope,
|
|
401
|
+
connection: AUTH0_CONFIG.connection || 'not set'
|
|
402
|
+
});
|
|
366
403
|
}
|
|
367
404
|
|
|
368
405
|
/**
|
|
@@ -391,6 +428,8 @@ let AuthService = class AuthService {
|
|
|
391
428
|
constructor(eventBus) {
|
|
392
429
|
this.eventBus = eventBus;
|
|
393
430
|
console.log("[AuthService] Initializing Auth0 authentication service");
|
|
431
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
432
|
+
console.log('[AuthService] 🔍 DEBUG: Constructor called, starting initialization');
|
|
394
433
|
this.initializationPromise = this.initializeAuth0();
|
|
395
434
|
}
|
|
396
435
|
/**
|
|
@@ -399,13 +438,30 @@ let AuthService = class AuthService {
|
|
|
399
438
|
async initializeAuth0() {
|
|
400
439
|
try {
|
|
401
440
|
console.log("[AuthService] Starting Auth0 client initialization...");
|
|
441
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
442
|
+
console.log('[AuthService] 🔍 DEBUG: initializeAuth0 called');
|
|
402
443
|
// Defensive check for AUTH0_CONFIG
|
|
403
444
|
if (!AUTH0_CONFIG || typeof AUTH0_CONFIG !== 'object') {
|
|
445
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
446
|
+
console.error('[AuthService] 🔍 DEBUG: AUTH0_CONFIG validation failed - invalid or undefined');
|
|
404
447
|
throw new Error('[AuthService] AUTH0_CONFIG is not defined or invalid');
|
|
405
448
|
}
|
|
406
449
|
if (!AUTH0_CONFIG.domain || !AUTH0_CONFIG.clientId) {
|
|
450
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
451
|
+
console.error('[AuthService] 🔍 DEBUG: AUTH0_CONFIG validation failed - missing domain or clientId', {
|
|
452
|
+
domain: AUTH0_CONFIG.domain,
|
|
453
|
+
clientId: AUTH0_CONFIG.clientId ? '[REDACTED]' : undefined
|
|
454
|
+
});
|
|
407
455
|
throw new Error('[AuthService] AUTH0_CONFIG is missing required fields (domain, clientId)');
|
|
408
456
|
}
|
|
457
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
458
|
+
console.log('[AuthService] 🔍 DEBUG: Creating Auth0 client with config:', {
|
|
459
|
+
domain: AUTH0_CONFIG.domain,
|
|
460
|
+
clientId: AUTH0_CONFIG.clientId ? '[REDACTED]' : undefined,
|
|
461
|
+
redirectUri: AUTH0_CONFIG.redirectUri,
|
|
462
|
+
scope: AUTH0_CONFIG.scope,
|
|
463
|
+
audience: AUTH0_CONFIG.audience || 'not set'
|
|
464
|
+
});
|
|
409
465
|
this.auth0Client = await oa({
|
|
410
466
|
domain: AUTH0_CONFIG.domain,
|
|
411
467
|
clientId: AUTH0_CONFIG.clientId,
|
|
@@ -418,9 +474,13 @@ let AuthService = class AuthService {
|
|
|
418
474
|
useRefreshTokens: true, // Enable refresh tokens for better security
|
|
419
475
|
});
|
|
420
476
|
console.log("[AuthService] Auth0 client initialized successfully");
|
|
477
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
478
|
+
console.log('[AuthService] 🔍 DEBUG: Auth0 client created successfully');
|
|
421
479
|
}
|
|
422
480
|
catch (error) {
|
|
423
481
|
console.error("[AuthService] Failed to initialize Auth0 client:", error);
|
|
482
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
483
|
+
console.error('[AuthService] 🔍 DEBUG: initializeAuth0 failed with error:', error);
|
|
424
484
|
throw error;
|
|
425
485
|
}
|
|
426
486
|
}
|
|
@@ -442,21 +502,24 @@ let AuthService = class AuthService {
|
|
|
442
502
|
* @param options - Optional login options including invitation and organization parameters
|
|
443
503
|
*/
|
|
444
504
|
async login(user, options) {
|
|
505
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
506
|
+
console.log('[AuthService] 🔍 DEBUG: login() called', { user, options });
|
|
445
507
|
if (user) {
|
|
446
508
|
console.log(`[AuthService] Logging in: ${user}`);
|
|
447
509
|
}
|
|
448
510
|
try {
|
|
449
511
|
// Ensure Auth0 client is initialized
|
|
450
512
|
await this.ensureInitialized();
|
|
513
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
514
|
+
console.log('[AuthService] 🔍 DEBUG: Auth0 client ensured initialized for login');
|
|
451
515
|
// Capture current URL search parameters to preserve through auth flow
|
|
452
|
-
// Only capture if we're not already on the callback page
|
|
453
|
-
const currentPath = window.location.pathname;
|
|
454
|
-
const isCallbackPage = currentPath.includes('auth-callback');
|
|
455
516
|
let appState = undefined;
|
|
456
|
-
if (
|
|
517
|
+
if (window.location.search) {
|
|
457
518
|
const currentSearchParams = window.location.search;
|
|
458
519
|
appState = { returnTo: currentSearchParams };
|
|
459
520
|
console.log('[AuthService] Preserving URL parameters through auth flow:', currentSearchParams);
|
|
521
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
522
|
+
console.log('[AuthService] 🔍 DEBUG: Captured URL search params for preservation:', currentSearchParams);
|
|
460
523
|
}
|
|
461
524
|
// Build authorization parameters
|
|
462
525
|
const authorizationParams = {
|
|
@@ -474,14 +537,30 @@ let AuthService = class AuthService {
|
|
|
474
537
|
authorizationParams.organization = options.organization;
|
|
475
538
|
console.log('[AuthService] Including organization parameter:', options.organization);
|
|
476
539
|
}
|
|
540
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
541
|
+
console.log('[AuthService] 🔍 DEBUG: Authorization params prepared:', {
|
|
542
|
+
redirect_uri: authorizationParams.redirect_uri,
|
|
543
|
+
scope: authorizationParams.scope,
|
|
544
|
+
audience: authorizationParams.audience || 'not set',
|
|
545
|
+
connection: authorizationParams.connection || 'not set',
|
|
546
|
+
invitation: authorizationParams.invitation || 'not set',
|
|
547
|
+
organization: authorizationParams.organization || 'not set',
|
|
548
|
+
hasAppState: !!appState
|
|
549
|
+
});
|
|
477
550
|
console.log('[AuthService] Starting Auth0 login redirect...');
|
|
551
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
552
|
+
console.log('[AuthService] 🔍 DEBUG: About to call loginWithRedirect');
|
|
478
553
|
await this.auth0Client.loginWithRedirect({
|
|
479
554
|
authorizationParams,
|
|
480
555
|
...(appState && { appState })
|
|
481
556
|
});
|
|
557
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
558
|
+
console.log('[AuthService] 🔍 DEBUG: loginWithRedirect completed (this may not be visible due to redirect)');
|
|
482
559
|
}
|
|
483
560
|
catch (error) {
|
|
484
561
|
console.error("[AuthService] Login failed:", error);
|
|
562
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
563
|
+
console.error('[AuthService] 🔍 DEBUG: login() failed with error:', error);
|
|
485
564
|
// Emit login failure event
|
|
486
565
|
this.emitAuthEvent('login_failure', { error: error instanceof Error ? error.message : String(error) });
|
|
487
566
|
throw error; // Re-throw to allow caller to handle
|
|
@@ -499,11 +578,19 @@ let AuthService = class AuthService {
|
|
|
499
578
|
async handleCallback() {
|
|
500
579
|
try {
|
|
501
580
|
console.log("[AuthService] Processing Auth0 callback...");
|
|
581
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
582
|
+
console.log('[AuthService] 🔍 DEBUG: handleCallback() called');
|
|
583
|
+
console.log('[AuthService] 🔍 DEBUG: Current URL:', window.location.href);
|
|
584
|
+
console.log('[AuthService] 🔍 DEBUG: URL params:', window.location.search);
|
|
502
585
|
// Ensure Auth0 client is initialized
|
|
503
586
|
await this.ensureInitialized();
|
|
587
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
588
|
+
console.log('[AuthService] 🔍 DEBUG: Auth0 client ensured initialized for callback');
|
|
504
589
|
// Process the callback
|
|
505
590
|
const result = await this.auth0Client.handleRedirectCallback();
|
|
506
591
|
console.log("[AuthService] Callback processed successfully");
|
|
592
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
593
|
+
console.log('[AuthService] 🔍 DEBUG: handleRedirectCallback result:', result);
|
|
507
594
|
// Log preserved appState if present
|
|
508
595
|
if (result.appState) {
|
|
509
596
|
console.log('[AuthService] Restored appState from auth flow:', JSON.stringify(result.appState));
|
|
@@ -512,23 +599,35 @@ let AuthService = class AuthService {
|
|
|
512
599
|
console.log('[AuthService] No appState restored (user may not have started from invitation link)');
|
|
513
600
|
}
|
|
514
601
|
// Get user info
|
|
602
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
603
|
+
console.log('[AuthService] 🔍 DEBUG: Fetching user info from Auth0');
|
|
515
604
|
const user = await this.auth0Client.getUser();
|
|
516
605
|
if (user) {
|
|
606
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
607
|
+
console.log('[AuthService] 🔍 DEBUG: User info retrieved successfully');
|
|
517
608
|
this.logUserClaims(user);
|
|
518
609
|
this.setUserInfo(user);
|
|
519
610
|
}
|
|
520
611
|
else {
|
|
521
612
|
console.warn('[AuthService] No user info returned from Auth0');
|
|
613
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
614
|
+
console.warn('[AuthService] 🔍 DEBUG: getUser() returned null or undefined');
|
|
522
615
|
// Emit login failure event
|
|
523
616
|
this.emitAuthEvent('login_failure', { error: 'No user info returned from Auth0' });
|
|
524
617
|
return { success: false };
|
|
525
618
|
}
|
|
526
619
|
// Get and store access token
|
|
620
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
621
|
+
console.log('[AuthService] 🔍 DEBUG: Fetching access token');
|
|
527
622
|
const token = await this.auth0Client.getTokenSilently();
|
|
623
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
624
|
+
console.log('[AuthService] 🔍 DEBUG: Access token retrieved, length:', token?.length || 0);
|
|
528
625
|
this.setToken(token);
|
|
529
626
|
// Decode and print the token to console
|
|
530
627
|
this.decodeAndLogToken(token);
|
|
531
628
|
console.log("[AuthService] Authentication successful");
|
|
629
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
630
|
+
console.log('[AuthService] 🔍 DEBUG: handleCallback() completed successfully');
|
|
532
631
|
// Emit login success event
|
|
533
632
|
this.emitAuthEvent('login_success', { user, appState: result.appState });
|
|
534
633
|
return { success: true, appState: result.appState };
|
|
@@ -536,6 +635,10 @@ let AuthService = class AuthService {
|
|
|
536
635
|
catch (error) {
|
|
537
636
|
console.error("[AuthService] Error processing callback:", error);
|
|
538
637
|
console.error("[AuthService] Error details:", JSON.stringify(error, null, 2));
|
|
638
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
639
|
+
console.error('[AuthService] 🔍 DEBUG: handleCallback() failed with error:', error);
|
|
640
|
+
console.error('[AuthService] 🔍 DEBUG: Error type:', typeof error);
|
|
641
|
+
console.error('[AuthService] 🔍 DEBUG: Error stack:', error?.stack);
|
|
539
642
|
// Emit login failure event
|
|
540
643
|
this.emitAuthEvent('login_failure', { error: error instanceof Error ? error.message : String(error) });
|
|
541
644
|
return { success: false };
|
|
@@ -642,23 +745,33 @@ let AuthService = class AuthService {
|
|
|
642
745
|
* Redirects to Auth0 logout endpoint and clears local state
|
|
643
746
|
*/
|
|
644
747
|
async logout() {
|
|
748
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
749
|
+
console.log('[AuthService] 🔍 DEBUG: logout() called');
|
|
645
750
|
// Clear local storage
|
|
646
751
|
removeStorageItem(STORAGE_KEYS.ACCESS_TOKEN, STORAGE_CONFIG.TOKEN_STORAGE);
|
|
647
752
|
removeStorageItem(STORAGE_KEYS.USER_INFO, STORAGE_CONFIG.USER_INFO_STORAGE);
|
|
753
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
754
|
+
console.log('[AuthService] 🔍 DEBUG: Storage cleared (token and user info removed)');
|
|
648
755
|
this.userSubject.next(null);
|
|
649
756
|
this.emitAuthEvent('logout', null);
|
|
650
757
|
console.log('[AuthService] User logged out, clearing Auth0 session');
|
|
651
758
|
// Logout from Auth0
|
|
652
759
|
try {
|
|
653
760
|
await this.ensureInitialized();
|
|
761
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
762
|
+
console.log('[AuthService] 🔍 DEBUG: About to call Auth0 logout, returnTo:', AUTH0_CONFIG.logoutUri);
|
|
654
763
|
await this.auth0Client.logout({
|
|
655
764
|
logoutParams: {
|
|
656
765
|
returnTo: AUTH0_CONFIG.logoutUri
|
|
657
766
|
}
|
|
658
767
|
});
|
|
768
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
769
|
+
console.log('[AuthService] 🔍 DEBUG: Auth0 logout completed (this may not be visible due to redirect)');
|
|
659
770
|
}
|
|
660
771
|
catch (error) {
|
|
661
772
|
console.error('[AuthService] Error during Auth0 logout:', error);
|
|
773
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
774
|
+
console.error('[AuthService] 🔍 DEBUG: logout() failed with error:', error);
|
|
662
775
|
}
|
|
663
776
|
}
|
|
664
777
|
/**
|
|
@@ -666,20 +779,30 @@ let AuthService = class AuthService {
|
|
|
666
779
|
* @returns string | null - Access token or null if not authenticated
|
|
667
780
|
*/
|
|
668
781
|
async getToken() {
|
|
782
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
783
|
+
console.log('[AuthService] 🔍 DEBUG: getToken() called');
|
|
669
784
|
// Try to get from storage first
|
|
670
785
|
const storedToken = getStorageItem(STORAGE_KEYS.ACCESS_TOKEN, STORAGE_CONFIG.TOKEN_STORAGE);
|
|
671
786
|
if (storedToken) {
|
|
787
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
788
|
+
console.log('[AuthService] 🔍 DEBUG: Token found in storage, length:', storedToken.length);
|
|
672
789
|
return storedToken;
|
|
673
790
|
}
|
|
791
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
792
|
+
console.log('[AuthService] 🔍 DEBUG: Token not in storage, fetching from Auth0');
|
|
674
793
|
// If not in storage, try to get from Auth0 client
|
|
675
794
|
try {
|
|
676
795
|
await this.ensureInitialized();
|
|
677
796
|
const token = await this.auth0Client.getTokenSilently();
|
|
797
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
798
|
+
console.log('[AuthService] 🔍 DEBUG: Token retrieved from Auth0, length:', token?.length || 0);
|
|
678
799
|
this.setToken(token);
|
|
679
800
|
return token;
|
|
680
801
|
}
|
|
681
802
|
catch (error) {
|
|
682
803
|
console.error('[AuthService] Error getting token from Auth0:', error);
|
|
804
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
805
|
+
console.error('[AuthService] 🔍 DEBUG: getToken() failed:', error);
|
|
683
806
|
return null;
|
|
684
807
|
}
|
|
685
808
|
}
|
|
@@ -696,22 +819,34 @@ let AuthService = class AuthService {
|
|
|
696
819
|
* @param token - Access token to store
|
|
697
820
|
*/
|
|
698
821
|
setToken(token) {
|
|
822
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
823
|
+
console.log('[AuthService] 🔍 DEBUG: setToken() called, storing token in storage');
|
|
699
824
|
setStorageItem(STORAGE_KEYS.ACCESS_TOKEN, token, STORAGE_CONFIG.TOKEN_STORAGE);
|
|
700
825
|
this.emitAuthEvent('token_updated', { token });
|
|
826
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
827
|
+
console.log('[AuthService] 🔍 DEBUG: Token stored and token_updated event emitted');
|
|
701
828
|
}
|
|
702
829
|
/**
|
|
703
830
|
* Check if user is authenticated
|
|
704
831
|
* @returns boolean - True if user has valid token
|
|
705
832
|
*/
|
|
706
833
|
async isAuthenticated() {
|
|
834
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
835
|
+
console.log('[AuthService] 🔍 DEBUG: isAuthenticated() called');
|
|
707
836
|
try {
|
|
708
837
|
await this.ensureInitialized();
|
|
709
|
-
|
|
838
|
+
const result = await this.auth0Client.isAuthenticated();
|
|
839
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
840
|
+
console.log('[AuthService] 🔍 DEBUG: isAuthenticated() result from Auth0:', result);
|
|
841
|
+
return result;
|
|
710
842
|
}
|
|
711
843
|
catch (error) {
|
|
712
844
|
console.error('[AuthService] Error checking authentication status:', error);
|
|
713
845
|
// Fallback to checking storage
|
|
714
|
-
|
|
846
|
+
const hasToken = !!getStorageItem(STORAGE_KEYS.ACCESS_TOKEN, STORAGE_CONFIG.TOKEN_STORAGE);
|
|
847
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
848
|
+
console.error('[AuthService] 🔍 DEBUG: isAuthenticated() failed, falling back to storage check:', hasToken);
|
|
849
|
+
return hasToken;
|
|
715
850
|
}
|
|
716
851
|
}
|
|
717
852
|
/**
|
|
@@ -791,6 +926,8 @@ let AuthService = class AuthService {
|
|
|
791
926
|
* @param userInfo - User information to store
|
|
792
927
|
*/
|
|
793
928
|
setUserInfo(userInfo) {
|
|
929
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
930
|
+
console.log('[AuthService] 🔍 DEBUG: setUserInfo() called');
|
|
794
931
|
setStorageItem(STORAGE_KEYS.USER_INFO, JSON.stringify(userInfo), STORAGE_CONFIG.USER_INFO_STORAGE);
|
|
795
932
|
this.userSubject.next(userInfo);
|
|
796
933
|
// Log stored user info with all claims
|
|
@@ -809,6 +946,8 @@ let AuthService = class AuthService {
|
|
|
809
946
|
console.log(` • ${claim}:`, userInfo[claim]);
|
|
810
947
|
});
|
|
811
948
|
}
|
|
949
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
950
|
+
console.log('[AuthService] 🔍 DEBUG: User info stored in storage and userSubject updated');
|
|
812
951
|
this.emitAuthEvent('user_info_updated', userInfo);
|
|
813
952
|
}
|
|
814
953
|
/**
|
|
@@ -823,6 +962,8 @@ let AuthService = class AuthService {
|
|
|
823
962
|
payload,
|
|
824
963
|
timestamp: new Date().toISOString()
|
|
825
964
|
};
|
|
965
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
966
|
+
console.log('[AuthService] 🔍 DEBUG: emitAuthEvent() called, event type:', event.type);
|
|
826
967
|
this.eventBus.sendEvent(JSON.stringify(event));
|
|
827
968
|
console.log('[AuthService] Auth event emitted:', event.type);
|
|
828
969
|
}
|