|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, UrlTree } from '@angular/router';
|
|
|
|
|
import { ActivatedRouteSnapshot, CanActivate, RouterStateSnapshot, UrlTree, Router } from '@angular/router';
|
|
|
|
|
import { Store } from '@ngxs/store';
|
|
|
|
|
import { OAuthService } from 'angular-oauth2-oidc';
|
|
|
|
|
import { Observable } from 'rxjs';
|
|
|
|
@ -9,15 +9,14 @@ import { Navigate } from '@ngxs/router-plugin';
|
|
|
|
|
providedIn: 'root',
|
|
|
|
|
})
|
|
|
|
|
export class AuthGuard implements CanActivate {
|
|
|
|
|
constructor(private oauthService: OAuthService, private store: Store) {}
|
|
|
|
|
constructor(private oauthService: OAuthService, private store: Store, private router: Router) {}
|
|
|
|
|
|
|
|
|
|
canActivate(_: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean | UrlTree {
|
|
|
|
|
const hasValidAccessToken = this.oauthService.hasValidAccessToken();
|
|
|
|
|
if (hasValidAccessToken) {
|
|
|
|
|
return hasValidAccessToken;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.store.dispatch(new Navigate(['/account/login'], null, { state: { redirectUrl: state.url } }));
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
return this.router.createUrlTree(['/account/login'], { state: { redirectUrl: state.url } });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|