angular-guards

Angular - Are admin files downloadable?

我的未来我决定 提交于 2021-02-08 06:46:34
问题 I have a website with Angular. I implemented the auth with jwt . I know we can prevent the user to go to the restricted routes with Angular Route Guard . Usually in SPAs all routes (html) are downloadable. Just we handle unauthorized routes in server by responding 403 code. So it's safe that user can see the html bu can't get any data. But in a specific project, we even don't want user to be able to see the html of admin panel (Since he can know about structures) Any idea? Should I use the

How to check: is the User logged in with angular-6-social-login npm package?

旧时模样 提交于 2021-01-28 12:21:09
问题 I have successfully integrated with angular-6-social-login (https://www.npmjs.com/package/angular-6-social-login) to login into my angular APP using google account. I am creating an Angular Guard to protect the routes so that only users can access after logging in. The AuthService from angular-6-social-login does not support any direct function to see if the user has logged in or not. Any suggestions here, please? import { Injectable } from '@angular/core'; import { CanActivate,

How to prevent actions by user role in Angular

十年热恋 提交于 2020-06-12 08:49:04
问题 I already have an AuthService to authenticate user on login and AuthGuard to prevent access if not logged in. Some pages I restrict access by UserProfile/Role but now I need to prevent actions on page. I have roles like "Admin, Manager, Support and Agent", from greater to lower. How to set level only to Manager or Above to edit content on a page that all can access (Support and Agent restrict to view only)? This is my current canActivate method: canActivate(route: ActivatedRouteSnapshot) {

How to prevent actions by user role in Angular

青春壹個敷衍的年華 提交于 2020-06-12 08:48:17
问题 I already have an AuthService to authenticate user on login and AuthGuard to prevent access if not logged in. Some pages I restrict access by UserProfile/Role but now I need to prevent actions on page. I have roles like "Admin, Manager, Support and Agent", from greater to lower. How to set level only to Manager or Above to edit content on a page that all can access (Support and Agent restrict to view only)? This is my current canActivate method: canActivate(route: ActivatedRouteSnapshot) {

getting variable data outside subscribe method

本小妞迷上赌 提交于 2020-01-15 07:09:07
问题 I am trying to implement canActivate for user routes, before that I want to check whether the access token is still valid or not. Therefore I implement something like this export class AuthGuard implements CanActivate { data:Array<Object>; constructor(private base: BaseService){} canActivate( next: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean { var session: any = { token: localStorage.getItem('abc') }; this.base.valid(session).subscribe(result => { this.data=result; console

Angular 2+ : canLoad usage

萝らか妹 提交于 2019-12-13 03:01:38
问题 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 compilation I get this : chunk {admin.module} admin.module.chunk.js, admin.module.chunk.js.map () 28 kB {main} {pilotage.module} {suiviprod.module} chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] chunk {main} main.bundle

Guard always return true

空扰寡人 提交于 2019-12-12 07:03:53
问题 I have two pretty similar guards in angular app. First of them checking is User logged in: // isUser guard export class isUser implements CanActivate { constructor( private fireAuth: AngularFireAuth, private router: Router ) {} canActivate( next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree { return this.fireAuth.authState.pipe( take(1), map(authState => !!authState), tap(auth => !auth ? this.router

Angular Guard is not able to access the Angular Service Object

浪尽此生 提交于 2019-12-11 06:37:25
问题 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 Service. In the constructor of that service, I ensure that AuthContext is well set. Through the debug, I have seen that object is available with all the required claims. But then when I access the regular component (which I have guarded through the Auth

How to guard route if HTTP GET request returns no data?

可紊 提交于 2019-12-11 06:05:09
问题 Below is a table in my Angular app. It is populated with data from employees.json : <tbody> <tr *ngFor="let employee of employees"> <td (click)="viewEmployeeProfile(1, employee.id)">{{employee.fullName}} </td> </tr> </tbody> When the user clicks on a name, the employeeId is passed to this method: viewEmployeeProfile(roleId: number, employeeId: number) { this._router.navigate(['/profile', roleId, employeeId]); } Here is the route in my AppRouting module: const routes: Routes = [ { path:

Angular use modal dialog in canDeactivate Guard service for unsubmitted changes (Form dirty)

寵の児 提交于 2019-11-27 21:37:52
In my Angular 4 application I have some components with a form, like this: export class MyComponent implements OnInit, FormComponent { form: FormGroup; ngOnInit() { this.form = new FormGroup({...}); } they use a Guard service to prevent unsubmitted changes to get lost, so if the user tries to change route before it will ask for a confirmation: import { CanDeactivate } from '@angular/router'; import { FormGroup } from '@angular/forms'; export interface FormComponent { form: FormGroup; } export class UnsavedChangesGuardService implements CanDeactivate<FormComponent> { canDeactivate(component: