From f6d1b8623c2b1cc090c751b8c1b188ca9d0fa561 Mon Sep 17 00:00:00 2001 From: Andreas Knuth Date: Wed, 19 Feb 2025 16:24:42 -0600 Subject: [PATCH] remove keycloak --- bizmatch-server/.vscode/launch.json | 4 +- .../src/drizzle/importFromExported.ts | 68 +++++++++++++++++++ bizmatch-server/src/drizzle/migrate.ts | 12 ---- bizmatch/package.json | 4 +- bizmatch/src/app/app.component.ts | 56 +++++++-------- bizmatch/src/app/app.config.ts | 61 ----------------- .../app/components/header/header.component.ts | 17 ++--- .../app/components/logout/logout.component.ts | 6 +- bizmatch/src/app/guards/auth.guard.ts | 33 --------- .../details-business-listing.component.ts | 7 +- ...s-commercial-property-listing.component.ts | 7 +- .../details-user/details-user.component.ts | 8 +-- .../src/app/pages/home/home.component.html | 4 +- bizmatch/src/app/pages/home/home.component.ts | 21 +++--- .../src/app/pages/login/login.component.ts | 5 +- .../app/pages/pricing/pricing.component.ts | 30 ++------ .../subscription/account/account.component.ts | 8 +-- .../edit-business-listing.component.ts | 3 - ...t-commercial-property-listing.component.ts | 3 - .../email-us/email-us.component.ts | 4 -- .../favorites/favorites.component.ts | 10 +-- .../my-listing/my-listing.component.ts | 13 ---- .../app/pages/success/success.component.ts | 4 +- .../src/app/services/globalErrorHandler.ts | 8 +-- .../services/keycloak-initializer.service.ts | 49 +++++++------ bizmatch/src/app/utils/utils.ts | 3 + 26 files changed, 166 insertions(+), 282 deletions(-) create mode 100644 bizmatch-server/src/drizzle/importFromExported.ts delete mode 100644 bizmatch-server/src/drizzle/migrate.ts diff --git a/bizmatch-server/.vscode/launch.json b/bizmatch-server/.vscode/launch.json index fb9a8e7..d1bc0a5 100644 --- a/bizmatch-server/.vscode/launch.json +++ b/bizmatch-server/.vscode/launch.json @@ -14,8 +14,8 @@ "console": "integratedTerminal", "env": { "HOST_NAME": "localhost" - }, - "preLaunchTask": "Start Stripe Listener" + } + // "preLaunchTask": "Start Stripe Listener" }, { "type": "node", diff --git a/bizmatch-server/src/drizzle/importFromExported.ts b/bizmatch-server/src/drizzle/importFromExported.ts new file mode 100644 index 0000000..4d98371 --- /dev/null +++ b/bizmatch-server/src/drizzle/importFromExported.ts @@ -0,0 +1,68 @@ +import 'dotenv/config'; +import { drizzle } from 'drizzle-orm/node-postgres'; +import { readFileSync } from 'fs'; +import { Pool } from 'pg'; +import { BusinessListingService } from 'src/listings/business-listing.service'; +import { CommercialPropertyService } from 'src/listings/commercial-property.service'; +import { UserService } from 'src/user/user.service'; +import winston from 'winston'; +import { BusinessListing, CommercialPropertyListing, User } from '../models/db.model'; +import * as schema from './schema'; + +(async () => { + const connectionString = process.env.DATABASE_URL; + const client = new Pool({ connectionString }); + const db = drizzle(client, { schema, logger: true }); + const logger = winston.createLogger({ + transports: [new winston.transports.Console()], + }); + const commService = new CommercialPropertyService(null, db); + const businessService = new BusinessListingService(null, db); + const userService = new UserService(null, db, null, null); + + //Delete Content + await db.delete(schema.commercials); + await db.delete(schema.businesses); + await db.delete(schema.users); + + let filePath = `./data/users_export.json`; + let data: string = readFileSync(filePath, 'utf8'); + const usersData: User[] = JSON.parse(data); // Erwartet ein Array von Objekten + for (let index = 0; index < usersData.length; index++) { + const user = usersData[index]; + delete user.id; + const u = await userService.saveUser(user, false); + logger.info(`user_${index} inserted`); + } + + //Corporate Listings + filePath = `./data/commercials_export.json`; + data = readFileSync(filePath, 'utf8'); + const commercialJsonData = JSON.parse(data) as CommercialPropertyListing[]; // Erwartet ein Array von Objekten + for (let index = 0; index < commercialJsonData.length; index++) { + const commercial = commercialJsonData[index]; + delete commercial.id; + const result = await commService.createListing(commercial); + } + + //Business Listings + filePath = `./data/businesses_export.json`; + data = readFileSync(filePath, 'utf8'); + const businessJsonData = JSON.parse(data) as BusinessListing[]; // Erwartet ein Array von Objekten + for (let index = 0; index < businessJsonData.length; index++) { + const business = businessJsonData[index]; + delete business.id; + await businessService.createListing(business); + } + + //End + await client.end(); +})(); +function getRandomItem(arr: T[]): T { + if (arr.length === 0) { + throw new Error('The array is empty.'); + } + + const randomIndex = Math.floor(Math.random() * arr.length); + return arr[randomIndex]; +} diff --git a/bizmatch-server/src/drizzle/migrate.ts b/bizmatch-server/src/drizzle/migrate.ts deleted file mode 100644 index e35435a..0000000 --- a/bizmatch-server/src/drizzle/migrate.ts +++ /dev/null @@ -1,12 +0,0 @@ -import 'dotenv/config'; -import { drizzle } from 'drizzle-orm/node-postgres'; -import pkg from 'pg'; -import * as schema from './schema'; -const { Pool } = pkg; -const connectionString = process.env.DATABASE_URL; -const pool = new Pool({ connectionString }); -const db = drizzle(pool, { schema }); -// This will run migrations on the database, skipping the ones already applied -//await migrate(db, { migrationsFolder: './src/drizzle/migrations' }); -// Don't forget to close the connection, otherwise the script will hang -//await pool.end(); diff --git a/bizmatch/package.json b/bizmatch/package.json index 4b88f19..4b2decb 100644 --- a/bizmatch/package.json +++ b/bizmatch/package.json @@ -42,8 +42,6 @@ "express": "^4.18.2", "flowbite": "^2.4.1", "jwt-decode": "^4.0.0", - "keycloak-angular": "^16.0.1", - "keycloak-js": "^25.0.1", "leaflet": "^1.9.4", "memoize-one": "^6.0.0", "ng-gallery": "^11.0.0", @@ -79,4 +77,4 @@ "tailwindcss": "^3.4.4", "typescript": "~5.4.5" } -} +} \ No newline at end of file diff --git a/bizmatch/src/app/app.component.ts b/bizmatch/src/app/app.component.ts index 6962509..4dc0bdf 100644 --- a/bizmatch/src/app/app.component.ts +++ b/bizmatch/src/app/app.component.ts @@ -1,7 +1,6 @@ import { CommonModule } from '@angular/common'; import { Component, HostListener } from '@angular/core'; import { ActivatedRoute, NavigationEnd, Router, RouterOutlet } from '@angular/router'; -import { KeycloakEventType, KeycloakService } from 'keycloak-angular'; import { filter } from 'rxjs/operators'; import build from '../build'; @@ -34,7 +33,6 @@ export class AppComponent { public loadingService: LoadingService, private router: Router, private activatedRoute: ActivatedRoute, - private keycloakService: KeycloakService, private userService: UserService, private confirmationService: ConfirmationService, private auditService: AuditService, @@ -50,35 +48,33 @@ export class AppComponent { }); } ngOnInit() { - // Überwache Keycloak-Events, um den Token-Refresh zu kontrollieren - this.keycloakService.keycloakEvents$.subscribe({ - next: event => { - if (event.type === KeycloakEventType.OnTokenExpired) { - // Wenn der Token abgelaufen ist, versuchen wir einen Refresh - this.handleTokenExpiration(); - } - }, - }); - } - private async handleTokenExpiration(): Promise { - try { - // Versuche, den Token zu erneuern - const refreshed = await this.keycloakService.updateToken(); - if (!refreshed) { - // Wenn der Token nicht erneuert werden kann, leite zur Login-Seite weiter - this.keycloakService.login({ - redirectUri: window.location.href, // oder eine andere Seite - }); - } - } catch (error) { - if (error.error === 'invalid_grant' && error.error_description === 'Token is not active') { - // Hier wird der Fehler "invalid_grant" abgefangen - this.keycloakService.login({ - redirectUri: window.location.href, - }); - } - } + // this.keycloakService.keycloakEvents$.subscribe({ + // next: event => { + // if (event.type === KeycloakEventType.OnTokenExpired) { + // this.handleTokenExpiration(); + // } + // }, + // }); } + // private async handleTokenExpiration(): Promise { + // try { + // // Versuche, den Token zu erneuern + // const refreshed = await this.keycloakService.updateToken(); + // if (!refreshed) { + // // Wenn der Token nicht erneuert werden kann, leite zur Login-Seite weiter + // this.keycloakService.login({ + // redirectUri: window.location.href, // oder eine andere Seite + // }); + // } + // } catch (error) { + // if (error.error === 'invalid_grant' && error.error_description === 'Token is not active') { + // // Hier wird der Fehler "invalid_grant" abgefangen + // this.keycloakService.login({ + // redirectUri: window.location.href, + // }); + // } + // } + // } @HostListener('window:keydown', ['$event']) handleKeyboardEvent(event: KeyboardEvent) { if (event.shiftKey && event.ctrlKey && event.key === 'V') { diff --git a/bizmatch/src/app/app.config.ts b/bizmatch/src/app/app.config.ts index 72eb61b..a06db31 100644 --- a/bizmatch/src/app/app.config.ts +++ b/bizmatch/src/app/app.config.ts @@ -5,7 +5,6 @@ import { HTTP_INTERCEPTORS, provideHttpClient, withInterceptorsFromDi } from '@a import { initializeApp, provideFirebaseApp } from '@angular/fire/app'; import { getAuth, provideAuth } from '@angular/fire/auth'; import { provideAnimations } from '@angular/platform-browser/animations'; -import { KeycloakBearerInterceptor, KeycloakService } from 'keycloak-angular'; import { GALLERY_CONFIG, GalleryConfig } from 'ng-gallery'; import { provideQuillConfig } from 'ngx-quill'; import { provideShareButtonsOptions, SharerMethods, withConfig } from 'ngx-sharebuttons'; @@ -17,7 +16,6 @@ import { AuthInterceptor } from './interceptors/auth.interceptor'; import { LoadingInterceptor } from './interceptors/loading.interceptor'; import { TimeoutInterceptor } from './interceptors/timeout.interceptor'; import { GlobalErrorHandler } from './services/globalErrorHandler'; -import { KeycloakInitializerService } from './services/keycloak-initializer.service'; import { SelectOptionsService } from './services/select-options.service'; import { createLogger } from './utils/utils'; // provideClientHydration() @@ -25,16 +23,6 @@ const logger = createLogger('ApplicationConfig'); export const appConfig: ApplicationConfig = { providers: [ provideHttpClient(withInterceptorsFromDi()), - { provide: KeycloakService }, - { - provide: APP_INITIALIZER, - // useFactory: initializeKeycloak1, - //useFactory: initializeKeycloak2, - useFactory: initializeKeycloak, - multi: true, - //deps: [KeycloakService], - deps: [KeycloakInitializerService], - }, { provide: APP_INITIALIZER, useFactory: initServices, @@ -46,11 +34,6 @@ export const appConfig: ApplicationConfig = { useClass: LoadingInterceptor, multi: true, }, - { - provide: HTTP_INTERCEPTORS, - useClass: KeycloakBearerInterceptor, - multi: true, - }, { provide: HTTP_INTERCEPTORS, useClass: TimeoutInterceptor, @@ -108,47 +91,3 @@ function initServices(selectOptions: SelectOptionsService) { await selectOptions.init(); }; } -export function initializeKeycloak(keycloak: KeycloakInitializerService) { - return () => keycloak.initialize(); -} - -// export function initializeKeycloak1(keycloak: KeycloakService): () => Promise { -// return async () => { -// const { url, realm, clientId } = environment.keycloak; -// const adapter = customKeycloakAdapter(() => keycloak.getKeycloakInstance(), {}); -// if (window.location.search.length > 0) { -// sessionStorage.setItem('SEARCH', window.location.search); -// } -// const { host, hostname, href, origin, pathname, port, protocol, search } = window.location; -// await keycloak.init({ -// config: { url, realm, clientId }, -// initOptions: { -// onLoad: 'check-sso', -// silentCheckSsoRedirectUri: window.location.hostname === 'localhost' ? `${window.location.origin}/assets/silent-check-sso.html` : `${window.location.origin}/dealerweb/assets/silent-check-sso.html`, -// adapter, -// redirectUri: `${origin}${pathname}`, -// }, -// }); -// }; -// } -// function initializeKeycloak2(keycloak: KeycloakService) { -// return async () => { -// logger.info(`###>calling keycloakService init ...`); -// const authenticated = await keycloak.init({ -// config: { -// url: environment.keycloak.url, -// realm: environment.keycloak.realm, -// clientId: environment.keycloak.clientId, -// }, -// initOptions: { -// onLoad: 'check-sso', -// silentCheckSsoRedirectUri: (window).location.origin + '/assets/silent-check-sso.html', -// }, -// bearerExcludedUrls: ['/assets'], -// shouldUpdateToken(request) { -// return !request.headers.get('token-update') === false; -// }, -// }); -// logger.info(`+++>${authenticated}`); -// }; -// } diff --git a/bizmatch/src/app/components/header/header.component.ts b/bizmatch/src/app/components/header/header.component.ts index 5609c38..98cd16e 100644 --- a/bizmatch/src/app/components/header/header.component.ts +++ b/bizmatch/src/app/components/header/header.component.ts @@ -6,7 +6,6 @@ import { NavigationEnd, Router, RouterModule } from '@angular/router'; import { faUserGear } from '@fortawesome/free-solid-svg-icons'; import { UntilDestroy, untilDestroyed } from '@ngneat/until-destroy'; import { Collapse, Dropdown, initFlowbite } from 'flowbite'; -import { KeycloakService } from 'keycloak-angular'; import { filter, Observable, Subject, Subscription } from 'rxjs'; import { SortByOptions, User } from '../../../../../bizmatch-server/src/models/db.model'; import { BusinessListingCriteria, CommercialPropertyListingCriteria, emailToDirName, KeycloakUser, KeyValueAsSortBy, UserListingCriteria } from '../../../../../bizmatch-server/src/models/main.model'; @@ -17,7 +16,7 @@ import { SearchService } from '../../services/search.service'; import { SelectOptionsService } from '../../services/select-options.service'; import { SharedService } from '../../services/shared.service'; import { UserService } from '../../services/user.service'; -import { assignProperties, compareObjects, createEmptyBusinessListingCriteria, createEmptyCommercialPropertyListingCriteria, createEmptyUserListingCriteria, getCriteriaProxy, map2User } from '../../utils/utils'; +import { assignProperties, compareObjects, createEmptyBusinessListingCriteria, createEmptyCommercialPropertyListingCriteria, createEmptyUserListingCriteria, getCriteriaProxy, isAdmin, map2User } from '../../utils/utils'; import { DropdownComponent } from '../dropdown/dropdown.component'; import { ModalService } from '../search-modal/modal.service'; @UntilDestroy() @@ -48,7 +47,6 @@ export class HeaderComponent { sortDropdownVisible: boolean; sortByOptions: KeyValueAsSortBy[] = []; constructor( - public keycloakService: KeycloakService, private router: Router, private userService: UserService, private sharedService: SharedService, @@ -67,7 +65,6 @@ export class HeaderComponent { } } async ngOnInit() { - //const token = await this.keycloakService.getToken(); const token = await this.authService.getToken(); this.keycloakUser = map2User(token); if (this.keycloakUser) { @@ -127,11 +124,6 @@ export class HeaderComponent { navigateWithState(dest: string, state: any) { this.router.navigate([dest], { state: state }); } - login() { - this.keycloakService.login({ - redirectUri: `${window.location.origin}/login${this.router.routerState.snapshot.url}`, - }); - } isActive(route: string): boolean { return this.router.url === route; @@ -192,9 +184,7 @@ export class HeaderComponent { return 0; } } - isAdmin() { - return this.keycloakService.getUserRoles(true).includes('ADMIN'); - } + sortBy(sortBy: SortByOptions) { this.criteria.sortBy = sortBy; this.sortDropdownVisible = false; @@ -203,4 +193,7 @@ export class HeaderComponent { toggleSortDropdown() { this.sortDropdownVisible = !this.sortDropdownVisible; } + isAdmin() { + return isAdmin(this.user.email); + } } diff --git a/bizmatch/src/app/components/logout/logout.component.ts b/bizmatch/src/app/components/logout/logout.component.ts index 8d8ad06..69f9abb 100644 --- a/bizmatch/src/app/components/logout/logout.component.ts +++ b/bizmatch/src/app/components/logout/logout.component.ts @@ -1,7 +1,7 @@ import { CommonModule } from '@angular/common'; import { Component } from '@angular/core'; import { Router, RouterModule } from '@angular/router'; -import { KeycloakService } from 'keycloak-angular'; + import { AuthService } from '../../services/auth.service'; @Component({ @@ -11,9 +11,7 @@ import { AuthService } from '../../services/auth.service'; template: ``, }) export class LogoutComponent { - constructor(public keycloakService: KeycloakService, private authService: AuthService, private router: Router) { - //sessionStorage.removeItem('USERID'); - //keycloakService.logout(window.location.origin + '/home'); + constructor(private authService: AuthService, private router: Router) { this.authService.logout(); this.router.navigate(['/home']); } diff --git a/bizmatch/src/app/guards/auth.guard.ts b/bizmatch/src/app/guards/auth.guard.ts index ef894d6..01bb7b7 100644 --- a/bizmatch/src/app/guards/auth.guard.ts +++ b/bizmatch/src/app/guards/auth.guard.ts @@ -6,39 +6,6 @@ const logger = createLogger('AuthGuard'); @Injectable({ providedIn: 'root', }) -// export class AuthGuard extends KeycloakAuthGuard { -// constructor(protected override readonly router: Router, protected readonly keycloak: KeycloakService, private keycloakInitializer: KeycloakInitializerService) { -// super(router, keycloak); -// } - -// async isAccessAllowed(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise { -// logger.info(`--->AuthGuard`); -// while (!this.keycloakInitializer.initialized) { -// logger.info(`Waiting 100 msec`); -// await new Promise(resolve => setTimeout(resolve, 100)); -// } -// // Force the user to log in if currently unauthenticated. -// const authenticated = this.keycloak.isLoggedIn(); -// //this.keycloak.isTokenExpired() -// if (!this.authenticated && !authenticated) { -// await this.keycloak.login({ -// redirectUri: window.location.origin + state.url, -// }); -// // return false; -// } - -// // Get the roles required from the route. -// const requiredRoles = route.data['roles']; - -// // Allow the user to proceed if no additional roles are required to access the route. -// if (!Array.isArray(requiredRoles) || requiredRoles.length === 0) { -// return true; -// } - -// // Allow the user to proceed if all the required roles are present. -// return requiredRoles.every(role => this.roles.includes(role)); -// } -// } export class AuthGuard implements CanActivate { constructor(private authService: AuthService, private router: Router) {} diff --git a/bizmatch/src/app/pages/details/details-business-listing/details-business-listing.component.ts b/bizmatch/src/app/pages/details/details-business-listing/details-business-listing.component.ts index 3cc3f62..a194145 100644 --- a/bizmatch/src/app/pages/details/details-business-listing/details-business-listing.component.ts +++ b/bizmatch/src/app/pages/details/details-business-listing/details-business-listing.component.ts @@ -2,7 +2,6 @@ import { Component } from '@angular/core'; import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; import { ActivatedRoute, NavigationEnd, Router } from '@angular/router'; import { LeafletModule } from '@bluehalo/ngx-leaflet'; -import { KeycloakService } from 'keycloak-angular'; import { ShareButton } from 'ngx-sharebuttons/button'; import { lastValueFrom } from 'rxjs'; import { BusinessListing, EventTypeEnum, ShareByEMail, User } from '../../../../../../bizmatch-server/src/models/db.model'; @@ -22,7 +21,7 @@ import { MailService } from '../../../services/mail.service'; import { SelectOptionsService } from '../../../services/select-options.service'; import { UserService } from '../../../services/user.service'; import { SharedModule } from '../../../shared/shared/shared.module'; -import { createMailInfo, map2User } from '../../../utils/utils'; +import { createMailInfo, isAdmin, map2User } from '../../../utils/utils'; // Import für Leaflet // Benannte Importe für Leaflet import { AuthService } from '../../../services/auth.service'; @@ -75,7 +74,6 @@ export class DetailsBusinessListingComponent extends BaseDetailsComponent { private mailService: MailService, private sanitizer: DomSanitizer, public historyService: HistoryService, - public keycloakService: KeycloakService, private validationMessagesService: ValidationMessagesService, private messageService: MessageService, private auditService: AuditService, @@ -94,7 +92,6 @@ export class DetailsBusinessListingComponent extends BaseDetailsComponent { } async ngOnInit() { - // const token = await this.keycloakService.getToken(); const token = await this.authService.getToken(); this.keycloakUser = map2User(token); if (this.keycloakUser) { @@ -119,7 +116,7 @@ export class DetailsBusinessListingComponent extends BaseDetailsComponent { this.validationMessagesService.clearMessages(); // Löschen Sie alle bestehenden Validierungsnachrichten } isAdmin() { - return this.keycloakService.getUserRoles(true).includes('ADMIN'); + return isAdmin(this.keycloakUser.email); //this.keycloakService.getUserRoles(true).includes('ADMIN'); } async mail() { try { diff --git a/bizmatch/src/app/pages/details/details-commercial-property-listing/details-commercial-property-listing.component.ts b/bizmatch/src/app/pages/details/details-commercial-property-listing/details-commercial-property-listing.component.ts index 7a34f0b..81c447b 100644 --- a/bizmatch/src/app/pages/details/details-commercial-property-listing/details-commercial-property-listing.component.ts +++ b/bizmatch/src/app/pages/details/details-commercial-property-listing/details-commercial-property-listing.component.ts @@ -3,7 +3,6 @@ import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; import { ActivatedRoute, Router } from '@angular/router'; import { LeafletModule } from '@bluehalo/ngx-leaflet'; import { faTimes } from '@fortawesome/free-solid-svg-icons'; -import { KeycloakService } from 'keycloak-angular'; import { GalleryModule, ImageItem } from 'ng-gallery'; import { ShareButton } from 'ngx-sharebuttons/button'; import { lastValueFrom } from 'rxjs'; @@ -25,7 +24,7 @@ import { MailService } from '../../../services/mail.service'; import { SelectOptionsService } from '../../../services/select-options.service'; import { UserService } from '../../../services/user.service'; import { SharedModule } from '../../../shared/shared/shared.module'; -import { createMailInfo, map2User } from '../../../utils/utils'; +import { createMailInfo, isAdmin, map2User } from '../../../utils/utils'; import { BaseDetailsComponent } from '../base-details.component'; @Component({ @@ -78,7 +77,6 @@ export class DetailsCommercialPropertyListingComponent extends BaseDetailsCompon private mailService: MailService, private sanitizer: DomSanitizer, public historyService: HistoryService, - public keycloakService: KeycloakService, private imageService: ImageService, private ngZone: NgZone, private validationMessagesService: ValidationMessagesService, @@ -92,7 +90,6 @@ export class DetailsCommercialPropertyListingComponent extends BaseDetailsCompon } async ngOnInit() { - // const token = await this.keycloakService.getToken(); const token = await this.authService.getToken(); this.keycloakUser = map2User(token); if (this.keycloakUser) { @@ -143,7 +140,7 @@ export class DetailsCommercialPropertyListingComponent extends BaseDetailsCompon }); } isAdmin() { - return this.keycloakService.getUserRoles(true).includes('ADMIN'); + return isAdmin(this.keycloakUser.email); } async mail() { try { diff --git a/bizmatch/src/app/pages/details/details-user/details-user.component.ts b/bizmatch/src/app/pages/details/details-user/details-user.component.ts index a6ecfda..e81c8d2 100644 --- a/bizmatch/src/app/pages/details/details-user/details-user.component.ts +++ b/bizmatch/src/app/pages/details/details-user/details-user.component.ts @@ -1,7 +1,6 @@ import { Component } from '@angular/core'; import { DomSanitizer, SafeHtml } from '@angular/platform-browser'; import { ActivatedRoute, Router } from '@angular/router'; -import { KeycloakService } from 'keycloak-angular'; import { Observable } from 'rxjs'; import { BusinessListing, CommercialPropertyListing, User } from '../../../../../../bizmatch-server/src/models/db.model'; import { KeycloakUser, emailToDirName } from '../../../../../../bizmatch-server/src/models/main.model'; @@ -13,7 +12,7 @@ import { ListingsService } from '../../../services/listings.service'; import { SelectOptionsService } from '../../../services/select-options.service'; import { UserService } from '../../../services/user.service'; import { SharedModule } from '../../../shared/shared/shared.module'; -import { formatPhoneNumber, map2User } from '../../../utils/utils'; +import { formatPhoneNumber, isAdmin, map2User } from '../../../utils/utils'; @Component({ selector: 'app-details-user', @@ -46,7 +45,6 @@ export class DetailsUserComponent { private sanitizer: DomSanitizer, private imageService: ImageService, public historyService: HistoryService, - public keycloakService: KeycloakService, private authService: AuthService, ) {} @@ -56,8 +54,6 @@ export class DetailsUserComponent { // Zuweisen der Ergebnisse zu den Member-Variablen der Klasse this.businessListings = results[0]; this.commercialPropListings = results[1] as CommercialPropertyListing[]; - //this.user$ = this.userService.getUserObservable(); - // const token = await this.keycloakService.getToken(); const token = await this.authService.getToken(); this.keycloakUser = map2User(token); this.companyOverview = this.sanitizer.bypassSecurityTrustHtml(this.user.companyOverview ? this.user.companyOverview : ''); @@ -65,6 +61,6 @@ export class DetailsUserComponent { } isAdmin() { - return this.keycloakService.getUserRoles(true).includes('ADMIN'); + return isAdmin(this.user.email); } } diff --git a/bizmatch/src/app/pages/home/home.component.html b/bizmatch/src/app/pages/home/home.component.html index 92db789..6388e3f 100644 --- a/bizmatch/src/app/pages/home/home.component.html +++ b/bizmatch/src/app/pages/home/home.component.html @@ -23,8 +23,8 @@ @if(user){ Account } @else { - Log In - Register + Log In + Register }