diff --git a/src/app/commons/guard/auth.guard.ts b/src/app/commons/guard/auth.guard.ts index 23e4d3a..fd98d82 100644 --- a/src/app/commons/guard/auth.guard.ts +++ b/src/app/commons/guard/auth.guard.ts @@ -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 + private store: Store, + private cookieService: CookieService, ) { } canActivate(next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { @@ -27,7 +28,11 @@ export class AuthGuard implements CanActivate, CanActivateChild { .select(AuthSelector.select('signined')) .map(signined => { if (!signined) { - this.store.dispatch(new AuthStore.SigninRedirect(state.url)); + 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); } }