Questions tagged canactivate

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

Delay canActivate call when page refreshes in order to wait for the data to load

When I reload my page, it always goes to blank page instead of the same page. The reason behind this is canActivate method which is cheking for user’s permission gets invoked as soon as user refreshes the page and it is not able to get user data immediately. User data comes after some seconds. Is […]

By Radiant
Categorized as angular, angular-ui-router, canactivate, rxjs Tagged , , ,

How to reactivate deleted item

I am working on a web app and I need to implement reactivation of deleted items. I have a method that checks if the item exists already: getExistence( item: string ): Observable<any> { if (item) { return this.http.get<any>( this.existenceUrl + item ); } } and its interface looks like this export interface ItemExistence { short: […]

By user16814898
Categorized as angular, canactivate, service, typescript Tagged , , ,

How can i use canActivate() to block access to certain routes?

I am actually working on an website that have multiple users. I want to update a user’s information and it works so fine but when i type on the URL an id of another user instead of the current user i can simply access to that profile while i am not supposed to . Source: […]

By BHIRI Yosri
Categorized as angular, auth-guard, canactivate, routes Tagged , , ,

How to fix error TS2416: Property ‘canActivate’ in type ‘KeycloakAuthGuard’ is not assignable to the same property in base type ‘CanActivate’?

I am very new to the angular project. After I clone the project and try to up the project with ng serve. So I am getting an error like. ERROR in node_modules/keycloak-angular/lib/core/services/keycloak-auth-guard.d.ts(10,5): error TS2416: Property ‘canActivate’ in type ‘KeycloakAuthGuard’ is not assignable to the same property in base type ‘CanActivate’. Type ‘(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) […]

By Dasun
Categorized as angular, angular6, canactivate, keycloak Tagged , , ,

CanActivate on pagination in Angular

I have server side pagination on a list screen in angular. When I click on the link to visit the screen, sometimes the pagination number doesn’t appear and I have to double click the link to get the number. I have used CanActivate guard on the screens so that the screen gets displayed only when […]

By Ahmad
Categorized as angular, auth-guard, canactivate Tagged , ,

How to correctly go to state url using AuthGuardService

I am having trouble navigating to the state url after login. Here is my AuthGuardService canActivate func: async canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { sessionStorage.setItem(‘routeAfterLogin’, state.url); let auth: boolean = true; this.authService.isAuthorized().subscribe(authorized => { if (!authorized) { this.authService.login(); } auth = authorized; }) return auth; } and then I’m getting the saved state url in app.component.ts […]

Delayed CanActivate in Angular Router blocks rendering

I have a mat-table with 3000 rows (array with mock data) behind a CanActivate guard. Based on CanActivate docs, it can return both boolean or Observable<boolean>. If it returns true, mat-table component loads instantly. Now, I want to use the CanActivate to see if user has logged in. Here is an observable that will wait […]

Role based permissions system

I’ve never done this before and couldn’t find a good reference online so I’m asking. I’m building angular webapp and want to make a role -> permission system. I’ve made roleGuard with CanActivate, but I cannot find a good way to make logic for checking permissions for it. Storing permissions in token or localstorage and […]

By reznov46
Categorized as angular, angular8, canactivate Tagged , ,

CanActivate guard leads to multiple http calls

I observed strange behavior with my CanActivate guard (Angular 10.2.5): export class VersionGuardService implements CanActivate { constructor(private router: Router, private http: HttpClient){ } canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { console.log("In the Guard"); return this.http.request<any>(‘get’,``).pipe( tap(resp => console.log("Response: ", resp)), map(resp => false) ); //return of(false); } } Routes in app-routing.module.ts looks like this: const routes: […]

By dzk008
Categorized as angular, canactivate Tagged ,

Angular Http call in CanActivate getting cancelled

I’m trying to create an guard to verify the token via http call, As CanActivate accepts return types as Observable . Though the http request is completed from the backend still in front it shows as cancelled, below is my code canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> | boolean { if (this.isTokenPresent(route)) { return this.validateToken(route).pipe(map((e: any) […]

By Azeem
Categorized as angular, canactivate Tagged ,
1 3

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