From fd6623b92f1a5a118568a8e010549376fe9f2f0d Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Fri, 20 Sep 2024 21:53:32 +0200 Subject: [PATCH] feat: log when provided configId does not exist --- .../src/lib/config/config.service.spec.ts | 4 ++++ .../src/lib/config/config.service.ts | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/projects/angular-auth-oidc-client/src/lib/config/config.service.spec.ts b/projects/angular-auth-oidc-client/src/lib/config/config.service.spec.ts index fe7ba74e..394543e4 100644 --- a/projects/angular-auth-oidc-client/src/lib/config/config.service.spec.ts +++ b/projects/angular-auth-oidc-client/src/lib/config/config.service.spec.ts @@ -120,9 +120,11 @@ describe('Configuration Service', () => { spyOn(configService as any, 'loadConfigs').and.returnValue(of(configs)); spyOn(configValidationService, 'validateConfig').and.returnValue(false); + const consoleSpy = spyOn(console, 'warn'); configService.getOpenIDConfiguration('configId1').subscribe((config) => { expect(config).toBeNull(); + expect(consoleSpy).toHaveBeenCalledOnceWith(`[angular-auth-oidc-client] No configuration found for config id 'configId1'.`) }); })); @@ -144,6 +146,7 @@ describe('Configuration Service', () => { spyOn(configService as any, 'loadConfigs').and.returnValue(of(configs)); spyOn(configValidationService, 'validateConfig').and.returnValue(true); + const consoleSpy = spyOn(console, 'warn'); spyOn(storagePersistenceService, 'read').and.returnValue({ issuer: 'auth-well-known', @@ -153,6 +156,7 @@ describe('Configuration Service', () => { expect(config?.authWellknownEndpoints).toEqual({ issuer: 'auth-well-known', }); + expect(consoleSpy).not.toHaveBeenCalled() }); })); diff --git a/projects/angular-auth-oidc-client/src/lib/config/config.service.ts b/projects/angular-auth-oidc-client/src/lib/config/config.service.ts index cf1042a0..d395e428 100644 --- a/projects/angular-auth-oidc-client/src/lib/config/config.service.ts +++ b/projects/angular-auth-oidc-client/src/lib/config/config.service.ts @@ -1,4 +1,4 @@ -import { inject, Injectable } from '@angular/core'; +import {inject, Injectable, isDevMode} from '@angular/core'; import { forkJoin, Observable, of } from 'rxjs'; import { concatMap, map } from 'rxjs/operators'; import { LoggerService } from '../logging/logger.service'; @@ -85,7 +85,13 @@ export class ConfigurationService { private getConfig(configId?: string): OpenIdConfiguration | null { if (Boolean(configId)) { - return this.configsInternal[configId as string] || null; + const config = this.configsInternal[configId!]; + + if(!config && isDevMode()) { + console.warn(`[angular-auth-oidc-client] No configuration found for config id '${configId}'.`); + } + + return config || null; } const [, value] = Object.entries(this.configsInternal)[0] || [[null, null]];