Questions tagged [canactivate]

145 questions
1
vote
1 answer

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…
Dasun
  • 602
  • 1
  • 11
  • 34
1
vote
1 answer

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,…
dzk008
  • 31
  • 6
1
vote
0 answers

Angular 10 - canActivate Guard Prevents Navigation to Correct URL When Entered Manually

In my Angular 10 application, I have a route with several child routes, that has a canActivate guard on it. { path: 'settings', component: SettingsComponent, children: [ { path: '', redirectTo: 'index-types', pathMatch: 'full' }, …
1
vote
1 answer

What is the right way to route to another root node from a child node in angular?

I have a login page, and a lazy loaded module whose children constitutes most of the pages within the app. Here is a look at app-routing.module.ts const routes: Routes = [{ path: '', loadChildren: './main/main.module#MainModule' }, …
1
vote
0 answers

canActivate does not get called the 2nd time when inner observable emits another value

I am using combineLatest(which combines the values from all the Observables passed as arguments) in the canActivate method. My understanding is that, whenever any one of the observables fires, the canActivate observable needs to fire. But that is…
1
vote
0 answers

Guard only re-directs is app is already open in the browser

I'm trying to use a canActivate guard to validate url params and if they aren't a match then the app is supposed to redirect. I have the following so far: @Injectable() export class NodeInfoDetailGuard implements CanActivate { constructor( …
1
vote
3 answers

How to apply canActivate guard for all routes(master route and all sub routes) in Angular

I use Angular Guard to protect my routes, i add canActivate attr in master route and it works fine, while for sub single routes(ReportsRouteModule/RequestsRouteModule...), if i want to enable guard, i alse need to set canActivate in each routes, i…
1
vote
0 answers

Prevent Routing To Secondary View If Page Refresh In Angular going into recursion

I am developing "Prevent Routing To Secondary View If Page Refresh In Angular" code from : https://www.bennadel.com/blog/3368-prevent-routing-to-secondary-view-if-page-refresh-in-angular-5-0-0.htm I have developed below code, but code is going into…
PAA
  • 1
  • 46
  • 174
  • 282
1
vote
0 answers

Angular5 canActivate() async function unit test

Can anyone help me with this.. New to unit test.. Thanks Facing issues with Assync data export class ClassGuard implements CanActivate { isLoaded: boolean = false; constructor(private router: Router, private store:…
Beginner
  • 11
  • 2
1
vote
1 answer

How to fix canLoad issue when we are returning an observable with 404 exception

I am trying to call an API in canLoad event for a module in my angular application, Even though that API is not available and gives 404 in network, still my page is loading. I wanted to avoid that situation if there is 404 then I wanted to redirect…
vinod j
  • 83
  • 1
  • 12
1
vote
1 answer

Router Guards canActivate not working with API in angular

This Auth guard not working with API response. When I run the code it always returns true. but I want to run guard base on api response. is their way to achieving that? import {Injectable} from '@angular/core'; import {CanActivate,…
Supun Abesekara
  • 708
  • 7
  • 32
1
vote
2 answers

Handle HttpErrorResponse from an Observable that doesn't return a boolean inside a canActivate()

I'm trying to create a canActivate() function that will : return false; this.router.navigateByUrl('/login'); when the status code it 401 from an Observable i.e when HttpErrorResponse is raised. ============================================== This…
Hans Daigle
  • 364
  • 2
  • 14
1
vote
1 answer

CanActivate: Observable Boolean with Socket listener

I'm trying to grab a property from a socket from the server like this isVerified() { this.socket.emit('verify'); return new Observable(observer => { this.socket.on('isVerified', data => { observer.next(data) …
ErraticFox
  • 1,363
  • 1
  • 18
  • 30
1
vote
1 answer

Angular 5 canActivate always return to login page for specific route

I'm trying to secure my app from unauthorized users, by defining routes guard and assigning canActivate to each wanted-to-be-secure route. Everything is going fine on those routes, for example when someone want to access route from url it will…
Atom
  • 421
  • 2
  • 6
  • 16
1
vote
3 answers

Is it necessary to use a JWT token when logging in to Angular 6 and PHP web app

About the login step at Angular 6: If I did it as the following: Send username and password to PHP; Server code check user if exists; If really exists, we will send a json array again to Angular containing username and user role Save them in…
alim1990
  • 4,656
  • 12
  • 67
  • 130