mirror of https://github.com/abpframework/abp.git
3 changed files with 10 additions and 105 deletions
@ -1,32 +1,22 @@ |
|||
import { Injectable, Injector } from '@angular/core'; |
|||
import { |
|||
ActivatedRouteSnapshot, |
|||
CanActivate, |
|||
Router, |
|||
RouterStateSnapshot, |
|||
UrlTree, |
|||
} from '@angular/router'; |
|||
import { Injectable } from '@angular/core'; |
|||
import { CanActivate, UrlTree } from '@angular/router'; |
|||
import { OAuthService } from 'angular-oauth2-oidc'; |
|||
import { Observable } from 'rxjs'; |
|||
import { AuthService } from '../services/auth.service'; |
|||
|
|||
@Injectable({ |
|||
providedIn: 'root', |
|||
}) |
|||
export class AuthGuard implements CanActivate { |
|||
constructor(private oauthService: OAuthService, private injector: Injector) {} |
|||
|
|||
canActivate( |
|||
_: ActivatedRouteSnapshot, |
|||
state: RouterStateSnapshot, |
|||
): Observable<boolean> | boolean | UrlTree { |
|||
const router = this.injector.get(Router); |
|||
constructor(private oauthService: OAuthService, private authService: AuthService) {} |
|||
|
|||
canActivate(): Observable<boolean> | boolean | UrlTree { |
|||
const hasValidAccessToken = this.oauthService.hasValidAccessToken(); |
|||
if (hasValidAccessToken) { |
|||
return hasValidAccessToken; |
|||
} |
|||
|
|||
router.navigate(['/account/login'], { state: { redirectUrl: state.url } }); |
|||
this.authService.initLogin(); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
Loading…
Reference in new issue