From 0c727af9ed3461d67a268bac79bc0d7c1107300b Mon Sep 17 00:00:00 2001 From: AkinCam <172804016@ogr.cbu.edu.tr> Date: Fri, 31 Jan 2020 15:31:48 +0300 Subject: [PATCH 1/2] Added logout in authService --- .../core/src/lib/services/auth.service.ts | 14 +++++++ .../application-layout.component.ts | 42 ++++++++++++------- 2 files changed, 41 insertions(+), 15 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/services/auth.service.ts b/npm/ng-packs/packages/core/src/lib/services/auth.service.ts index 0fc69f62ff..5ae13a4012 100644 --- a/npm/ng-packs/packages/core/src/lib/services/auth.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/auth.service.ts @@ -48,4 +48,18 @@ export class AuthService { take(1), ); } + + logout(): Observable { + return this.rest + .request({ + method: 'GET', + url: '/api/account/logout', + }) + .pipe( + switchMap(() => { + this.oAuthService.logOut(); + return this.store.dispatch(new GetAppConfiguration()); + }), + ); + } } diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts index 78c358ca69..c4a05f01f3 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts @@ -33,6 +33,7 @@ import snq from 'snq'; import { AddNavigationElement } from '../../actions'; import { Layout } from '../../models/layout'; import { LayoutState } from '../../states'; +import { AuthService } from 'packages/core/src/lib/services/auth.service'; @Component({ selector: 'abp-layout-application', @@ -78,7 +79,10 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy { get defaultLanguage$(): Observable { return this.languages$.pipe( map( - languages => snq(() => languages.find(lang => lang.cultureName === this.selectedLangCulture).displayName), + languages => + snq( + () => languages.find(lang => lang.cultureName === this.selectedLangCulture).displayName, + ), '', ), ); @@ -86,7 +90,11 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy { get dropdownLanguages$(): Observable { return this.languages$.pipe( - map(languages => snq(() => languages.filter(lang => lang.cultureName !== this.selectedLangCulture)), []), + map( + languages => + snq(() => languages.filter(lang => lang.cultureName !== this.selectedLangCulture)), + [], + ), ); } @@ -100,7 +108,12 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy { trackElementByFn: TrackByFunction = (_, element) => element; - constructor(private store: Store, private oauthService: OAuthService, private renderer: Renderer2) {} + constructor( + private store: Store, + private oauthService: OAuthService, + private renderer: Renderer2, + private authService: AuthService, + ) {} private checkWindowWidth() { setTimeout(() => { @@ -121,7 +134,9 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy { } ngAfterViewInit() { - const navigations = this.store.selectSnapshot(LayoutState.getNavigationElements).map(({ name }) => name); + const navigations = this.store + .selectSnapshot(LayoutState.getNavigationElements) + .map(({ name }) => name); if (navigations.indexOf('LanguageRef') < 0) { this.store.dispatch( @@ -145,10 +160,7 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy { this.checkWindowWidth(); fromEvent(window, 'resize') - .pipe( - takeUntilDestroy(this), - debounceTime(150), - ) + .pipe(takeUntilDestroy(this), debounceTime(150)) .subscribe(() => { this.checkWindowWidth(); }); @@ -161,13 +173,13 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy { } logout() { - this.oauthService.logOut(); - this.store.dispatch( - new Navigate(['/'], null, { - state: { redirectUrl: this.store.selectSnapshot(RouterState).state.url }, - }), - ); - this.store.dispatch(new GetAppConfiguration()); + this.authService.logout().subscribe(() => { + this.store.dispatch( + new Navigate(['/'], null, { + state: { redirectUrl: this.store.selectSnapshot(RouterState).state.url }, + }), + ); + }); } openChange(event: boolean, childrenContainer: HTMLDivElement) { From b1934b4102780b735264a5d398df087356e6f603 Mon Sep 17 00:00:00 2001 From: AkinCam <172804016@ogr.cbu.edu.tr> Date: Mon, 3 Feb 2020 09:22:58 +0300 Subject: [PATCH 2/2] Removed OauthService in application-layout --- .../application-layout/application-layout.component.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts index c4a05f01f3..06f67c8e87 100644 --- a/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts +++ b/npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts @@ -25,7 +25,6 @@ import { import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'; import { Navigate, RouterState } from '@ngxs/router-plugin'; import { Select, Store } from '@ngxs/store'; -import { OAuthService } from 'angular-oauth2-oidc'; import compare from 'just-compare'; import { fromEvent, Observable } from 'rxjs'; import { debounceTime, filter, map } from 'rxjs/operators'; @@ -110,7 +109,6 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy { constructor( private store: Store, - private oauthService: OAuthService, private renderer: Renderer2, private authService: AuthService, ) {}