From f8112cbd1bdb20df9911adbd0760e9a4b6e590e4 Mon Sep 17 00:00:00 2001 From: christophercr Date: Mon, 8 Oct 2018 17:47:48 +0200 Subject: [PATCH] feat(stark-core): allow customizing Login and Preloading states via the StarkSessionConfig ISSUES CLOSED: #727 --- package-lock.json | 160 +++++++++--------- .../entities/session-config.entity.intf.ts | 28 ++- .../session/services/session.service.spec.ts | 7 +- .../session/services/session.service.ts | 13 +- .../src/modules/session/session.module.ts | 36 +++- .../components/app-footer.component.spec.ts | 2 +- .../components/app-logout.component.spec.ts | 2 +- .../components/app-logout.component.ts | 17 +- .../components/app-menu-item.component.ts | 12 +- .../components/app-container.component.html | 6 +- .../components/app-container.component.ts | 15 +- .../src/modules/session-ui/pages/login.ts | 2 +- .../pages/login/_login-page.component.scss | 46 ++--- .../_preloading-page.component.scss | 8 +- .../_session-expired-page.component.scss | 16 +- .../_session-logout-page.component.scss | 8 +- .../modules/session-ui/session-ui.module.ts | 61 +++++-- 17 files changed, 260 insertions(+), 179 deletions(-) diff --git a/package-lock.json b/package-lock.json index 649dc9fddf..ad3481c18d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -543,18 +543,18 @@ "integrity": "sha512-PUHWGoQOx8m6ZSpZPSHb+YISFAvW7jiWvCJOQiViKHZC8CLKu4bjyc/AwP8gBte0RsTGAu1ekiitp5Q0NcLGcA==", "dev": true, "requires": { - "@commitlint/format": "^7.2.1", - "@commitlint/lint": "^7.2.1", - "@commitlint/load": "^7.2.1", - "@commitlint/read": "^7.1.2", + "@commitlint/format": "7.2.1", + "@commitlint/lint": "7.2.1", + "@commitlint/load": "7.2.1", + "@commitlint/read": "7.1.2", "babel-polyfill": "6.26.0", "chalk": "2.3.1", "get-stdin": "5.0.1", "lodash.merge": "4.6.1", "lodash.pick": "4.4.0", "meow": "5.0.0", - "resolve-from": "^4.0.0", - "resolve-global": "^0.1.0" + "resolve-from": "4.0.0", + "resolve-global": "0.1.0" } }, "@commitlint/config-conventional": { @@ -591,8 +591,8 @@ "integrity": "sha512-1YcL+ZWB8V52oDFQBhSBJjiJOZDt4Vl06O5TkG70BMpre3EQru5KYIN16eEPqfihNw0bj8gSIWcf87Gvh3OrOw==", "dev": true, "requires": { - "babel-runtime": "^6.23.0", - "chalk": "^2.0.1" + "babel-runtime": "6.26.0", + "chalk": "2.3.1" } }, "@commitlint/is-ignored": { @@ -618,10 +618,10 @@ "integrity": "sha512-rM7nUyNUJyuKw1MTwJG/wk4twB5YCAG2wzJMn5NqVpGD/qmLOzlZoBl0+CYmuOsbIRAA2rlEV6KZHBk9tTfAdQ==", "dev": true, "requires": { - "@commitlint/is-ignored": "^7.2.1", - "@commitlint/parse": "^7.1.2", - "@commitlint/rules": "^7.2.0", - "babel-runtime": "^6.23.0", + "@commitlint/is-ignored": "7.2.1", + "@commitlint/parse": "7.1.2", + "@commitlint/rules": "7.2.0", + "babel-runtime": "6.26.0", "lodash.topairs": "4.3.0" } }, @@ -631,10 +631,10 @@ "integrity": "sha512-FnfmfhPGJqGwILVRznduBejOicNey6p/byfcyxtcBkN2+X96gDuNtqcnGcngCrzPIAgaIrQQcTQDA1/KMtW21A==", "dev": true, "requires": { - "@commitlint/execute-rule": "^7.1.2", - "@commitlint/resolve-extends": "^7.1.2", - "babel-runtime": "^6.23.0", - "cosmiconfig": "^4.0.0", + "@commitlint/execute-rule": "7.1.2", + "@commitlint/resolve-extends": "7.1.2", + "babel-runtime": "6.26.0", + "cosmiconfig": "4.0.0", "lodash.merge": "4.6.1", "lodash.mergewith": "4.6.1", "lodash.pick": "4.4.0", @@ -654,8 +654,8 @@ "integrity": "sha512-wrdLwJZL3cs89MfgPtnbbKByijUo3Wrug55aTke5k/F0XNxGaDaNJyH4QXgidgXk57r2t4NJVAKwjnY4wjfNwg==", "dev": true, "requires": { - "conventional-changelog-angular": "^1.3.3", - "conventional-commits-parser": "^2.1.0" + "conventional-changelog-angular": "1.6.6", + "conventional-commits-parser": "2.1.7" } }, "@commitlint/read": { @@ -664,10 +664,10 @@ "integrity": "sha512-sarYQgfTay2Eu7onHz53EYyRw7pI5QmLE7tP5Ri9op6eu4LadjSoA/4dfc+VE7avsq21J2ewSbz+9f0uvhDxgg==", "dev": true, "requires": { - "@commitlint/top-level": "^7.1.2", - "@marionebl/sander": "^0.6.0", - "babel-runtime": "^6.23.0", - "git-raw-commits": "^1.3.0" + "@commitlint/top-level": "7.1.2", + "@marionebl/sander": "0.6.1", + "babel-runtime": "6.26.0", + "git-raw-commits": "1.3.6" } }, "@commitlint/resolve-extends": { @@ -679,9 +679,9 @@ "babel-runtime": "6.26.0", "lodash.merge": "4.6.1", "lodash.omit": "4.5.0", - "require-uncached": "^1.0.3", - "resolve-from": "^4.0.0", - "resolve-global": "^0.1.0" + "require-uncached": "1.0.3", + "resolve-from": "4.0.0", + "resolve-global": "0.1.0" } }, "@commitlint/rules": { @@ -690,10 +690,10 @@ "integrity": "sha512-c15Q9H5iYE9fnncLnFnMuvPLYA/i0pve5moV0uxJJGr4GgJoBKyldd4CCDhoE80C1k8ABuqr2o2qsopzVEp3Ww==", "dev": true, "requires": { - "@commitlint/ensure": "^7.2.0", - "@commitlint/message": "^7.1.2", - "@commitlint/to-lines": "^7.1.2", - "babel-runtime": "^6.23.0" + "@commitlint/ensure": "7.2.0", + "@commitlint/message": "7.1.2", + "@commitlint/to-lines": "7.1.2", + "babel-runtime": "6.26.0" } }, "@commitlint/to-lines": { @@ -708,7 +708,7 @@ "integrity": "sha512-YKugOAKy3hgM/ITezPp7Ns51U3xoJfuOsVnMGW4oDcHLhuQ/Qd58ROv/Hgedtk8HugKX3DdZ8XoEnRG70RDGqQ==", "dev": true, "requires": { - "find-up": "^2.1.0" + "find-up": "2.1.0" } }, "@compodoc/compodoc": { @@ -837,9 +837,9 @@ "integrity": "sha1-GViWWHTyS8Ub5Ih1/rUNZC/EH3s=", "dev": true, "requires": { - "graceful-fs": "^4.1.3", - "mkdirp": "^0.5.1", - "rimraf": "^2.5.2" + "graceful-fs": "4.1.11", + "mkdirp": "0.5.1", + "rimraf": "2.6.2" } }, "@mrmlnc/readdir-enhanced": { @@ -1876,9 +1876,9 @@ "integrity": "sha1-N5k3q8Z9eJWXCtxiHyhM2WbPIVM=", "dev": true, "requires": { - "babel-runtime": "^6.26.0", - "core-js": "^2.5.0", - "regenerator-runtime": "^0.10.5" + "babel-runtime": "6.26.0", + "core-js": "2.5.7", + "regenerator-runtime": "0.10.5" }, "dependencies": { "regenerator-runtime": { @@ -2281,7 +2281,7 @@ "integrity": "sha1-lAhe9jWB7NPaqSREqP6U6CV3dR8=", "dev": true, "requires": { - "callsites": "^0.2.0" + "callsites": "0.2.0" } }, "callsites": { @@ -3129,13 +3129,13 @@ "integrity": "sha512-BoMaddIEJ6B4QVMSDu9IkVImlGOSGA1I2BQyOZHeLQ6qVOJLcLKn97+fL6dGbzWEiqDzfH4OkcveULmeq2MHFQ==", "dev": true, "requires": { - "JSONStream": "^1.0.4", - "is-text-path": "^1.0.0", - "lodash": "^4.2.1", - "meow": "^4.0.0", - "split2": "^2.0.0", - "through2": "^2.0.0", - "trim-off-newlines": "^1.0.0" + "JSONStream": "1.3.4", + "is-text-path": "1.0.1", + "lodash": "4.17.11", + "meow": "4.0.1", + "split2": "2.2.0", + "through2": "2.0.3", + "trim-off-newlines": "1.0.1" }, "dependencies": { "meow": { @@ -3144,15 +3144,15 @@ "integrity": "sha512-xcSBHD5Z86zaOc+781KrupuHAzeGXSLtiAOmBsiLDiPSaYSB6hdew2ng9EBAnZ62jagG9MHAOdxpDi/lWBFJ/A==", "dev": true, "requires": { - "camelcase-keys": "^4.0.0", - "decamelize-keys": "^1.0.0", - "loud-rejection": "^1.0.0", - "minimist": "^1.1.3", - "minimist-options": "^3.0.1", - "normalize-package-data": "^2.3.4", - "read-pkg-up": "^3.0.0", - "redent": "^2.0.0", - "trim-newlines": "^2.0.0" + "camelcase-keys": "4.2.0", + "decamelize-keys": "1.1.0", + "loud-rejection": "1.6.0", + "minimist": "1.2.0", + "minimist-options": "3.0.2", + "normalize-package-data": "2.4.0", + "read-pkg-up": "3.0.0", + "redent": "2.0.0", + "trim-newlines": "2.0.0" } } } @@ -3263,10 +3263,10 @@ "integrity": "sha512-6e5vDdrXZD+t5v0L8CrurPeybg4Fmf+FCSYxXKYVAqLUtyCSbuyqE059d0kDthTNRzKVjL7QMgNpEUlsoYH3iQ==", "dev": true, "requires": { - "is-directory": "^0.3.1", - "js-yaml": "^3.9.0", - "parse-json": "^4.0.0", - "require-from-string": "^2.0.1" + "is-directory": "0.3.1", + "js-yaml": "3.12.0", + "parse-json": "4.0.0", + "require-from-string": "2.0.2" } }, "cp-file": { @@ -4871,11 +4871,11 @@ "integrity": "sha512-svsK26tQ8vEKnMshTDatSIQSMDdz8CxIIqKsvPqbtV23Etmw6VNaFAitu8zwZ0VrOne7FztwPyRLxK7/DIUTQg==", "dev": true, "requires": { - "dargs": "^4.0.1", - "lodash.template": "^4.0.2", - "meow": "^4.0.0", - "split2": "^2.0.0", - "through2": "^2.0.0" + "dargs": "4.1.0", + "lodash.template": "4.4.0", + "meow": "4.0.1", + "split2": "2.2.0", + "through2": "2.0.3" }, "dependencies": { "meow": { @@ -4884,15 +4884,15 @@ "integrity": "sha512-xcSBHD5Z86zaOc+781KrupuHAzeGXSLtiAOmBsiLDiPSaYSB6hdew2ng9EBAnZ62jagG9MHAOdxpDi/lWBFJ/A==", "dev": true, "requires": { - "camelcase-keys": "^4.0.0", - "decamelize-keys": "^1.0.0", - "loud-rejection": "^1.0.0", - "minimist": "^1.1.3", - "minimist-options": "^3.0.1", - "normalize-package-data": "^2.3.4", - "read-pkg-up": "^3.0.0", - "redent": "^2.0.0", - "trim-newlines": "^2.0.0" + "camelcase-keys": "4.2.0", + "decamelize-keys": "1.1.0", + "loud-rejection": "1.6.0", + "minimist": "1.2.0", + "minimist-options": "3.0.2", + "normalize-package-data": "2.4.0", + "read-pkg-up": "3.0.0", + "redent": "2.0.0", + "trim-newlines": "2.0.0" } } } @@ -6813,7 +6813,7 @@ "integrity": "sha512-sCuTz6pYom8Rlt4ISPFn6wuFodbKMIHUMv4Qko9P17dpxb7s52KJTmRuZZqHdGmLCK9AOcDare039nRIcfdkEg==", "dev": true, "requires": { - "sourcemap-codec": "^1.4.1" + "sourcemap-codec": "1.4.3" } }, "make-dir": { @@ -8519,8 +8519,8 @@ "integrity": "sha1-Tg1W1slmL9MeQwEcS5WqSZVUIdM=", "dev": true, "requires": { - "caller-path": "^0.1.0", - "resolve-from": "^1.0.0" + "caller-path": "0.1.0", + "resolve-from": "1.0.1" }, "dependencies": { "resolve-from": { @@ -8562,7 +8562,7 @@ "integrity": "sha1-j7As/Vt9sgEY6IYxHxWvlb0V+9k=", "dev": true, "requires": { - "global-dirs": "^0.1.0" + "global-dirs": "0.1.1" } }, "resolve-url": { @@ -8624,7 +8624,7 @@ "dev": true, "requires": { "@types/estree": "0.0.39", - "@types/node": "*" + "@types/node": "10.11.4" } }, "rollup-plugin-commonjs": { @@ -8633,10 +8633,10 @@ "integrity": "sha512-0RM5U4Vd6iHjL6rLvr3lKBwnPsaVml+qxOGaaNUWN1lSq6S33KhITOfHmvxV3z2vy9Mk4t0g4rNlVaJJsNQPWA==", "dev": true, "requires": { - "estree-walker": "^0.5.2", - "magic-string": "^0.25.1", - "resolve": "^1.8.1", - "rollup-pluginutils": "^2.3.3" + "estree-walker": "0.5.2", + "magic-string": "0.25.1", + "resolve": "1.8.1", + "rollup-pluginutils": "2.3.3" } }, "rollup-plugin-node-resolve": { diff --git a/packages/stark-core/src/modules/session/entities/session-config.entity.intf.ts b/packages/stark-core/src/modules/session/entities/session-config.entity.intf.ts index 069bb6e204..2d783de142 100644 --- a/packages/stark-core/src/modules/session/entities/session-config.entity.intf.ts +++ b/packages/stark-core/src/modules/session/entities/session-config.entity.intf.ts @@ -1,16 +1,36 @@ -import {InjectionToken} from "@angular/core"; +import { InjectionToken } from "@angular/core"; /** * The InjectionToken version of the config name */ -export const STARK_SESSION_CONFIG: InjectionToken = new InjectionToken< - StarkSessionConfig - >("StarkSessionConfig"); +export const STARK_SESSION_CONFIG: InjectionToken = new InjectionToken("StarkSessionConfig"); /** * Definition of the configuration object for the Stark Session service */ export interface StarkSessionConfig { + /** + * Router state for the Login page where the user can choose a profile and use it to impersonate himself as someone else. + * This state is only used in DEVELOPMENT. + */ + loginStateName?: string; + + /** + * Router state for the Preloading page where the user profile is fetched and used to automatically log the user in. + * This state is only used in PRODUCTION. + */ + preloadingStateName?: string; + + /** + * Router state for the Session Expired page to be shown when the user has been automatically logged out. + * Such automatic logout occurs when the timeout of the session expiration timer (triggered due to user inactivity) is reached. + * This state is used in PRODUCTION and DEVELOPMENT. + */ sessionExpiredStateName?: string; + + /** + * Router state for the Session Logout Page that will be shown when the user intentionally logs out from the application. + * This state is used in PRODUCTION and DEVELOPMENT. + */ sessionLogoutStateName?: string; } diff --git a/packages/stark-core/src/modules/session/services/session.service.spec.ts b/packages/stark-core/src/modules/session/services/session.service.spec.ts index 6877285754..c3c5360f97 100644 --- a/packages/stark-core/src/modules/session/services/session.service.spec.ts +++ b/packages/stark-core/src/modules/session/services/session.service.spec.ts @@ -64,7 +64,7 @@ describe("Service: StarkSessionService", () => { roles: ["a role", "another role", "yet another role"] }; const mockSessionConfig: StarkSessionConfig = { - sessionExpiredStateName: "mock-session-state-name" + sessionExpiredStateName: "mock-session-expired-state-name" }; // Inject module dependencies @@ -503,7 +503,8 @@ describe("Service: StarkSessionService", () => { appConfig, mockIdleService, mockInjectorService, - mockTranslateService + mockTranslateService, + {} // default empty session config ); spyOn(sessionService, "logout"); @@ -884,7 +885,7 @@ class SessionServiceHelper extends StarkSessionServiceImpl { idle: Idle, injector: Injector, translateService: TranslateService, - sessionConfig?: StarkSessionConfig + sessionConfig: StarkSessionConfig ) { super(store, logger, routingService, appConfig, idle, injector, translateService, sessionConfig); } diff --git a/packages/stark-core/src/modules/session/services/session.service.ts b/packages/stark-core/src/modules/session/services/session.service.ts index 445823cdb0..0a3e657c46 100644 --- a/packages/stark-core/src/modules/session/services/session.service.ts +++ b/packages/stark-core/src/modules/session/services/session.service.ts @@ -1,6 +1,6 @@ /* tslint:disable:completed-docs*/ import { HttpHeaders, HttpRequest } from "@angular/common/http"; -import { Inject, Injectable, Injector } from "@angular/core"; +import { Inject, Injectable, Injector, Optional } from "@angular/core"; import { DEFAULT_INTERRUPTSOURCES, Idle } from "@ng-idle/core"; import { Keepalive } from "@ng-idle/keepalive"; import { TranslateService } from "@ngx-translate/core"; @@ -66,7 +66,9 @@ export class StarkSessionServiceImpl implements StarkSessionService { public idle: Idle, injector: Injector, public translateService: TranslateService, - @Inject(STARK_SESSION_CONFIG) private sessionConfig?: StarkSessionConfig + @Optional() + @Inject(STARK_SESSION_CONFIG) + private sessionConfig?: StarkSessionConfig ) { // ensuring that the app config is valid before doing anything StarkConfigurationUtil.validateConfig(this.appConfig, ["session"], starkSessionServiceName); @@ -258,18 +260,17 @@ export class StarkSessionServiceImpl implements StarkSessionService { this.store.dispatch(new StarkSessionTimeoutCountdownFinish()); this.logout(); - let sessionExpiredStateName: string; + let sessionExpiredStateName: string = starkSessionExpiredStateName; if ( - typeof this.sessionConfig !== "undefined" && + this.sessionConfig && typeof this.sessionConfig.sessionExpiredStateName !== "undefined" && this.sessionConfig.sessionExpiredStateName !== "" ) { sessionExpiredStateName = this.sessionConfig.sessionExpiredStateName; - } else { - sessionExpiredStateName = starkSessionExpiredStateName; } this.routingService.navigateTo(sessionExpiredStateName); }); + this.idle.onTimeoutWarning.subscribe((countdown: number) => { if (countdown === this.idle.getTimeout()) { this.countdownStarted = true; diff --git a/packages/stark-core/src/modules/session/session.module.ts b/packages/stark-core/src/modules/session/session.module.ts index 6c879507d9..3c46a96d04 100644 --- a/packages/stark-core/src/modules/session/session.module.ts +++ b/packages/stark-core/src/modules/session/session.module.ts @@ -1,10 +1,40 @@ import { ModuleWithProviders, NgModule, Optional, SkipSelf } from "@angular/core"; +import { StoreModule } from "@ngrx/store"; import { starkSessionReducers } from "./reducers"; import { StarkSessionConfig, STARK_SESSION_CONFIG } from "./entities"; import { STARK_SESSION_SERVICE, StarkSessionServiceImpl } from "./services"; -import { StoreModule } from "@ngrx/store"; - import { StarkUserModule } from "../user/user.module"; +import { starkAppExitStateName, starkAppInitStateName } from "./routes"; + +/** + * Validates and creates the StarkSessionConfig to be provided for the Stark Session Service + * @param customConfig - Custom configuration object passed via the StarkSessionModule.forRoot() method + * @returns The StarkSessionConfig to be provided for the Stark Session Service. + * @throws In case the configuration object passed via the StarkSessionModule.forRoot() method is not valid + */ +export function starkSessionConfigFactory(customConfig: StarkSessionConfig): StarkSessionConfig { + const invalidConfigErrorPrefix: string = "StarkSessionModule: invalid StarkSessionConfig object. "; + const invalidConfigErrorAppInitSuffix: string = + " should have the prefix '" + starkAppInitStateName + ".' in order to be configured correctly as an application initial state"; + const invalidConfigErrorAppExitSuffix: string = + " should have the prefix '" + starkAppExitStateName + ".' in order to be configured correctly as an application exit state"; + + // validate config to ensure that the init/exit states have the correct StarkAppInit or StarkAppExit parent + if (customConfig.loginStateName && !customConfig.loginStateName.startsWith(starkAppInitStateName)) { + throw new Error(invalidConfigErrorPrefix + "'loginStateName' value" + invalidConfigErrorAppInitSuffix); + } + if (customConfig.preloadingStateName && !customConfig.preloadingStateName.startsWith(starkAppInitStateName)) { + throw new Error(invalidConfigErrorPrefix + "'preloadingStateName' value" + invalidConfigErrorAppInitSuffix); + } + if (customConfig.sessionExpiredStateName && !customConfig.sessionExpiredStateName.startsWith(starkAppExitStateName)) { + throw new Error(invalidConfigErrorPrefix + "'sessionExpiredStateName' value" + invalidConfigErrorAppExitSuffix); + } + if (customConfig.sessionLogoutStateName && !customConfig.sessionLogoutStateName.startsWith(starkAppExitStateName)) { + throw new Error(invalidConfigErrorPrefix + "'sessionLogoutStateName' value" + invalidConfigErrorAppExitSuffix); + } + + return customConfig; +} @NgModule({ imports: [StoreModule.forFeature("StarkSession", starkSessionReducers), StarkUserModule] @@ -22,7 +52,7 @@ export class StarkSessionModule { ngModule: StarkSessionModule, providers: [ { provide: STARK_SESSION_SERVICE, useClass: StarkSessionServiceImpl }, - { provide: STARK_SESSION_CONFIG, useValue: sessionConfig } + sessionConfig ? { provide: STARK_SESSION_CONFIG, useValue: starkSessionConfigFactory(sessionConfig) } : [] ] }; } diff --git a/packages/stark-ui/src/modules/app-footer/components/app-footer.component.spec.ts b/packages/stark-ui/src/modules/app-footer/components/app-footer.component.spec.ts index bd69a73bda..28773d196b 100644 --- a/packages/stark-ui/src/modules/app-footer/components/app-footer.component.spec.ts +++ b/packages/stark-ui/src/modules/app-footer/components/app-footer.component.spec.ts @@ -5,7 +5,7 @@ import { MockStarkLoggingService } from "@nationalbankbelgium/stark-core/testing import { StarkAppFooterComponent } from "./app-footer.component"; import { TranslateModule, TranslateService } from "@ngx-translate/core"; -describe("AppLogoutComponent", () => { +describe("AppFooterComponent", () => { let component: StarkAppFooterComponent; let fixture: ComponentFixture; diff --git a/packages/stark-ui/src/modules/app-logout/components/app-logout.component.spec.ts b/packages/stark-ui/src/modules/app-logout/components/app-logout.component.spec.ts index 5e06932d85..2db28e9f74 100644 --- a/packages/stark-ui/src/modules/app-logout/components/app-logout.component.spec.ts +++ b/packages/stark-ui/src/modules/app-logout/components/app-logout.component.spec.ts @@ -90,7 +90,7 @@ describe("AppLogoutComponent", () => { }); it("should log out the user and navigate to starkSessionLogoutStateName", () => { - component.sessionConfig.sessionLogoutStateName = undefined; + (component.sessionConfig).sessionLogoutStateName = undefined; (component.routingService.navigateTo).calls.reset(); component.logout(); diff --git a/packages/stark-ui/src/modules/app-logout/components/app-logout.component.ts b/packages/stark-ui/src/modules/app-logout/components/app-logout.component.ts index 27978e03e0..322fb39136 100644 --- a/packages/stark-ui/src/modules/app-logout/components/app-logout.component.ts +++ b/packages/stark-ui/src/modules/app-logout/components/app-logout.component.ts @@ -1,4 +1,4 @@ -import { Component, ElementRef, Inject, Input, OnInit, Renderer2, ViewEncapsulation } from "@angular/core"; +import { Component, ElementRef, Inject, Input, OnInit, Optional, Renderer2, ViewEncapsulation } from "@angular/core"; import { STARK_LOGGING_SERVICE, @@ -50,9 +50,11 @@ export class StarkAppLogoutComponent extends AbstractStarkUiComponent implements @Inject(STARK_LOGGING_SERVICE) public logger: StarkLoggingService, @Inject(STARK_ROUTING_SERVICE) public routingService: StarkRoutingService, @Inject(STARK_SESSION_SERVICE) public sessionService: StarkSessionService, - @Inject(STARK_SESSION_CONFIG) public sessionConfig: StarkSessionConfig, protected renderer: Renderer2, - protected elementRef: ElementRef + protected elementRef: ElementRef, + @Optional() + @Inject(STARK_SESSION_CONFIG) + public sessionConfig?: StarkSessionConfig ) { super(renderer, elementRef); } @@ -69,14 +71,15 @@ export class StarkAppLogoutComponent extends AbstractStarkUiComponent implements */ public logout(): void { this.sessionService.logout(); + + let sessionLogoutStateName: string = starkSessionLogoutStateName; if ( - typeof this.sessionConfig !== "undefined" && + this.sessionConfig && typeof this.sessionConfig.sessionLogoutStateName !== "undefined" && this.sessionConfig.sessionLogoutStateName !== "" ) { - this.routingService.navigateTo(this.sessionConfig.sessionLogoutStateName); - } else { - this.routingService.navigateTo(starkSessionLogoutStateName); + sessionLogoutStateName = this.sessionConfig.sessionLogoutStateName; } + this.routingService.navigateTo(sessionLogoutStateName); } } diff --git a/packages/stark-ui/src/modules/app-menu/components/app-menu-item.component.ts b/packages/stark-ui/src/modules/app-menu/components/app-menu-item.component.ts index eab8681994..2e594b9e25 100644 --- a/packages/stark-ui/src/modules/app-menu/components/app-menu-item.component.ts +++ b/packages/stark-ui/src/modules/app-menu/components/app-menu-item.component.ts @@ -93,12 +93,12 @@ export class StarkAppMenuItemComponent extends AbstractStarkUiComponent implemen /** * Routing transition finish callback */ - private routingTransitionFinishCallback: Function; + private routingTransitionFinishCallback?: Function; /** * Routing transition success callback */ - private routingTransitionSuccessCallback: Function; + private routingTransitionSuccessCallback?: Function; /** * Class constructor @@ -143,8 +143,12 @@ export class StarkAppMenuItemComponent extends AbstractStarkUiComponent implemen * Component OnDestroy lifecycle hook */ public ngOnDestroy(): void { - this.routingTransitionFinishCallback(); - this.routingTransitionSuccessCallback(); + if (this.routingTransitionFinishCallback) { + this.routingTransitionFinishCallback(); + } + if (this.routingTransitionSuccessCallback) { + this.routingTransitionSuccessCallback(); + } } /** diff --git a/packages/stark-ui/src/modules/session-ui/components/app-container.component.html b/packages/stark-ui/src/modules/session-ui/components/app-container.component.html index 10dcf91661..b5a6276130 100644 --- a/packages/stark-ui/src/modules/session-ui/components/app-container.component.html +++ b/packages/stark-ui/src/modules/session-ui/components/app-container.component.html @@ -1,6 +1,6 @@ -