Refers to Angular's AuthenticationGuard class, a route protection mechanism most commonly implementing `canActivate`.
Questions tagged [auth-guard]
164 questions
2
votes
0 answers
Angular 6: transfer isAdmin? value from AuthService to AuthGuard canActivate() method
Angular 6 & Firestore application.
I am trying to build an AuthGuard service with a canActivate() method that returns a boolean. The boolean is based on a UserAuthService property called isAdmin.
The trouble is that canActivate() executes before…

John
- 521
- 1
- 7
- 23
2
votes
3 answers
How to achieve Role Based redirection after login in Angular-5?
I am new to Angular, and i am using Angular-5.
In my application i have 2 screens/components called 'Admin-Dashboard' and 'HR-Dashboard'. My default route is /Admin-Dashboard have look at following routes:
const routes: Routes = [
{
path:…

Anonymous
- 1,726
- 4
- 22
- 47
2
votes
1 answer
Angular routing not working after successfull authentication
I got the simple authentication working with AngularFireAuth but now my routing doesn't work anymore the console.logs shows the 'Nice it worked', so what is wrong? (this is mainly just the routing guard out of the…

Burst of Ice
- 386
- 2
- 6
- 23
2
votes
1 answer
How to stop my angular application from logging out after page reload
I am using auth gaurd to prevent URL manipulation in my angular application and redirecting URL manipulation to login page. But it is causing a problem and that is even after successful login, on refreshing the webpage it considers it as URL…

ABHISHEK KUMAR
- 71
- 1
- 10
2
votes
3 answers
How can I return true/false based on api response message in my angular authguard method?
I've put an angular routing authguard to put my page. I've an api that checks if the token is valid and based on that I want to return true or false for further navigation.
But seems that in 'subscribe' I assign my 'result' flag true not persisting…

tyro
- 577
- 8
- 17
2
votes
1 answer
Angular 5 Authentication
I'm trying to understand the authentication process with Angular and .Net core which sends me an jwt Bearer token(Works). So my Problem is that I don't know what i should do in the guard and auth service to manage users (with roles later) properly.…

Amsel
- 107
- 1
- 13
1
vote
2 answers
Angular's AuthGuard allways return false on page refresh, but I am authenticated
I am creating login system in my Angular application. Everything works fine, I have just one problem with my AuthGuard. When I refresh the page in which implement 'canActivate: [AuthGuard]' it redirects me to login and i get isAuth = false. But from…

devZ
- 606
- 1
- 7
- 23
1
vote
0 answers
AuthGuard with HTTP Request Error (HTTP Request return = undefined)
i try to implement a AutGuard with a HTTP Get Request. but the http request dont work. the variable userRole is undefined and the get request doesnt work. (the adminService.getUserByToken... works on Components). is it possible to http request in…

rickymort
- 11
- 2
1
vote
1 answer
Login request is always 401 Unauthorized with AuthGuard
I have been following this tutorial and trying to convert it to GraphQL. I am trying to implement a NestJS + GraphQL + Passport + Express-Session solution but I am having problems with the AuthGuard. Sadly there is only little information on this…

Tanonic
- 133
- 5
1
vote
1 answer
Can an Angular Component also be used as an Authentication Guard
I'd like to move the CanActivate method out of my Auth.guard.ts to rather be in each pages component. The reason for this is that my auth guard file is getting cluttered and I think logically it makes sense for the permissions handling of a…

Stanton
- 904
- 10
- 25
1
vote
1 answer
Angular keeps redirecting me to login Page when I try to access another Page
I have a website that it is divided into some ordinary components that can be accessed by any user and one protected component which is shielded by AuthGuard that will redirect user to login page if not logged in.
The problem I am facing here is…

jumosbro
- 51
- 1
- 5
1
vote
1 answer
AuthGuard CanActivate not working in app-routing.module.ts for an authenticated user with role as admin in angular .net project
After a user is authenticated, if user is of admin role, the menu items - movie, genres, actor and movie theater are shown in the menu else they remained hidden. After my WEBAPI returns role as "admin", the menu items remain hidden. I am not able to…

abacus
- 19
- 2
1
vote
1 answer
Angular Router endless loop with canActivate / redirectTo
I'm having trouble getting a redirect in my routing module working, and adding an AuthGuard in CanActivate complicates it even further. Here is a simplified router:
const routes: Routes = [
{
path: 'login',
component: LoginComponent,
},
…

Luke Peña
- 41
- 4
1
vote
1 answer
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…

Tommy Gordon
- 21
- 4
1
vote
0 answers
angular mutiple observable guard dont run with ordering
hi i have two guard in my routing.
my first guard is like below code
canActivate(
route: ActivatedRouteSnapshot,
state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree {
const token =…

arman
- 41
- 6