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

View File

@ -20,7 +20,9 @@ import { TranslateLoaderService } from './translate-loader.service';
import { TranslationService } from './translation.service';
import { TranslateModule } from '@ngx-translate/core';
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;
@ -30,14 +32,8 @@ describe('TranslateLoader', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [
AuthModule.forRoot({ useHash: true }),
TranslateModule.forRoot(),
CoreModule.forRoot()
],
providers: [
TranslationService
]
imports: [AuthModule.forRoot({ useHash: true }), TranslateModule.forRoot(), CoreModule.forRoot()],
providers: [TranslationService, { provide: JWT_STORAGE_SERVICE, useClass: StorageService }]
});
translationService = TestBed.inject(TranslationService);
customLoader = translationService.translate.currentLoader as TranslateLoaderService;