Questions tagged [canactivate]

145 questions
1
vote
1 answer

Angular canActive with observable

I am using the canActivate method in a guard. Inside I have an observable, which gives me back an object. This object has a password. I check the password, and if it's right, I want canActivate to return true, if not, false. Here is the code …
AlbertMunichMar
  • 1,680
  • 5
  • 25
  • 49
1
vote
1 answer

Angular 5 routing with query string

I am writing my angular 5+ app and using AuthGuardService what I am doing is that I am redirecting from another php application which send me form data in query string http://localhost:44200/#/users/save?first_name=John&last_name=Doe the…
Khan
  • 5,052
  • 5
  • 22
  • 23
1
vote
1 answer

How to use CanActivate for child route correctly?

I'am using CanActivate feature for my router and its child, but it doesn't work - Have been using the same couple of months ago, but now not. There is no error, warning or something similar I can debug... the app just run and I can reach the router…
k.vincent
  • 3,743
  • 8
  • 37
  • 74
1
vote
1 answer

angular 4 router auth-guard not invoked on same route

Hi i configured this routing: const routes: Routes = [ { path: '', component: LayoutComponent, canActivateChild: [AuthGuardService], children: [ { path: '', pathMatch: 'full', redirectTo:…
user9223099
1
vote
3 answers

Angular 4 - CanActivate check component being route

In CanActivate is there a way to check which component is being route/requested by the user for authentication purpose. So instead of checking the url as i am doing below, i would like to do something like if(route.component instanceof…
Bhavesh
  • 819
  • 1
  • 17
  • 31
1
vote
1 answer

How come Angular http.post invoked without `.subscribe`?

Looking at this authguard which is called from canactivate : @Injectable() export class AuthGuard implements CanActivate { constructor(private loginServicePOST:LoginService, private router:Router) { } …
Royi Namir
  • 144,742
  • 138
  • 468
  • 792
1
vote
1 answer

CanActivate: Converting Observable> to Observable

I have a user settings page that only the owner should have access to. I want to use CanActivate to implement the restriction. CanActivate requires the output to be boolean or the observable of a boolean. However, my code outputs an observable of an…
Noel Delgado
  • 173
  • 1
  • 2
  • 7
1
vote
1 answer

Navigating to a certain page if user enters an url from a new tab

I have built a loginPageGuard which simply not letting user lo login page if it is already logged in. Lets say user is on http://localhost:4200/#/testUrl and tries to go to http://localhost:4200/#/login LoginPageGuard works as i want it to and…
rematnarab
  • 1,277
  • 4
  • 22
  • 42
1
vote
1 answer

CanActivate with Modal/selector

I am currently working on the authentication service of an application. This service works with a token generated by the back-end. As it is now, if the token is expired it will redirect the user to the login page; However, I would like to implement…
Filipe Tabosa
  • 183
  • 1
  • 3
  • 15
1
vote
1 answer

While Implementing CanActivate Guard Error as : No provider for HRComponent

While Implementing CanActivate Guard Im Getting error as : No provider for HRComponent import { Component, OnInit } from "@angular/core" import { ActivatedRoute, CanActivate } from "@angular/router" import { LoginService } from…
user8311110
1
vote
1 answer

Angular 4 CanActivate any one guard is true

Is there a way to implement CanActivate guard in Angular 4 such that if any one guard is true the route should be allowed. I know this is possible by using provide to a function and implementing the logic inside it, but was having a tough time…
1
vote
1 answer

canactivate guard angular 2

I have an angular app with two components "login" and "home". I want to guard the home component until user logs in. I have a service which has a boolean variable "isUserLoggedIn". Based on the value of this variable, I guard my component. Network…
Shiv Baral
  • 409
  • 4
  • 11
  • 18
1
vote
0 answers

Will CanActivate and CanActivateChild run at the same time if set?

Currently my application will set a XHR to server to get user information. I have set CanActivate and CanActivateChild like: { path: '', canActivate: [AuthService], canActivateChild: [AuthService], children: [ { …
tom10271
  • 4,222
  • 5
  • 33
  • 62
1
vote
1 answer

Browser totally blocked when I use guard children route in Angular 2

When I use RoleGuard in my 'pre-harvest' children path and I open the browser the browser is totally blocked, it seems that is in an infinite loop. I don't have any compilation problem and I can't open the console to see what errors I have. Is…
Ekaitz Hernandez Troyas
  • 1,147
  • 2
  • 11
  • 18
1
vote
1 answer

How does CanActivate work in Angular2?

TL;DR How does CanActivate work? Long version It is the first time that I see the implementation of a client-side access control. In all the authentication systems that I used so far (e.g. PHP or other server side programming language), there's…