Questions tagged [angular-guards]

123 questions
0
votes
1 answer

Angular router doesn't work when guards return an Observable

I want to redirect users who are not logged in when they try to access protected routes but redirection does not work because the function that checks if the user is logged in returns an Observable. This is my code in PrivateGuard: import {…
0
votes
2 answers

Angular Guard and JWT

I am trying to do the next... i have an API where i send a JWT token by POST to be verified if it is valid/expired, so in my angular login service i have a method like this. isUserlogged() { return this.httpClient.get(`${this.URL}/verifyToken`, {…
Sergio Cano
  • 690
  • 3
  • 13
  • 36
0
votes
1 answer

CanDeactivate fires only once and not always

My CanDeactivateGuard not always fires when I click browser back button. I can't find the reason. Could you take a look at my code, and give me advice? Guard: @Injectable() export class CanDeactivateGuard implements CanDeactivate { …
pelcomppl
  • 575
  • 2
  • 6
  • 16
0
votes
2 answers

Route to some other page based on guard in angular 6, rxjx 6 async request

I have implemented the functionality where I am able to get the request and control the authorization of the page, I want to redirect to login page in case of false request. public canActivate(route: ActivatedRouteSnapshot, state:…
Abhishek
  • 61
  • 2
  • 8
0
votes
1 answer

Angular 6 nested children routing not rendering view

I am stuck in a place where the navigation works, but view is not working basically one component is mapped to two different routes: Component is example.component.ts Routes…
Kumail Hussain
  • 869
  • 2
  • 26
  • 49
0
votes
2 answers

Is there a way to redirect if from within Guard in Angular when using asynchronous method to validate?

In my Angular(6.x.x) project, I am implementing a Guard on certain routes that should redirect to '/login' if it fails. The Guard, relies on an asynchronous method in AuthService for validating the user. // AuthService checkLogin():…
aryaag
  • 110
  • 8
0
votes
1 answer

Angular 6+ Guards - Return true/false to combineLatest subscription

How can I return true/false inside subscribe? import {Injectable} from '@angular/core'; import {Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot} from '@angular/router'; import {AppState} from '../../app.state'; import {select,…
Michalis
  • 6,686
  • 13
  • 52
  • 78
0
votes
1 answer

User access for specific routes with parameters

I am using Angular with firebase. In my app users can create "projects" and invite another users to that "project" in other words one project can have multiple users. I have user collection and project collection in firestore. User…
Raold
  • 1,383
  • 4
  • 20
  • 33
0
votes
1 answer

CanActivate returns me to a blank page instead of redirecting

My guard returns me to a blank page instead of redirecting me. Also my root is not a blank page it should send me to login as well. This happens when I go to any supervisor page. These are my routes: export const appRoutes: Routes = [ {path: '',…
Sinan Samet
  • 6,432
  • 12
  • 50
  • 93
0
votes
0 answers

Angular 2 authentication guard http GET request to check if user has session

I am trying to call an http GET method to check if the user has a session with my back end NodeJS API, but I can't see the request being made. I have an observable that is set when the user logs in so my AuthGuard will check this first, if this is…
0
votes
1 answer

Angular2 auth card navigate to home page

I'm new to angular 2 actually im facing issue when i am refresh its redirect to login page but actually i wants redirected to dashboard canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | boolean { //…
dhinesh
  • 1
  • 4
0
votes
0 answers

Angular - restricted page being shown as window.open redirects in guard

I am implementing a canActivate Guard that has a logic to redirect to the login site if the user is not logged in. So far, all the examples and fixes I've come across are dealing with a login page defined in Angular itself. In my case, login is on a…
0
votes
1 answer

Angular 4 call an observable after the first finish then return a value

I have a big problem and after hours of reading documents and solution I can't find how I will be able to solve this problem : Basically I have in my angular guard this : canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { …
Imad El Hitti
  • 917
  • 3
  • 10
  • 23
0
votes
2 answers

Angular 2+ : canLoad usage

I'm trying to use the canLoad function with routes, but it doesn't seem to work. I don't know why, maybe you can't use it with canActivate or something, but since I don't know, I thought someone would here. The code runs, when serving with aot…
user4676340
-1
votes
1 answer

How to redirect to the route in Angular if URL corresponds to the special pattern?

I have the URLs: /example.com/client/page-1?param=data /example.com/client/page-2 /example.com/client/page-3?newparam=data I want to redirect user to the following pages while they open the…
1 2 3
8
9