From 0078aed04efec2f6df3f762554ba769640db6fbe Mon Sep 17 00:00:00 2001
From: Helmut Hutzler <helmut.hutzler@th-nuernberg.de>
Date: Wed, 30 Nov 2022 16:24:34 +0100
Subject: [PATCH] Configure proxyConfig fo ng serve Recalculate real Keycloak
 Url by reading evironment.proxyKeycloakUrl

---
 angular.json                                  |  3 ++-
 .../account-self-deletion.component.ts        | 22 ++++++++++++++++---
 src/environments/environment.ts               |  5 +++--
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/angular.json b/angular.json
index 3b31c2c..fbf0fa5 100644
--- a/angular.json
+++ b/angular.json
@@ -68,7 +68,8 @@
         "serve": {
           "builder": "@angular-devkit/build-angular:dev-server",
           "options": {
-            "browserTarget": "angular-oidc-authorization-sample:build"
+            "browserTarget": "angular-oidc-authorization-sample:build",
+            "proxyConfig": "proxy.conf.dev.json"
           },
           "configurations": {
             "production": {
diff --git a/src/app/account-self-deletion/account-self-deletion.component.ts b/src/app/account-self-deletion/account-self-deletion.component.ts
index d0e442b..758cfe0 100644
--- a/src/app/account-self-deletion/account-self-deletion.component.ts
+++ b/src/app/account-self-deletion/account-self-deletion.component.ts
@@ -2,6 +2,7 @@ import { Component, OnInit } from '@angular/core';
 import {AccountService} from "../account.service";
 import {MessageService} from "../message.service";
 import {FormBuilder} from "@angular/forms";
+import {environment} from "../../environments/environment";
 
 @Component({
   selector: 'app-account-self-deletion',
@@ -10,15 +11,30 @@ import {FormBuilder} from "@angular/forms";
 })
 export class AccountSelfDeletionComponent implements OnInit {
   private logHeader = '';
-
+  private redirectLoction  = '';
   constructor(public accountService: AccountService,
               public messageService: MessageService,
     ) {}
 
   ngOnInit(): void {
     this.logHeader = "[AccountSelfDeletionComponent:ngOnInit()] ";
-    this.messageService.add(this.logHeader + 'Inside   ngOnInit')
-    window.location.href = "http://localhost:8280/auth/realms/RBAC/account/#/personal-info";
+    this.messageService.add(this.logHeader + 'Inside   ngOnInit');
+    /*
+        Recalulate Keyloak URL
+        Note : As we use a proxyConfig we currently don't know the real keycloak URL .
+               if we just use /auth this will fails as we get  redirect to http://localhaost:4200:/auth
+        To overcome this we have defined environment.proxyKeycloakURL
+     */
+    if (!environment.production) {
+      this.redirectLoction = environment.proxyKeycloakURL;
+    }
+    else {
+      this.redirectLoction = environment.keycloakURL;
+    }
+    this.redirectLoction = this.redirectLoction + 'realms/RBAC/account/#/personal-info';
+    console.warn('Now running Page Redirect to : ' + this.redirectLoction);
+    //window.location.href = "https://kube-master-h1.informatik.fh-nuernberg.de/auth/realms/RBAC/account/#/personal-info";
+    window.location.href = this.redirectLoction;
   }
 
 }
diff --git a/src/environments/environment.ts b/src/environments/environment.ts
index d251bc7..f8058b4 100644
--- a/src/environments/environment.ts
+++ b/src/environments/environment.ts
@@ -8,10 +8,11 @@ export const environment = {
   production: false,
    //  keycloakURL: 'http://localhost:8280/auth/'
     keycloakURL: '/auth/',
-    // keycloakURL: 'https://kube-master-h1.informatik.fh-nuernberg.de/auth/',
+    // Only used for development in account-self-deletion.component component for page redirect
+    proxyKeycloakURL: 'https://kube-master-h1.informatik.fh-nuernberg.de/auth/',
     //  apiURL: 'http://localhost:8080/api',
     apiURL: '/api',
-     appVersion: require('../../package.json').version
+    appVersion: require('../../package.json').version
 
 };
 
-- 
GitLab