ing
This commit is contained in:
parent
dfd124f62c
commit
7bf2087484
|
@ -8,10 +8,10 @@ import {
|
|||
import { Store } from '@ngrx/store';
|
||||
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/operator/catch';
|
||||
import 'rxjs/add/operator/take';
|
||||
import 'rxjs/add/operator/map';
|
||||
import { of } from 'rxjs/observable/of';
|
||||
|
||||
import { CookieService } from 'ngx-cookie-service';
|
||||
|
||||
import * as AuthStore from 'packages/member/store/auth';
|
||||
import { AuthSelector } from 'packages/member/store';
|
||||
|
@ -19,7 +19,8 @@ import { AuthSelector } from 'packages/member/store';
|
|||
@Injectable()
|
||||
export class AuthGuard implements CanActivate, CanActivateChild {
|
||||
constructor(
|
||||
private store: Store<AuthStore.State>
|
||||
private store: Store<AuthStore.State>,
|
||||
private cookieService: CookieService,
|
||||
) { }
|
||||
|
||||
canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> {
|
||||
|
@ -27,7 +28,11 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
|||
.select(AuthSelector.select('signined'))
|
||||
.map(signined => {
|
||||
if (!signined) {
|
||||
if (this.cookieService.check('authToken')) {
|
||||
this.store.dispatch(new AuthStore.SigninCookie({authToken: this.cookieService.get('authToken'), returnURL: state.url}));
|
||||
} else {
|
||||
this.store.dispatch(new AuthStore.SigninRedirect(state.url));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -47,10 +52,6 @@ export class AuthGuard implements CanActivate, CanActivateChild {
|
|||
|
||||
return true;
|
||||
})
|
||||
.catch(() => {
|
||||
this.store.dispatch(new AuthStore.SigninRedirect(state.url));
|
||||
return of(false);
|
||||
})
|
||||
.take(1);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user