Added redirect after logout

This commit is contained in:
Giuseppe Digilio
2018-04-04 10:59:08 +02:00
parent b9e0d6f18a
commit 5fc6d4ead8
2 changed files with 8 additions and 11 deletions

View File

@@ -129,7 +129,7 @@ export class AuthEffects {
public logOutSuccess: Observable<Action> = this.actions$
.ofType(AuthActionTypes.LOG_OUT_SUCCESS)
.do(() => this.authService.removeToken())
.do(() => this.authService.refreshPage());
.do(() => this.authService.refreshAfterLogout());
@Effect({dispatch: false})
public redirectToLogin: Observable<Action> = this.actions$

View File

@@ -1,4 +1,4 @@
import { Injectable } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { NavigationExtras, PRIMARY_OUTLET, Router, UrlSegmentGroup, UrlTree } from '@angular/router';
import { Observable } from 'rxjs/Observable';
@@ -18,6 +18,7 @@ import { Store } from '@ngrx/store';
import { ResetAuthenticationMessagesAction, SetRedirectUrlAction } from './auth.actions';
import { RouterReducerState } from '@ngrx/router-store';
import { CookieAttributes } from 'js-cookie';
import { NativeWindowRef, NativeWindowService } from '../../shared/services/window.service';
export const LOGIN_ROUTE = '/login';
@@ -33,7 +34,8 @@ export class AuthService {
*/
private _authenticated: boolean;
constructor(private authRequestService: AuthRequestService,
constructor(@Inject(NativeWindowService) private _window: NativeWindowRef,
private authRequestService: AuthRequestService,
private router: Router,
private storage: CookieService,
private store: Store<AppState>) {
@@ -290,14 +292,9 @@ export class AuthService {
/**
* Refresh route navigated
*/
public refreshPage() {
this.store.select(routerStateSelector)
.take(1)
.subscribe((router) => {
// TODO Check a way to hard refresh the same route
// this.router.navigate([router.state.url], { replaceUrl: true });
this.router.navigate(['/']);
})
public refreshAfterLogout() {
// Hard redirect to home page, so that all state is definitely lost
this._window.nativeWindow.location.href = '/home';
}
/**