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 { Injectable } from '@angular/core'; |
||||
import { |
import { CanActivate, UrlTree } from '@angular/router'; |
||||
ActivatedRouteSnapshot, |
|
||||
CanActivate, |
|
||||
Router, |
|
||||
RouterStateSnapshot, |
|
||||
UrlTree, |
|
||||
} from '@angular/router'; |
|
||||
import { OAuthService } from 'angular-oauth2-oidc'; |
import { OAuthService } from 'angular-oauth2-oidc'; |
||||
import { Observable } from 'rxjs'; |
import { Observable } from 'rxjs'; |
||||
|
import { AuthService } from '../services/auth.service'; |
||||
|
|
||||
@Injectable({ |
@Injectable({ |
||||
providedIn: 'root', |
providedIn: 'root', |
||||
}) |
}) |
||||
export class AuthGuard implements CanActivate { |
export class AuthGuard implements CanActivate { |
||||
constructor(private oauthService: OAuthService, private injector: Injector) {} |
constructor(private oauthService: OAuthService, private authService: AuthService) {} |
||||
|
|
||||
canActivate( |
|
||||
_: ActivatedRouteSnapshot, |
|
||||
state: RouterStateSnapshot, |
|
||||
): Observable<boolean> | boolean | UrlTree { |
|
||||
const router = this.injector.get(Router); |
|
||||
|
|
||||
|
canActivate(): Observable<boolean> | boolean | UrlTree { |
||||
const hasValidAccessToken = this.oauthService.hasValidAccessToken(); |
const hasValidAccessToken = this.oauthService.hasValidAccessToken(); |
||||
if (hasValidAccessToken) { |
if (hasValidAccessToken) { |
||||
return hasValidAccessToken; |
return hasValidAccessToken; |
||||
} |
} |
||||
|
|
||||
router.navigate(['/account/login'], { state: { redirectUrl: state.url } }); |
this.authService.initLogin(); |
||||
return true; |
return true; |
||||
} |
} |
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue