Questions tagged canactivate

Explore the latest questions and answers asked by our top developers.

How to process data from api response then return a boolean value synchronously in angular?

I have a simple function in my service: /** * Funtion to check if the user logged in has admin rights */ isAdmin(user_id: string) { var adminTemp: boolean; this.httpClient .get(`${this.urk}/${user_id}`) .subscribe((data: any) => { if (data.includes(‘Admin’)) { adminTemp = true; } else { adminTemp = false; } }); return adminTemp; } This function is called […]

make delay in canActivate till IP address data is fetched

I’m making a guard for my angular application where all users should be redirected to maintenance page except for certain IPs. I’m getting the client IP address using third party APIs like http://api.ipify.org/?format=json. The PROBLEM I’m facing is that the canActivate guard gets executed before the IP API sends in the response, thus always returning […]

angular – How to create a canActivate guard to only allow redirects from another component?

I have a component that I wish to allow it’s access only in case of a redirect from another component. So if I put the url in the browser it wouldn’t allow me to access it but, if I redirect to it from another specific component like this it will be allowed: this.router.navigate([‘/main/myLockedComponent’]); I thought […]

How to unify canActivate logic and pass selector function as route parameter in Angular10?

everyone reading this :). Have a good time ! I was solving a problem in our project and cannot find a way to write DRY code We have /article/:id URL in app, some articles are available by id – [1,2,3], others are not [11,22,33] (for example) and i need to prevent user openning such ids. […]

By Anton
Published
Categorized as angular, canactivate, router Tagged , ,

Angular CanActivate with observables

I’m having a problem with the guard of a route in angular; I have an APP_INITIALIZER that call a service ( AuthService) to perform a login to a SSO system ( keyclok ); I have an Observable ( in the AuthService ) that emit the result of the login; the problem that I have is […]

By S-Wing
Published
Categorized as angular, angular2-routing, canactivate Tagged , ,

Authgard JWT refresh undefined

I am currently integrating authgard in my angular application. I’ve also set up a token refresh system if the token has expired. Everything works pretty well, but I still have a problem with redirection after the token refresh. The "canActivate" function doesn’t wait for the response from the "isAuthenticated" function and receives an "undefined" instead […]

Angular routing same path different guard

I want to use the same path ticket because I want to redirect when save something (Use same component to Update Ticket ). But there is a problem with canActivate. What is the best way to fix it? const router: Routes = [ { path: ”, component: HomeLayoutComponent, canActivate: [AuthGuard], children: [ { path: ”, […]

How to pass a boolean parameter from Route Guards in Angular

I need to guard the routerLinks based on some boolean configurations coming from a server. Currently i have written canActivate route guard. ActivateRoutes file async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<any> { const visibility = route.data.name; return await this.service.activateRouterLinks(visibility); } This my app.module.ts file { path: ‘home’, loadChildren: ‘src/app/home/home.module#HomeModule’, data: { title: ‘Home’, name: Names.HOME }, […]

angular router endless loop when navigated from from canActivate

As angular routers need static paths, I am using canActive to dynamically route my app. my main module is as follows. import { NgModule } from "@angular/core"; import { RouterModule } from "@angular/router"; import { AuthGuard, AuthData} from "./shared/auth-guard"; // DOC https://toddmotto.com/angular-component-router @NgModule({ imports: [ RouterModule.forRoot([ { path: ”, redirectTo: ‘app’, pathMatch: ‘full’ }, { […]

Angular canActivate get updated variable from service

I have a post request from a service which returns if a user is logged in, and I want to set a authGuard to only show the admin panel when they are logged in. My post request is as follows: public isLoggedIn: boolean = false; checkSesh(data: object) { const options = { headers: new HttpHeaders().set(‘Content-Type’, […]

By DevStacker
Published
Categorized as angular, canactivate, subscribe Tagged , ,
1 2 3 4

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq