Questions tagged [angular-guards]

123 questions
1
vote
0 answers

Angular Guard is not able to access the Angular Service Object

I am trying to access the Angular Service Object (I have set the AuthContext in service) but Angular Guard is giving undefined even though that is well set. I have login component, which I call first and internally It uses the Angular Auth…
1
vote
1 answer

Check guard on multiple values via ngrx select

I have a canActivate ( guard ) where I am checking the loaded variable to see if the queue has loaded or not. However I now need to check multiple queue loaded variable ( boolean ) to see if they have all loaded or not. I will need to dispatch…
prabhat gundepalli
  • 907
  • 3
  • 15
  • 39
1
vote
1 answer

Using a service in angular 4 guards

Please assist with angular guards, I have the following angular Guard below : export class RoleGuard implements CanActivate { private role: any; constructor(private router: Router, private accountService: AccountService) {} canActivate( …
Silva
  • 625
  • 1
  • 6
  • 25
1
vote
1 answer

Router canActivateChild with more than 1 guard

I am using more than one canActivateChild guards as shown below: {path: 'admin', canActivateChild : [AdminAuthGuard, EmployeeAuthGuard], children: adminRoutes } Below is definition of admin guard: canActivateChild() : boolean { const role =…
Tavish Aggarwal
  • 1,020
  • 3
  • 22
  • 51
1
vote
1 answer

How can I protect a URL based on the input of an Angular Material Dialog using a Guard?

Goal: I have a specific URL protected using a Guard. When a user attempts to access that URL I have an Angular 4 material dialog open. Based on the dialog input, I want to authorize or not authorize the user. Issue: In the Guard I subscribe to the…
jinan
  • 173
  • 1
  • 10
1
vote
1 answer

resolver with a guard in angular4 with ASP.NET Web Api 2

I am working on angular 4 Project with Asp.NET Web API 2. I want to check if the user is authorized before he enters the admin section. I tried to set the resolver in the routing of angular, like that: resolve(route: ActivatedRouteSnapshot, state:…
Samy Sammour
  • 2,298
  • 2
  • 31
  • 66
0
votes
0 answers

Block all methods except GET to root url of my application

I am experiencing an issue where any call to my root URL, http://example.com, is returning a 200 response, but I would like to restrict this behavior to only GET methods for security purposes. I have tried multiple approaches such as backend…
Kenzo_Gilead
  • 2,187
  • 9
  • 35
  • 60
0
votes
1 answer

Lock/deny url from users (angular guard)

I would like to block url access from unauthorized users. I'm currently using canActivate with route Guard from angular for blocking no Admin user to access /admin route (that's works OK). But now, I have an other use case that is a bit complex: I…
0
votes
2 answers

Angular15 - canActivate based on values stored in BehaviorSubject in oher service

I have PermissionsService which stores user's permissions. These are loaded from API by HttpClient after user's successful auth process (after login I call the getUserGroupsWithModelPermissions() which loads user's permission groups, and then I sum…
0
votes
0 answers

Angular canActivate is not working, it can not redirect to the site what I expected

Use Case: I want to use angular guards canActivate to redirect a Info site. the code with canActivate is as follow: canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable< boolean | UrlTree>{ …
user1938143
  • 1,022
  • 2
  • 22
  • 46
0
votes
1 answer

Why Angular Guards canActivate method is always returning false?

I'm doing a basic authentication for users after login, but weird behavior is happening, where canActivate is returning false, even though it is being called in the right time. in Login Component private login() { …
Ali
  • 1,633
  • 7
  • 35
  • 58
0
votes
2 answers

alternative way for canActivate in angular

In my angular 12 project, I have applied canActivate on routes but due to which routes are not working on browser page reload. In canActivate , i am checking data is present or not in localStorage for currentUser. but when I reload page I didn't get…
ganesh
  • 416
  • 1
  • 11
  • 32
0
votes
1 answer

Angular Guard - how to make canActivate wait for a value?

I have a guard that depends on a client. The guard isn't working as expected because the client is not ready by the time the guard is hit. How do I get the guard to wait until the client is ready? public canActivate() { if…
BNK
  • 11
  • 1
0
votes
1 answer

Guard not re-routing to other component

I have these two guards @Injectable({ providedIn: 'root' }) export class DesktopGuard implements CanActivate { constructor( private router: Router, private route: ActivatedRoute, ) { } canActivate() { if (window.innerWidth < 768)…
godhar
  • 1,128
  • 1
  • 14
  • 34
0
votes
0 answers

Angular Guard Service not working when i hit the url directly

I have implemented Routing and Guard Service in my application. When navigate by clicking by anchor tag button it is working fine. But, when I try to navigate by hitting url it is returning empty page. app-routing.module.ts import { NgModule } from…
1 2 3
8 9