fix: get current user call after each login / my apps uses search endpoint for fetching api images
MODIFY
src/app/components/api-card-list/api-card-list.component.ts
src/app/components/api-card-list/api-card-list.component.ts
@@ -109,9 +109,7 @@ export class ApiCardListComponent implements OnInit {
this.ready = false;
this.error = false;
- this.apiService
- .searchApis(this.searchCriteria)
- .pipe(
+ this.apiService.searchApis(this.searchCriteria).pipe(
// map from SearchResultsBeanApiSummaryBean to IApiSummary[]
map((searchResult) => {
this.totalSize = searchResult.totalSize;
@@ -121,8 +119,7 @@ export class ApiCardListComponent implements OnInit {
switchMap((apiSummaries: IApiSummary[]) => {
return this.checkApisDocsInApiVersions(apiSummaries);
})
- )
- .subscribe(
+ ).subscribe(
(apiList: IApiSummaryExt[]) => {
this.apis = apiList;
this.loadingSpinnerService.stopWaiting();

MODIFY
src/app/components/my-apps/my-apps.component.ts
src/app/components/my-apps/my-apps.component.ts
@@ -12,7 +12,7 @@ import {
IApi,
IClientSummary, IClientVersionSummary,
IContract,
- IContractSummary, IPermission, IUserPermissions,
+ IContractSummary, IPermission, ISearchCriteria, ISearchResultsApiSummary, IUserPermissions,
} from '../../interfaces/ICommunication';
import { IContractExt } from '../../interfaces/IContractExt';
import {PolicyService} from "../../services/policy/policy.service";
@@ -175,8 +175,13 @@ export class MyAppsComponent implements OnInit {
// TODO: include this in to the main request chain. Reminder: ApiVersions do not have api.api.image property
private getApiImages(contracts: IContractExt[]){
contracts.forEach((contract: IContractExt) => {
- this.backend.getApi(contract.api.api.organization.id, contract.api.api.id).subscribe((api: IApi) => {
- this.apiImages.set(contract.api.api.name, api.image!);
+ const searchCriteria: ISearchCriteria = {
+ filters: [{name: 'name', value: contract.api.api.name, operator: 'like'}],
+ paging: {page: 1, pageSize: 1}
+ };
+
+ this.backend.searchApis(searchCriteria).subscribe((apiSummaries: ISearchResultsApiSummary) => {
+ this.apiImages.set(contract.api.api.name, apiSummaries.beans[0].image);
});
});
}

MODIFY
src/app/guards/auth.guard.ts
src/app/guards/auth.guard.ts
@@ -7,6 +7,10 @@ import {
} from '@angular/router';
import { KeycloakAuthGuard, KeycloakService } from 'keycloak-angular';
import { KeycloakHelperService } from '../services/keycloak-helper/keycloak-helper.service';
+import {BackendService} from "../services/backend/backend.service";
+import {ICurrentUser} from "../interfaces/ICommunication";
+import {catchError} from "rxjs/operators";
+import {EMPTY} from "rxjs";
@Injectable({
providedIn: 'root',
@@ -15,7 +19,8 @@ export class AuthGuard extends KeycloakAuthGuard {
constructor(
protected readonly router: Router,
protected readonly keycloakAngular: KeycloakService,
- private keycloakHelper: KeycloakHelperService
+ private keycloakHelper: KeycloakHelperService,
+ private backend: BackendService
) {
super(router, keycloakAngular);
}
@@ -37,6 +42,16 @@ export class AuthGuard extends KeycloakAuthGuard {
} else {
// we are logged in and can set the tokens
this.keycloakHelper.setAndUpdateTokens();
+
+ this.backend.getCurrentUser().pipe(
+ catchError((err, caught) => {
+ console.warn(err);
+ this.authenticated = false;
+ return EMPTY;
+ })
+ ).subscribe((user: ICurrentUser) => {
+ console.log('Logged in with user: ', user);
+ });
}
return Promise.resolve(this.authenticated);
}

MODIFY
src/app/services/backend/backend.service.ts
src/app/services/backend/backend.service.ts
@@ -14,7 +14,7 @@ import {
IClientSummary,
IClientVersionSummary,
IContract,
- IContractSummary,
+ IContractSummary, ICurrentUser,
INewContract,
INewOrganization,
IOrganization,
@@ -312,6 +312,11 @@ export class BackendService {
) as Observable<any>;
}
+ public getCurrentUser() {
+ const path = 'users/currentuser/info';
+ return this.http.get<ICurrentUser>(this.generateUrl(path), this.httpOptions);
+ }
+
/********* Helper **********/
private generateUrl(path: string) {
return `${this.endpoint}/${path}`;

fix: get current user call after each login / my apps uses search endpoint for fetching api images