@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/angular/index.d.ts
CHANGED
|
@@ -283,6 +283,10 @@ declare class AuthService {
|
|
|
283
283
|
/**
|
|
284
284
|
* Auth0 client configuration
|
|
285
285
|
* Override these values in your consuming application by setting them before importing AuthService
|
|
286
|
+
*
|
|
287
|
+
* Note: redirectUri defaults to window.location.origin (base URL without path).
|
|
288
|
+
* Auth0 will redirect back to this URL after authentication.
|
|
289
|
+
* You can override this to a specific callback URL (e.g., '/auth-callback') using configureAuth0().
|
|
286
290
|
*/
|
|
287
291
|
declare const AUTH0_CONFIG: {
|
|
288
292
|
domain: string;
|
|
@@ -333,17 +337,29 @@ declare function setStorageItem(key: string, value: string, storageType?: 'local
|
|
|
333
337
|
*/
|
|
334
338
|
declare function removeStorageItem(key: string, storageType?: 'localStorage' | 'sessionStorage'): void;
|
|
335
339
|
/**
|
|
336
|
-
* Configure Auth0 settings
|
|
337
|
-
* Call this function in your consuming application
|
|
340
|
+
* Configure Auth0 settings (OPTIONAL)
|
|
341
|
+
* Call this function in your consuming application to override default Auth0 configuration.
|
|
342
|
+
* Only the values you provide will be overridden; all other defaults remain unchanged.
|
|
343
|
+
*
|
|
344
|
+
* Note: This function is optional. If not called, default values will be used.
|
|
345
|
+
*
|
|
346
|
+
* @param config - Partial Auth0 configuration object with values to override
|
|
338
347
|
*
|
|
339
348
|
* @example
|
|
340
349
|
* ```typescript
|
|
341
350
|
* import { configureAuth0 } from '@opensourcekd/ng-common-libs';
|
|
342
351
|
*
|
|
352
|
+
* // Only override specific values - others keep their defaults
|
|
343
353
|
* configureAuth0({
|
|
344
354
|
* domain: 'your-domain.auth0.com',
|
|
345
355
|
* clientId: 'your-client-id',
|
|
346
356
|
* audience: 'https://your-api.com'
|
|
357
|
+
* // redirectUri, logoutUri, scope, etc. will use defaults
|
|
358
|
+
* });
|
|
359
|
+
*
|
|
360
|
+
* // Or override just redirectUri to use a specific callback page
|
|
361
|
+
* configureAuth0({
|
|
362
|
+
* redirectUri: window.location.origin + '/auth-callback'
|
|
347
363
|
* });
|
|
348
364
|
* ```
|
|
349
365
|
*/
|
package/dist/angular/index.mjs
CHANGED
|
@@ -203,11 +203,15 @@ function jwtDecode(token, options) {
|
|
|
203
203
|
/**
|
|
204
204
|
* Auth0 client configuration
|
|
205
205
|
* Override these values in your consuming application by setting them before importing AuthService
|
|
206
|
+
*
|
|
207
|
+
* Note: redirectUri defaults to window.location.origin (base URL without path).
|
|
208
|
+
* Auth0 will redirect back to this URL after authentication.
|
|
209
|
+
* You can override this to a specific callback URL (e.g., '/auth-callback') using configureAuth0().
|
|
206
210
|
*/
|
|
207
211
|
const AUTH0_CONFIG = {
|
|
208
212
|
domain: '', // Set in consuming app: process.env['NX_AUTH0_DOMAIN'] || 'your-domain.auth0.com'
|
|
209
213
|
clientId: '', // Set in consuming app: process.env['NX_AUTH0_CLIENT_ID'] || 'your-client-id'
|
|
210
|
-
redirectUri: typeof window !== 'undefined' ? window.location.origin
|
|
214
|
+
redirectUri: typeof window !== 'undefined' ? window.location.origin : '',
|
|
211
215
|
logoutUri: typeof window !== 'undefined' ? window.location.origin : '',
|
|
212
216
|
audience: '', // Optional: Set in consuming app if using API authorization
|
|
213
217
|
scope: 'openid profile email', // Default scopes
|
|
@@ -268,22 +272,55 @@ function removeStorageItem(key, storageType = 'sessionStorage') {
|
|
|
268
272
|
storage.removeItem(key);
|
|
269
273
|
}
|
|
270
274
|
/**
|
|
271
|
-
* Configure Auth0 settings
|
|
272
|
-
* Call this function in your consuming application
|
|
275
|
+
* Configure Auth0 settings (OPTIONAL)
|
|
276
|
+
* Call this function in your consuming application to override default Auth0 configuration.
|
|
277
|
+
* Only the values you provide will be overridden; all other defaults remain unchanged.
|
|
278
|
+
*
|
|
279
|
+
* Note: This function is optional. If not called, default values will be used.
|
|
280
|
+
*
|
|
281
|
+
* @param config - Partial Auth0 configuration object with values to override
|
|
273
282
|
*
|
|
274
283
|
* @example
|
|
275
284
|
* ```typescript
|
|
276
285
|
* import { configureAuth0 } from '@opensourcekd/ng-common-libs';
|
|
277
286
|
*
|
|
287
|
+
* // Only override specific values - others keep their defaults
|
|
278
288
|
* configureAuth0({
|
|
279
289
|
* domain: 'your-domain.auth0.com',
|
|
280
290
|
* clientId: 'your-client-id',
|
|
281
291
|
* audience: 'https://your-api.com'
|
|
292
|
+
* // redirectUri, logoutUri, scope, etc. will use defaults
|
|
293
|
+
* });
|
|
294
|
+
*
|
|
295
|
+
* // Or override just redirectUri to use a specific callback page
|
|
296
|
+
* configureAuth0({
|
|
297
|
+
* redirectUri: window.location.origin + '/auth-callback'
|
|
282
298
|
* });
|
|
283
299
|
* ```
|
|
284
300
|
*/
|
|
285
301
|
function configureAuth0(config) {
|
|
302
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
303
|
+
console.log('[AuthConfig] 🔍 DEBUG: configureAuth0() called with config:', {
|
|
304
|
+
domain: config.domain || 'not provided',
|
|
305
|
+
clientId: config.clientId ? '[REDACTED]' : 'not provided',
|
|
306
|
+
redirectUri: config.redirectUri || 'not provided',
|
|
307
|
+
logoutUri: config.logoutUri || 'not provided',
|
|
308
|
+
audience: config.audience || 'not provided',
|
|
309
|
+
scope: config.scope || 'not provided',
|
|
310
|
+
connection: config.connection || 'not provided'
|
|
311
|
+
});
|
|
312
|
+
// Only override provided values, keeping defaults for others
|
|
286
313
|
Object.assign(AUTH0_CONFIG, config);
|
|
314
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
315
|
+
console.log('[AuthConfig] 🔍 DEBUG: AUTH0_CONFIG after merge:', {
|
|
316
|
+
domain: AUTH0_CONFIG.domain,
|
|
317
|
+
clientId: AUTH0_CONFIG.clientId ? '[REDACTED]' : undefined,
|
|
318
|
+
redirectUri: AUTH0_CONFIG.redirectUri,
|
|
319
|
+
logoutUri: AUTH0_CONFIG.logoutUri,
|
|
320
|
+
audience: AUTH0_CONFIG.audience || 'not set',
|
|
321
|
+
scope: AUTH0_CONFIG.scope,
|
|
322
|
+
connection: AUTH0_CONFIG.connection || 'not set'
|
|
323
|
+
});
|
|
287
324
|
}
|
|
288
325
|
|
|
289
326
|
/**
|
|
@@ -312,6 +349,8 @@ let AuthService = class AuthService {
|
|
|
312
349
|
constructor(eventBus) {
|
|
313
350
|
this.eventBus = eventBus;
|
|
314
351
|
console.log("[AuthService] Initializing Auth0 authentication service");
|
|
352
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
353
|
+
console.log('[AuthService] 🔍 DEBUG: Constructor called, starting initialization');
|
|
315
354
|
this.initializationPromise = this.initializeAuth0();
|
|
316
355
|
}
|
|
317
356
|
/**
|
|
@@ -320,13 +359,30 @@ let AuthService = class AuthService {
|
|
|
320
359
|
async initializeAuth0() {
|
|
321
360
|
try {
|
|
322
361
|
console.log("[AuthService] Starting Auth0 client initialization...");
|
|
362
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
363
|
+
console.log('[AuthService] 🔍 DEBUG: initializeAuth0 called');
|
|
323
364
|
// Defensive check for AUTH0_CONFIG
|
|
324
365
|
if (!AUTH0_CONFIG || typeof AUTH0_CONFIG !== 'object') {
|
|
366
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
367
|
+
console.error('[AuthService] 🔍 DEBUG: AUTH0_CONFIG validation failed - invalid or undefined');
|
|
325
368
|
throw new Error('[AuthService] AUTH0_CONFIG is not defined or invalid');
|
|
326
369
|
}
|
|
327
370
|
if (!AUTH0_CONFIG.domain || !AUTH0_CONFIG.clientId) {
|
|
371
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
372
|
+
console.error('[AuthService] 🔍 DEBUG: AUTH0_CONFIG validation failed - missing domain or clientId', {
|
|
373
|
+
domain: AUTH0_CONFIG.domain,
|
|
374
|
+
clientId: AUTH0_CONFIG.clientId ? '[REDACTED]' : undefined
|
|
375
|
+
});
|
|
328
376
|
throw new Error('[AuthService] AUTH0_CONFIG is missing required fields (domain, clientId)');
|
|
329
377
|
}
|
|
378
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
379
|
+
console.log('[AuthService] 🔍 DEBUG: Creating Auth0 client with config:', {
|
|
380
|
+
domain: AUTH0_CONFIG.domain,
|
|
381
|
+
clientId: AUTH0_CONFIG.clientId ? '[REDACTED]' : undefined,
|
|
382
|
+
redirectUri: AUTH0_CONFIG.redirectUri,
|
|
383
|
+
scope: AUTH0_CONFIG.scope,
|
|
384
|
+
audience: AUTH0_CONFIG.audience || 'not set'
|
|
385
|
+
});
|
|
330
386
|
this.auth0Client = await oa({
|
|
331
387
|
domain: AUTH0_CONFIG.domain,
|
|
332
388
|
clientId: AUTH0_CONFIG.clientId,
|
|
@@ -339,9 +395,13 @@ let AuthService = class AuthService {
|
|
|
339
395
|
useRefreshTokens: true, // Enable refresh tokens for better security
|
|
340
396
|
});
|
|
341
397
|
console.log("[AuthService] Auth0 client initialized successfully");
|
|
398
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
399
|
+
console.log('[AuthService] 🔍 DEBUG: Auth0 client created successfully');
|
|
342
400
|
}
|
|
343
401
|
catch (error) {
|
|
344
402
|
console.error("[AuthService] Failed to initialize Auth0 client:", error);
|
|
403
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
404
|
+
console.error('[AuthService] 🔍 DEBUG: initializeAuth0 failed with error:', error);
|
|
345
405
|
throw error;
|
|
346
406
|
}
|
|
347
407
|
}
|
|
@@ -363,21 +423,24 @@ let AuthService = class AuthService {
|
|
|
363
423
|
* @param options - Optional login options including invitation and organization parameters
|
|
364
424
|
*/
|
|
365
425
|
async login(user, options) {
|
|
426
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
427
|
+
console.log('[AuthService] 🔍 DEBUG: login() called', { user, options });
|
|
366
428
|
if (user) {
|
|
367
429
|
console.log(`[AuthService] Logging in: ${user}`);
|
|
368
430
|
}
|
|
369
431
|
try {
|
|
370
432
|
// Ensure Auth0 client is initialized
|
|
371
433
|
await this.ensureInitialized();
|
|
434
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
435
|
+
console.log('[AuthService] 🔍 DEBUG: Auth0 client ensured initialized for login');
|
|
372
436
|
// Capture current URL search parameters to preserve through auth flow
|
|
373
|
-
// Only capture if we're not already on the callback page
|
|
374
|
-
const currentPath = window.location.pathname;
|
|
375
|
-
const isCallbackPage = currentPath.includes('auth-callback');
|
|
376
437
|
let appState = undefined;
|
|
377
|
-
if (
|
|
438
|
+
if (window.location.search) {
|
|
378
439
|
const currentSearchParams = window.location.search;
|
|
379
440
|
appState = { returnTo: currentSearchParams };
|
|
380
441
|
console.log('[AuthService] Preserving URL parameters through auth flow:', currentSearchParams);
|
|
442
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
443
|
+
console.log('[AuthService] 🔍 DEBUG: Captured URL search params for preservation:', currentSearchParams);
|
|
381
444
|
}
|
|
382
445
|
// Build authorization parameters
|
|
383
446
|
const authorizationParams = {
|
|
@@ -395,14 +458,30 @@ let AuthService = class AuthService {
|
|
|
395
458
|
authorizationParams.organization = options.organization;
|
|
396
459
|
console.log('[AuthService] Including organization parameter:', options.organization);
|
|
397
460
|
}
|
|
461
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
462
|
+
console.log('[AuthService] 🔍 DEBUG: Authorization params prepared:', {
|
|
463
|
+
redirect_uri: authorizationParams.redirect_uri,
|
|
464
|
+
scope: authorizationParams.scope,
|
|
465
|
+
audience: authorizationParams.audience || 'not set',
|
|
466
|
+
connection: authorizationParams.connection || 'not set',
|
|
467
|
+
invitation: authorizationParams.invitation || 'not set',
|
|
468
|
+
organization: authorizationParams.organization || 'not set',
|
|
469
|
+
hasAppState: !!appState
|
|
470
|
+
});
|
|
398
471
|
console.log('[AuthService] Starting Auth0 login redirect...');
|
|
472
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
473
|
+
console.log('[AuthService] 🔍 DEBUG: About to call loginWithRedirect');
|
|
399
474
|
await this.auth0Client.loginWithRedirect({
|
|
400
475
|
authorizationParams,
|
|
401
476
|
...(appState && { appState })
|
|
402
477
|
});
|
|
478
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
479
|
+
console.log('[AuthService] 🔍 DEBUG: loginWithRedirect completed (this may not be visible due to redirect)');
|
|
403
480
|
}
|
|
404
481
|
catch (error) {
|
|
405
482
|
console.error("[AuthService] Login failed:", error);
|
|
483
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
484
|
+
console.error('[AuthService] 🔍 DEBUG: login() failed with error:', error);
|
|
406
485
|
// Emit login failure event
|
|
407
486
|
this.emitAuthEvent('login_failure', { error: error instanceof Error ? error.message : String(error) });
|
|
408
487
|
throw error; // Re-throw to allow caller to handle
|
|
@@ -420,11 +499,19 @@ let AuthService = class AuthService {
|
|
|
420
499
|
async handleCallback() {
|
|
421
500
|
try {
|
|
422
501
|
console.log("[AuthService] Processing Auth0 callback...");
|
|
502
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
503
|
+
console.log('[AuthService] 🔍 DEBUG: handleCallback() called');
|
|
504
|
+
console.log('[AuthService] 🔍 DEBUG: Current URL:', window.location.href);
|
|
505
|
+
console.log('[AuthService] 🔍 DEBUG: URL params:', window.location.search);
|
|
423
506
|
// Ensure Auth0 client is initialized
|
|
424
507
|
await this.ensureInitialized();
|
|
508
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
509
|
+
console.log('[AuthService] 🔍 DEBUG: Auth0 client ensured initialized for callback');
|
|
425
510
|
// Process the callback
|
|
426
511
|
const result = await this.auth0Client.handleRedirectCallback();
|
|
427
512
|
console.log("[AuthService] Callback processed successfully");
|
|
513
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
514
|
+
console.log('[AuthService] 🔍 DEBUG: handleRedirectCallback result:', result);
|
|
428
515
|
// Log preserved appState if present
|
|
429
516
|
if (result.appState) {
|
|
430
517
|
console.log('[AuthService] Restored appState from auth flow:', JSON.stringify(result.appState));
|
|
@@ -433,23 +520,35 @@ let AuthService = class AuthService {
|
|
|
433
520
|
console.log('[AuthService] No appState restored (user may not have started from invitation link)');
|
|
434
521
|
}
|
|
435
522
|
// Get user info
|
|
523
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
524
|
+
console.log('[AuthService] 🔍 DEBUG: Fetching user info from Auth0');
|
|
436
525
|
const user = await this.auth0Client.getUser();
|
|
437
526
|
if (user) {
|
|
527
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
528
|
+
console.log('[AuthService] 🔍 DEBUG: User info retrieved successfully');
|
|
438
529
|
this.logUserClaims(user);
|
|
439
530
|
this.setUserInfo(user);
|
|
440
531
|
}
|
|
441
532
|
else {
|
|
442
533
|
console.warn('[AuthService] No user info returned from Auth0');
|
|
534
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
535
|
+
console.warn('[AuthService] 🔍 DEBUG: getUser() returned null or undefined');
|
|
443
536
|
// Emit login failure event
|
|
444
537
|
this.emitAuthEvent('login_failure', { error: 'No user info returned from Auth0' });
|
|
445
538
|
return { success: false };
|
|
446
539
|
}
|
|
447
540
|
// Get and store access token
|
|
541
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
542
|
+
console.log('[AuthService] 🔍 DEBUG: Fetching access token');
|
|
448
543
|
const token = await this.auth0Client.getTokenSilently();
|
|
544
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
545
|
+
console.log('[AuthService] 🔍 DEBUG: Access token retrieved, length:', token?.length || 0);
|
|
449
546
|
this.setToken(token);
|
|
450
547
|
// Decode and print the token to console
|
|
451
548
|
this.decodeAndLogToken(token);
|
|
452
549
|
console.log("[AuthService] Authentication successful");
|
|
550
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
551
|
+
console.log('[AuthService] 🔍 DEBUG: handleCallback() completed successfully');
|
|
453
552
|
// Emit login success event
|
|
454
553
|
this.emitAuthEvent('login_success', { user, appState: result.appState });
|
|
455
554
|
return { success: true, appState: result.appState };
|
|
@@ -457,6 +556,10 @@ let AuthService = class AuthService {
|
|
|
457
556
|
catch (error) {
|
|
458
557
|
console.error("[AuthService] Error processing callback:", error);
|
|
459
558
|
console.error("[AuthService] Error details:", JSON.stringify(error, null, 2));
|
|
559
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
560
|
+
console.error('[AuthService] 🔍 DEBUG: handleCallback() failed with error:', error);
|
|
561
|
+
console.error('[AuthService] 🔍 DEBUG: Error type:', typeof error);
|
|
562
|
+
console.error('[AuthService] 🔍 DEBUG: Error stack:', error?.stack);
|
|
460
563
|
// Emit login failure event
|
|
461
564
|
this.emitAuthEvent('login_failure', { error: error instanceof Error ? error.message : String(error) });
|
|
462
565
|
return { success: false };
|
|
@@ -563,23 +666,33 @@ let AuthService = class AuthService {
|
|
|
563
666
|
* Redirects to Auth0 logout endpoint and clears local state
|
|
564
667
|
*/
|
|
565
668
|
async logout() {
|
|
669
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
670
|
+
console.log('[AuthService] 🔍 DEBUG: logout() called');
|
|
566
671
|
// Clear local storage
|
|
567
672
|
removeStorageItem(STORAGE_KEYS.ACCESS_TOKEN, STORAGE_CONFIG.TOKEN_STORAGE);
|
|
568
673
|
removeStorageItem(STORAGE_KEYS.USER_INFO, STORAGE_CONFIG.USER_INFO_STORAGE);
|
|
674
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
675
|
+
console.log('[AuthService] 🔍 DEBUG: Storage cleared (token and user info removed)');
|
|
569
676
|
this.userSubject.next(null);
|
|
570
677
|
this.emitAuthEvent('logout', null);
|
|
571
678
|
console.log('[AuthService] User logged out, clearing Auth0 session');
|
|
572
679
|
// Logout from Auth0
|
|
573
680
|
try {
|
|
574
681
|
await this.ensureInitialized();
|
|
682
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
683
|
+
console.log('[AuthService] 🔍 DEBUG: About to call Auth0 logout, returnTo:', AUTH0_CONFIG.logoutUri);
|
|
575
684
|
await this.auth0Client.logout({
|
|
576
685
|
logoutParams: {
|
|
577
686
|
returnTo: AUTH0_CONFIG.logoutUri
|
|
578
687
|
}
|
|
579
688
|
});
|
|
689
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
690
|
+
console.log('[AuthService] 🔍 DEBUG: Auth0 logout completed (this may not be visible due to redirect)');
|
|
580
691
|
}
|
|
581
692
|
catch (error) {
|
|
582
693
|
console.error('[AuthService] Error during Auth0 logout:', error);
|
|
694
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
695
|
+
console.error('[AuthService] 🔍 DEBUG: logout() failed with error:', error);
|
|
583
696
|
}
|
|
584
697
|
}
|
|
585
698
|
/**
|
|
@@ -587,20 +700,30 @@ let AuthService = class AuthService {
|
|
|
587
700
|
* @returns string | null - Access token or null if not authenticated
|
|
588
701
|
*/
|
|
589
702
|
async getToken() {
|
|
703
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
704
|
+
console.log('[AuthService] 🔍 DEBUG: getToken() called');
|
|
590
705
|
// Try to get from storage first
|
|
591
706
|
const storedToken = getStorageItem(STORAGE_KEYS.ACCESS_TOKEN, STORAGE_CONFIG.TOKEN_STORAGE);
|
|
592
707
|
if (storedToken) {
|
|
708
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
709
|
+
console.log('[AuthService] 🔍 DEBUG: Token found in storage, length:', storedToken.length);
|
|
593
710
|
return storedToken;
|
|
594
711
|
}
|
|
712
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
713
|
+
console.log('[AuthService] 🔍 DEBUG: Token not in storage, fetching from Auth0');
|
|
595
714
|
// If not in storage, try to get from Auth0 client
|
|
596
715
|
try {
|
|
597
716
|
await this.ensureInitialized();
|
|
598
717
|
const token = await this.auth0Client.getTokenSilently();
|
|
718
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
719
|
+
console.log('[AuthService] 🔍 DEBUG: Token retrieved from Auth0, length:', token?.length || 0);
|
|
599
720
|
this.setToken(token);
|
|
600
721
|
return token;
|
|
601
722
|
}
|
|
602
723
|
catch (error) {
|
|
603
724
|
console.error('[AuthService] Error getting token from Auth0:', error);
|
|
725
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
726
|
+
console.error('[AuthService] 🔍 DEBUG: getToken() failed:', error);
|
|
604
727
|
return null;
|
|
605
728
|
}
|
|
606
729
|
}
|
|
@@ -617,22 +740,34 @@ let AuthService = class AuthService {
|
|
|
617
740
|
* @param token - Access token to store
|
|
618
741
|
*/
|
|
619
742
|
setToken(token) {
|
|
743
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
744
|
+
console.log('[AuthService] 🔍 DEBUG: setToken() called, storing token in storage');
|
|
620
745
|
setStorageItem(STORAGE_KEYS.ACCESS_TOKEN, token, STORAGE_CONFIG.TOKEN_STORAGE);
|
|
621
746
|
this.emitAuthEvent('token_updated', { token });
|
|
747
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
748
|
+
console.log('[AuthService] 🔍 DEBUG: Token stored and token_updated event emitted');
|
|
622
749
|
}
|
|
623
750
|
/**
|
|
624
751
|
* Check if user is authenticated
|
|
625
752
|
* @returns boolean - True if user has valid token
|
|
626
753
|
*/
|
|
627
754
|
async isAuthenticated() {
|
|
755
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
756
|
+
console.log('[AuthService] 🔍 DEBUG: isAuthenticated() called');
|
|
628
757
|
try {
|
|
629
758
|
await this.ensureInitialized();
|
|
630
|
-
|
|
759
|
+
const result = await this.auth0Client.isAuthenticated();
|
|
760
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
761
|
+
console.log('[AuthService] 🔍 DEBUG: isAuthenticated() result from Auth0:', result);
|
|
762
|
+
return result;
|
|
631
763
|
}
|
|
632
764
|
catch (error) {
|
|
633
765
|
console.error('[AuthService] Error checking authentication status:', error);
|
|
634
766
|
// Fallback to checking storage
|
|
635
|
-
|
|
767
|
+
const hasToken = !!getStorageItem(STORAGE_KEYS.ACCESS_TOKEN, STORAGE_CONFIG.TOKEN_STORAGE);
|
|
768
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
769
|
+
console.error('[AuthService] 🔍 DEBUG: isAuthenticated() failed, falling back to storage check:', hasToken);
|
|
770
|
+
return hasToken;
|
|
636
771
|
}
|
|
637
772
|
}
|
|
638
773
|
/**
|
|
@@ -712,6 +847,8 @@ let AuthService = class AuthService {
|
|
|
712
847
|
* @param userInfo - User information to store
|
|
713
848
|
*/
|
|
714
849
|
setUserInfo(userInfo) {
|
|
850
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
851
|
+
console.log('[AuthService] 🔍 DEBUG: setUserInfo() called');
|
|
715
852
|
setStorageItem(STORAGE_KEYS.USER_INFO, JSON.stringify(userInfo), STORAGE_CONFIG.USER_INFO_STORAGE);
|
|
716
853
|
this.userSubject.next(userInfo);
|
|
717
854
|
// Log stored user info with all claims
|
|
@@ -730,6 +867,8 @@ let AuthService = class AuthService {
|
|
|
730
867
|
console.log(` • ${claim}:`, userInfo[claim]);
|
|
731
868
|
});
|
|
732
869
|
}
|
|
870
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
871
|
+
console.log('[AuthService] 🔍 DEBUG: User info stored in storage and userSubject updated');
|
|
733
872
|
this.emitAuthEvent('user_info_updated', userInfo);
|
|
734
873
|
}
|
|
735
874
|
/**
|
|
@@ -744,6 +883,8 @@ let AuthService = class AuthService {
|
|
|
744
883
|
payload,
|
|
745
884
|
timestamp: new Date().toISOString()
|
|
746
885
|
};
|
|
886
|
+
// TODO_REMOVE_DEBUG: Temporary debug log - remove after debugging
|
|
887
|
+
console.log('[AuthService] 🔍 DEBUG: emitAuthEvent() called, event type:', event.type);
|
|
747
888
|
this.eventBus.sendEvent(JSON.stringify(event));
|
|
748
889
|
console.log('[AuthService] Auth event emitted:', event.type);
|
|
749
890
|
}
|