154 questions
3
votes
0
answers
33
views
What is the purpose of canLoad in Angular if we already have lazy loading and canActivate? [duplicate]
I have two modules in my Angular application, and I am using lazy loading to prevent a module from being loaded until the user navigates to it.
Additionally, I am using canActivate in my route guards ...
1
vote
1
answer
228
views
How do I use Angular's inject within a canActivate function?
In the following canActivate function, I need to get the number of Items in a cart. I inject the CartService for this purpose but am getting an error that inject() must be called from an injection ...
1
vote
1
answer
169
views
I'm using version 17 of Angular and I would like to know how to use CanActivate, which has been discontinued and is now CanActivateFn
I have the following code in my old version of Angular
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from
'@angular/...
1
vote
1
answer
913
views
Angular 18: How to redirect on result of resolve
In Angular 18, I am trying to resolve a value before navigation, but redirect to another page based on that value.
Please don't link to a page titled "Redirecting Guards and Resolvers in Angular ...
2
votes
2
answers
108
views
How to prefix automatically language in path of route with Angular 14
I try to add the language of customer directly in the path like
/en/dashboard
And if a customer go to the web site with an older link, like
/home
I want to add automatically the default language in ...
1
vote
1
answer
211
views
How to implement state managed by auth reducer in angular auth guard using new CanActivateFn instead of deprecated CanActivate?
// auth.guard.ts
export class AuthGuard implements CanActivate {
constructor(private store: Store<fromAuth.AuthState>, private router: Router) {}
canActivate(): Observable<boolean> {
...
0
votes
1
answer
184
views
Upgrade from Angular 7 to 14 - routing problem -redirectTo and canActivate cannot be used together
I get this error Error: NG04014: redirectTo and canActivate cannot be used together. Redirects happen before activation so canActivate will never be executed. after upgrading angular 7 to 14. Anyone ...
1
vote
3
answers
156
views
Error using HttpClient in canActivate class | [ERROR] NullInjectorError: No provider for _HttpClient
I've some troubles when I want to use HttpClient in a CanActivate class.
I want to do some POST request in order to find my token in a Django API.
Examples are better than words :
auth.guard.ts :
...
3
votes
1
answer
1k
views
Service Injection in CanActivateFn - Angular 16.2
I'm trying to use the value I collect from the Authorization Header in an authGuard.
The Service that manages the login successfully logs the value I expect.
import { HttpClient, HttpResponse } from '@...
0
votes
0
answers
361
views
How do I use a CanActivateFn to hide a link?
I am using CanActivateFn rather than CanActivate to handle my routing authentication.
Here is my app-routing.module.ts:
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@...
0
votes
1
answer
102
views
Authorization Issue with Angular Auth Guard canActivate method
I am using an Angular authentication guard to handle authorization for each route. I need to call two API endpoints to retrieve user information and current user privileges. With my code, it follows ...
4
votes
1
answer
4k
views
Router parseUrl() vs navigate() in Angular16
I am in Authenticate with authGuard. I would like to know the difference between these two
// Redirect to the login page
return router.navigate(['/login']);
return router.parseUrl('/login');
In ...
0
votes
2
answers
1k
views
How to get dynamic parameter in functional canActivate guard without ActivatedRoute in Angular v16?
I'm trying to implement a functional canActivate guard in Angular v16, but I'm facing an issue with retrieving dynamic route parameters. I want to access the username and id parameters from the route ...
0
votes
1
answer
2k
views
Angular CanActivate Guard
I am developing a small project using Angular, Nodejs, Express, MySQL. In the project there is 2 type of user, customer user and contractor user.
I am having difficulty in using CanActivate to guard ...
1
vote
1
answer
78
views
Angular : Routes access restrictions for Logged users
I Need to restrict the logged in user from accessing all the routes when the user is forced to change password after its expiry.
The user should not be able to manipulate the URL in the address bar ...
1
vote
0
answers
299
views
Auth guards for google oauth2 connection always returns false
I'm on a angular project using angular-oauth2-oidc. There is login component, a home component and a auth guard that enable to go to /home only if I'am connected. The connection is with google sign in ...
1
vote
1
answer
2k
views
Return boolean observable on angular guard
I would like to block URL access from unauthorized users.
I'm currently using canActivate with route Guard from angular to block users to access /my/specific_url_route.
Indeed, I want to block some ...
0
votes
1
answer
440
views
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 ...
2
votes
1
answer
279
views
How to access the current Url Segment that is being tested in the Guard
I have a generic CanActivate guard and want to alter the matrix params of the corresponding path segment (the one being tested).
With given route config:
{
path: 'parent',
canActivate: [...
110
votes
5
answers
132k
views
Angular's "CanActivate" interface is deprecated. How to replace it?
My Angular app includes a simple AuthGuard as shown below and there has never been a problem with it. Recently, I upgraded my Angular version from 15.1.4 to 15.2.0 and since then, my IDE indicates ...
3
votes
2
answers
7k
views
Invalid configuration of route '': redirectTo and canActivate cannot be used together
I want to do laravel angular jwt authentication, so I want to apply guard but it gives me error: Invalid configuration of route '': redirectTo and canActivate cannot be used together. Redirects happen ...
0
votes
1
answer
115
views
How to stop my angular service guards from forcing my application to route to previous page without user input (clicking)
l'm working on a angular application and l have two service which are after login service and before login service. when l use these two guards my application routes itself after every 10 minutes e.g. ...
0
votes
0
answers
180
views
Infinite loop in Angular's canActivate route guard
In a very very worst case, If you see that the API which is used to fetch the permitted features for an authenticated user, responds with empty feature list or simply the call fails, means an ...
-1
votes
1
answer
502
views
Angular route throws 500 Internal server error on refresh the page when I remove the canActivate from the route
I am having an angular 11 app. It throws a 500 internal server error on the route when I refresh the page. This started to happen when I remove the "canActivate" from the route. This only ...
0
votes
0
answers
263
views
I need my Angular app to wait for the server to send the authentication cookie before canActivate() is called on the auth guard
I have an angular app, and authentication works, but when you open a new tab, the auth guard doesn't see the auth cookie(because the cookie hasn't arrived yet) and so the guard doesn't let you into ...
1
vote
1
answer
178
views
How to evaluate multiple observables in canActive guard?
I have this guard that is evaluating multiples observables, but in the verifyMoviesStore observable is having issues, this is a selector from NgRx, the problem with this one, is that is updating the ...
0
votes
1
answer
777
views
Using NGRX in Router Guard
Need some help with complicated Initialization using NGRX
I'm using a CanActivate guard for one of my routes to ensure my NGRX store is initialized with the necessary data for my component. I'm ...
1
vote
0
answers
418
views
lazy loading with CanActive
I implemented lazy loading in my project and it works well: the components load only if the http route is requested.
but when I implement canActive to prevent some users from accessing: the user can ...
1
vote
2
answers
3k
views
Angular CanActivate guard wait for api response and not calling api everytime
I have an observable to check if the user is loggedIn or not. I set that observable from auth api which is called from appComponent when application starts.
export class AppComponent implements OnInit ...
0
votes
2
answers
2k
views
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 ...
1
vote
1
answer
467
views
How to call an async method in canActivate | Ionic ,Angular
I want to get a token to authenticate the users. I save the data with import { Storage } from '@ionic/storage-angular'; the problem is that Storage methods just works in async mode.
This is the ...
0
votes
1
answer
755
views
Cannot find name 'canActivate'
Guys i'm trying to make a auth guard to guard routes that someone who isnt authenticated cannot access. In my AuthService i imported Can Activate like this:
import { CanActivate, ...
0
votes
1
answer
1k
views
How to use same route guard for different routes that differ in authorization logic
For my Angular 6 project, I have one canactivate AuthGuard to load ComponentA.
I want to know can I use the same AuthGuard for component B where it's the authorization logic is exactly opposite to ...
0
votes
1
answer
2k
views
Angular How to implement CanActivate guard with HTTP Get call
For my Angular 6 project, we want to use CanActivate guard to check authorization.
To implement this, I need to call getSummary() http get call from app.service and perform some logic from its ...
0
votes
2
answers
321
views
Angular canActivate httpClient infinite loop
I have code like this:
auth.guard.ts
canActivate(): void {
const token = localStorage.getItem('token');
const refreshToken = localStorage.getItem('refreshToken');
if (!token || !...
0
votes
1
answer
1k
views
Angular route protection with AuthGuard use only one time
i am protecting all my routes with a single Authguard and right now i am using in each route
canActivate: [AuthguardService]
my application has 30+ routes and so i need to type this 30 times in each ...
0
votes
1
answer
309
views
CanActivate, Cant map to subject
My group and I are building a website using angular for the client side. We're trying to use AuthGuard to lockdown the routes but are having trouble not being able to map to the subject.
LoginService:
...
0
votes
1
answer
1k
views
canActivate is blocking all routes when logged in, Angular 13
I am struggling to figure out what is going on with my canActivate Method. Currently, I am able to log in and see that my user credentials are being saved and used in both localStorage and a console....
3
votes
1
answer
537
views
The guard does not work the second time in angular 11
I am configuring a guard for my angular app and it happens that when I run the application and log in the first time it works fine, but I configure an error interceptor where I have a condition that ...
2
votes
1
answer
95
views
angular 9 why canActivateChild start befor canActivate completed?
in my program I have a func in canActivateChild that need to occur
after canActivate finished , but the child component loads befor canActivate of the parent finish,why?
my routing-module:
const ...
-1
votes
2
answers
2k
views
Angular RouteGuard "A function whose declared type is neither 'void' nor 'any' must return a value"
I have a route guard that checks if a user has access to a resource, before proceeding. After the subscription, I check if the user has access, and if not, redirect using parseUrl or return true.
@...
0
votes
1
answer
385
views
How to return a value after `retryWhen` expires? (for `canActivate` guard)
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 ...
2
votes
2
answers
2k
views
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 ...
1
vote
1
answer
232
views
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 ...
1
vote
1
answer
1k
views
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/...
2
votes
1
answer
877
views
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 web app and want to make a role -> permission system.
I've made roleGuard with CanActivate, ...
1
vote
1
answer
2k
views
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){
}
...
1
vote
1
answer
2k
views
Angular Router route guard CanActivate always returns false
I have used CanActivate to protect a page but it always returning false because of that I can not access the protected router. I tried many ways, but was not successful to fix the issue. I am new to ...
0
votes
1
answer
778
views
Angular Routing to Child path based on role
After successful login, I redirect to following path
this.router.navigate(['/main/'])
Based on role received from login. Is it possible to redirect to diff modules.
Example: If Role is 'Admin' if I ...
0
votes
1
answer
2k
views
Redirect to a specific page when using CanActivate
In my application when a user try to see the page "home" he is redirected to the login page (if he's not already logged in). If the user is already logged in, or after he logged in, I want ...