1

hi i have two guard in my routing.

my first guard is like below code

  canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {
const token = localStorage.getItem('token');
if (token) {
  if (this.authStore.getUserValue()) {
    this.user = this.authStore.getUserValue();
    return true;
  } else {
    return new Promise((resolve, reject) => {
      Promise.all([
        this.isLoggedIn()
      ]).then((res) => {
        console.log(res[0])
      }, reject)
    })
  }
} else {
  return new Promise((resolve, reject) => {
    Promise.all([
      this.isLoggedIn()
    ]).then((res) => {
      console.log(res[0])
    }, reject)
  })
}
}

  isLoggedIn(): Promise<UserModel> {
return new Promise((resolve, reject) => {
  this.authService.isLoggedIn().subscribe((res) => {
    resolve(res.data.user)
  }, reject)
})
}

its run perfect .

but my second guard dont wait for first guard and run.

is ther a way for run first guard and second guard like async await or other ways?

thanks for your answers.

ZINE Mahmoud
  • 1,272
  • 1
  • 17
  • 32
arman
  • 41
  • 6

0 Answers0