From 8ca9a99593b2b1f4b50b3ca7ba0aa1c5abc27b87 Mon Sep 17 00:00:00 2001 From: Andrey Melnikov Date: Wed, 28 Oct 2020 13:32:46 -0700 Subject: [PATCH 1/4] feat: updated code to detect local development and not set domain when setting cookies/local storage. --- src/app/auth/auth.service.ts | 7 +++++++ src/environments/environment.local.ts | 0 src/environments/environment.prod.ts | 3 ++- src/environments/environment.ts | 5 +++-- 4 files changed, 12 insertions(+), 3 deletions(-) delete mode 100644 src/environments/environment.local.ts diff --git a/src/app/auth/auth.service.ts b/src/app/auth/auth.service.ts index 44b70536..6da8caee 100644 --- a/src/app/auth/auth.service.ts +++ b/src/app/auth/auth.service.ts @@ -1,4 +1,5 @@ import { Injectable } from '@angular/core'; +import { environment } from '../../environments/environment'; @Injectable({ providedIn: 'root' @@ -45,6 +46,12 @@ export class AuthService { } setLogin(username: string, token: string, domain?: string) { + // When using a local environment, we don't want the domain set as we could be connected to a live running server + // on it's domain. This causes issues with cookies, so we don't set a domain when running locally. + if (environment.type === 'local') { + domain = undefined; + } + localStorage.setItem('auth-token', token); localStorage.setItem('auth-username', username); if (domain) { diff --git a/src/environments/environment.local.ts b/src/environments/environment.local.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/src/environments/environment.prod.ts b/src/environments/environment.prod.ts index cb307934..feae7756 100644 --- a/src/environments/environment.prod.ts +++ b/src/environments/environment.prod.ts @@ -1,6 +1,7 @@ export const environment = { production: true, + type: 'production', baseUrl: '', baseWsUrl: '', - version: "1.0.0" + version: '1.0.0' }; diff --git a/src/environments/environment.ts b/src/environments/environment.ts index e94073d6..f178b676 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -4,9 +4,10 @@ export const environment = { production: false, + type: 'local', baseUrl: 'http://localhost:8888', baseWsUrl: 'ws://localhost:8888', - version: "1.0.0" + version: 'development' }; /* @@ -16,4 +17,4 @@ export const environment = { * This import should be commented out in production mode because it will have a negative impact * on performance if an error is thrown. */ -// import 'zone.js/dist/zone-error'; // Included with Angular CLI. +import 'zone.js/dist/zone-error'; // Included with Angular CLI. From 20600a207b756b6f3cdf7f150d816801c0de6907 Mon Sep 17 00:00:00 2001 From: Andrey Melnikov Date: Wed, 28 Oct 2020 13:33:30 -0700 Subject: [PATCH 2/4] chore: code formatting - login component --- src/app/auth/login/login.component.ts | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/app/auth/login/login.component.ts b/src/app/auth/login/login.component.ts index 7b516bdc..3022dea8 100644 --- a/src/app/auth/login/login.component.ts +++ b/src/app/auth/login/login.component.ts @@ -72,22 +72,22 @@ export class LoginComponent implements OnInit { token: this.tokenInput.value, username: this.usernameInput.value }).subscribe(res => { - this.authService.setLogin(this.usernameInput.value, res.token, res.domain); + this.authService.setLogin(this.usernameInput.value, res.token, res.domain); - this.namespaceTracker.getNamespaces(); + this.namespaceTracker.getNamespaces(); - if (this.authService.redirectUrl) { - this.appRouter.navigateByUrl(this.authService.redirectUrl); - this.authService.redirectUrl = null; - this.loggingIn = false; - return; - } - - this.appRouter.navigateToHomePage(); - this.loggingIn = false; - }, err => { - this.tokenInput.setErrors({error: 'Invalid token'}); + if (this.authService.redirectUrl) { + this.appRouter.navigateByUrl(this.authService.redirectUrl); + this.authService.redirectUrl = null; this.loggingIn = false; - }); + return; + } + + this.appRouter.navigateToHomePage(); + this.loggingIn = false; + }, err => { + this.tokenInput.setErrors({error: 'Invalid token'}); + this.loggingIn = false; + }); } } From ee2a4ad5312baffbdaf7edfb82eb90020273d854 Mon Sep 17 00:00:00 2001 From: Andrey Melnikov Date: Wed, 28 Oct 2020 13:34:04 -0700 Subject: [PATCH 3/4] fix: issue where version wasn't being properly displayed --- Makefile | 2 +- src/app/app.component.html | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 993d2b35..d7b698fc 100644 --- a/Makefile +++ b/Makefile @@ -31,7 +31,7 @@ docker-push: docker push onepanel/core-ui:$(COMMIT_HASH) docker-custom: - docker build -t onepanel-core-ui . + docker build -t onepanel-core-ui . --build-arg VERSION=$(VERSION) docker tag onepanel-core-ui:latest onepanel/core-ui:$(TAG) docker push onepanel/core-ui:$(TAG) diff --git a/src/app/app.component.html b/src/app/app.component.html index f07ecba2..f291e16c 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -1,5 +1,6 @@ From 30275fa86198db22b577f8a519617d5f3a64d1c1 Mon Sep 17 00:00:00 2001 From: Andrey Melnikov Date: Wed, 28 Oct 2020 13:34:17 -0700 Subject: [PATCH 4/4] chore: minor code cleanup for angular.json file --- angular.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/angular.json b/angular.json index 7953af59..6947eb72 100644 --- a/angular.json +++ b/angular.json @@ -76,7 +76,7 @@ "browserTarget": "onepanel-core-ui:build:production" }, "local": { - "browserTarget": "onepanel-core-ui:build:local", + "browserTarget": "onepanel-core-ui:build:local" } } },