Added fallback for injection

This commit is contained in:
VitoAlbano
2024-10-15 12:05:53 +01:00
parent e81342ff7f
commit 5e96ce909c

View File

@@ -15,10 +15,8 @@
* limitations under the License. * limitations under the License.
*/ */
import { Inject, Injectable } from '@angular/core'; import { inject, Injectable } from '@angular/core';
import { OAuthStorage } from 'angular-oauth2-oidc'; import { OAuthStorage } from 'angular-oauth2-oidc';
import { StorageService } from '../../common/services/storage.service';
import { JWT_STORAGE_SERVICE } from '../oidc/auth.module';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -35,11 +33,7 @@ export class JwtHelperService {
static USER_PREFERRED_USERNAME = 'preferred_username'; static USER_PREFERRED_USERNAME = 'preferred_username';
static HXP_AUTHORIZATION = 'hxp_authorization'; static HXP_AUTHORIZATION = 'hxp_authorization';
private storageService: OAuthStorage; private storageService: OAuthStorage = inject(OAuthStorage)
constructor (@Inject(JWT_STORAGE_SERVICE) jwtStorageService: OAuthStorage, private defaultStorageService: StorageService) {
this.storageService = jwtStorageService ?? defaultStorageService;
}
/** /**
* Decodes a JSON web token into a JS object. * Decodes a JSON web token into a JS object.