Writing should use the same calss as reading

This commit is contained in:
VitoAlbano 2024-10-14 18:04:18 +01:00
parent c0ce6f70b3
commit 81df3bdabb
2 changed files with 15 additions and 14 deletions

View File

@ -15,18 +15,16 @@
* limitations under the License. * limitations under the License.
*/ */
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core'; import { APP_INITIALIZER, inject, ModuleWithProviders, NgModule } from '@angular/core';
import { AUTH_CONFIG, OAuthModule, OAuthStorage } from 'angular-oauth2-oidc'; import { AUTH_CONFIG, OAuthModule, OAuthStorage } from 'angular-oauth2-oidc';
import { AuthenticationService } from '../services/authentication.service'; import { AuthenticationService } from '../services/authentication.service';
import { StorageService } from '../../common/services/storage.service';
import { AuthModuleConfig, AUTH_MODULE_CONFIG } from './auth-config'; import { AuthModuleConfig, AUTH_MODULE_CONFIG } from './auth-config';
import { authConfigFactory, AuthConfigService } from './auth-config.service'; import { authConfigFactory, AuthConfigService } from './auth-config.service';
import { AuthRoutingModule } from './auth-routing.module'; import { AuthRoutingModule } from './auth-routing.module';
import { AuthService } from './auth.service'; import { AuthService } from './auth.service';
import { RedirectAuthService } from './redirect-auth.service'; import { RedirectAuthService } from './redirect-auth.service';
import { AuthenticationConfirmationComponent } from './view/authentication-confirmation/authentication-confirmation.component'; import { AuthenticationConfirmationComponent } from './view/authentication-confirmation/authentication-confirmation.component';
import { HTTP_INTERCEPTORS } from '@angular/common/http'; import { JWT_STORAGE_SERVICE } from '../services/jwt-helper.service';
import { TokenInterceptor } from './token.interceptor';
/** /**
* Create a Login Factory function * Create a Login Factory function
@ -38,11 +36,18 @@ export function loginFactory(redirectService: RedirectAuthService): () => Promis
return () => redirectService.init(); return () => redirectService.init();
} }
/**
* @returns current instance of OAuthStorage
*/
export function oauthStorageFactory(): OAuthStorage {
return inject(JWT_STORAGE_SERVICE);
}
@NgModule({ @NgModule({
declarations: [AuthenticationConfirmationComponent], declarations: [AuthenticationConfirmationComponent],
imports: [AuthRoutingModule, OAuthModule.forRoot()], imports: [AuthRoutingModule, OAuthModule.forRoot()],
providers: [ providers: [
{ provide: OAuthStorage, useExisting: StorageService }, { provide: OAuthStorage, useFactory: oauthStorageFactory },
{ provide: AuthenticationService }, { provide: AuthenticationService },
{ {
provide: AUTH_CONFIG, provide: AUTH_CONFIG,

View File

@ -20,7 +20,9 @@ import { TranslateLoaderService } from './translate-loader.service';
import { TranslationService } from './translation.service'; import { TranslationService } from './translation.service';
import { TranslateModule } from '@ngx-translate/core'; import { TranslateModule } from '@ngx-translate/core';
import { CoreModule } from '../core.module'; import { CoreModule } from '../core.module';
import { AuthModule } from '../auth'; import { AuthModule } from '../auth/oidc/auth.module';
import { StorageService } from '../common';
import { JWT_STORAGE_SERVICE } from '../auth/services/jwt-helper.service';
declare let jasmine: any; declare let jasmine: any;
@ -30,14 +32,8 @@ describe('TranslateLoader', () => {
beforeEach(() => { beforeEach(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [ imports: [AuthModule.forRoot({ useHash: true }), TranslateModule.forRoot(), CoreModule.forRoot()],
AuthModule.forRoot({ useHash: true }), providers: [TranslationService, { provide: JWT_STORAGE_SERVICE, useClass: StorageService }]
TranslateModule.forRoot(),
CoreModule.forRoot()
],
providers: [
TranslationService
]
}); });
translationService = TestBed.inject(TranslationService); translationService = TestBed.inject(TranslationService);
customLoader = translationService.translate.currentLoader as TranslateLoaderService; customLoader = translationService.translate.currentLoader as TranslateLoaderService;