@ -6,10 +6,10 @@ import {
CanActivateFn ,
CanActivateFn ,
} from '@angular/router' ;
} from '@angular/router' ;
import { Observable , in terval , filter , take , map , firstValueFrom , timeout , catchError , of } from 'rxjs' ;
import { Observable , tim er , filter , take , map , firstValueFrom , timeout , catchError , of } from 'rxjs' ;
import { OAuthService } from 'angular-oauth2-oidc' ;
import { OAuthService } from 'angular-oauth2-oidc' ;
import { AuthService , IAbpGuard } from '@abp/ng.core' ;
import { AuthService , IAbpGuard , EnvironmentService } from '@abp/ng.core' ;
/ * *
/ * *
* @deprecated Use ` abpOAuthGuard ` * function * instead .
* @deprecated Use ` abpOAuthGuard ` * function * instead .
@ -58,14 +58,17 @@ export const asyncAbpOAuthGuard: CanActivateFn = (
route : ActivatedRouteSnapshot ,
route : ActivatedRouteSnapshot ,
state : RouterStateSnapshot ,
state : RouterStateSnapshot ,
) = > {
) = > {
const oAuthService = inject ( OAuthService ) ;
const authService = inject ( AuthService ) ;
const authService = inject ( AuthService ) ;
const code = new URLSearchParams ( window . location . search ) . get ( 'code' ) ;
const environmentService = inject ( EnvironmentService ) ;
const { oAuthConfig } = environmentService . getEnvironment ( ) ;
if ( code ) {
if ( oAuthConfig ? . responseType === ' code' ) {
return firstValueFrom (
return firstValueFrom (
interval ( 100 ) . pipe (
timer ( 0 , 100 ) . pipe (
map ( ( ) = > authService . isAuthenticated ) ,
map ( ( ) = > oAuthService . hasValidAccessToken ( ) ) ,
filter ( isAuthenticated = > isAuthenticated ) ,
filter ( Boolean ) ,
take ( 1 ) ,
take ( 1 ) ,
timeout ( 3000 ) ,
timeout ( 3000 ) ,
catchError ( ( ) = > {
catchError ( ( ) = > {
@ -76,7 +79,7 @@ export const asyncAbpOAuthGuard: CanActivateFn = (
) ;
) ;
}
}
if ( authService . isAuthenticated ) {
if ( oAuthService . hasValidAccessToken ( ) ) {
return true ;
return true ;
}
}