Browse Source

Added logout in authService

pull/2734/head
AkinCam 7 years ago
parent
commit
0c727af9ed
  1. 14
      npm/ng-packs/packages/core/src/lib/services/auth.service.ts
  2. 42
      npm/ng-packs/packages/theme-basic/src/lib/components/application-layout/application-layout.component.ts

14
npm/ng-packs/packages/core/src/lib/services/auth.service.ts

@ -48,4 +48,18 @@ export class AuthService {
take(1), take(1),
); );
} }
logout(): Observable<void> {
return this.rest
.request({
method: 'GET',
url: '/api/account/logout',
})
.pipe(
switchMap(() => {
this.oAuthService.logOut();
return this.store.dispatch(new GetAppConfiguration());
}),
);
}
} }

42
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 { AddNavigationElement } from '../../actions';
import { Layout } from '../../models/layout'; import { Layout } from '../../models/layout';
import { LayoutState } from '../../states'; import { LayoutState } from '../../states';
import { AuthService } from 'packages/core/src/lib/services/auth.service';
@Component({ @Component({
selector: 'abp-layout-application', selector: 'abp-layout-application',
@ -78,7 +79,10 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy {
get defaultLanguage$(): Observable<string> { get defaultLanguage$(): Observable<string> {
return this.languages$.pipe( return this.languages$.pipe(
map( 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<ApplicationConfiguration.Language[]> { get dropdownLanguages$(): Observable<ApplicationConfiguration.Language[]> {
return this.languages$.pipe( 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<ABP.FullRoute> = (_, element) => element; trackElementByFn: TrackByFunction<ABP.FullRoute> = (_, 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() { private checkWindowWidth() {
setTimeout(() => { setTimeout(() => {
@ -121,7 +134,9 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy {
} }
ngAfterViewInit() { 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) { if (navigations.indexOf('LanguageRef') < 0) {
this.store.dispatch( this.store.dispatch(
@ -145,10 +160,7 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy {
this.checkWindowWidth(); this.checkWindowWidth();
fromEvent(window, 'resize') fromEvent(window, 'resize')
.pipe( .pipe(takeUntilDestroy(this), debounceTime(150))
takeUntilDestroy(this),
debounceTime(150),
)
.subscribe(() => { .subscribe(() => {
this.checkWindowWidth(); this.checkWindowWidth();
}); });
@ -161,13 +173,13 @@ export class ApplicationLayoutComponent implements AfterViewInit, OnDestroy {
} }
logout() { logout() {
this.oauthService.logOut(); this.authService.logout().subscribe(() => {
this.store.dispatch( this.store.dispatch(
new Navigate(['/'], null, { new Navigate(['/'], null, {
state: { redirectUrl: this.store.selectSnapshot(RouterState).state.url }, state: { redirectUrl: this.store.selectSnapshot(RouterState).state.url },
}), }),
); );
this.store.dispatch(new GetAppConfiguration()); });
} }
openChange(event: boolean, childrenContainer: HTMLDivElement) { openChange(event: boolean, childrenContainer: HTMLDivElement) {

Loading…
Cancel
Save