File tree Expand file tree Collapse file tree 8 files changed +22
-116
lines changed Expand file tree Collapse file tree 8 files changed +22
-116
lines changed Original file line number Diff line number Diff line change 1- import { Injectable , inject } from '@angular/core' ;
2- import { ActivatedRouteSnapshot , Router , UrlTree } from '@angular/router' ;
1+ import { Injectable } from '@angular/core' ;
2+ import { ActivatedRouteSnapshot , UrlTree } from '@angular/router' ;
33import { Observable } from 'rxjs' ;
44
55import { BaseAuth } from 'src/app/auth/guards/base-auth' ;
6- import { AuthenticationService } from 'src/app/auth/services' ;
76
87@Injectable ( {
98 providedIn : 'root' ,
109} )
1110export class AnonymousGuard extends BaseAuth {
12- protected readonly router : Router = inject ( Router ) ;
13- protected readonly authenticationService : AuthenticationService = inject ( AuthenticationService ) ;
14-
15- /**
16- * Constructor of the class, where we DI all services that we need to use
17- * within this guard.
18- */
19- public constructor ( ) {
20- const router : Router = inject ( Router ) ;
21- const authenticationService : AuthenticationService = inject ( AuthenticationService ) ;
22-
23- super ( router , authenticationService ) ;
24- }
25-
2611 /**
2712 * Purpose of this guard is check that current user has not been authenticated
2813 * to application. If user is authenticated he/she is redirected to application
Original file line number Diff line number Diff line change 1- import { Injectable , inject } from '@angular/core' ;
2- import { ActivatedRouteSnapshot , Router , UrlTree } from '@angular/router' ;
1+ import { Injectable } from '@angular/core' ;
2+ import { ActivatedRouteSnapshot , UrlTree } from '@angular/router' ;
33import { Observable } from 'rxjs' ;
44
55import { BaseAuth } from 'src/app/auth/guards/base-auth' ;
6- import { AuthenticationService } from 'src/app/auth/services' ;
76
87@Injectable ( {
98 providedIn : 'root' ,
109} )
1110export class AuthenticationGuard extends BaseAuth {
12- protected readonly router : Router = inject ( Router ) ;
13- protected readonly authenticationService : AuthenticationService = inject ( AuthenticationService ) ;
14-
15- /**
16- * Constructor of the class, where we DI all services that we need to use
17- * within this guard.
18- */
19- public constructor ( ) {
20- const router : Router = inject ( Router ) ;
21- const authenticationService : AuthenticationService = inject ( AuthenticationService ) ;
22-
23- super ( router , authenticationService ) ;
24- }
25-
2611 /**
2712 * Purpose of this guard is check that current user has been authenticated to
2813 * application. If user is not authenticated he/she is redirected to application
Original file line number Diff line number Diff line change 1+ import { inject } from '@angular/core' ;
12import { Router , UrlTree } from '@angular/router' ;
23import { Observable } from 'rxjs' ;
34import { map , take } from 'rxjs/operators' ;
@@ -6,20 +7,17 @@ import { AuthGuardMetaDataInterface } from 'src/app/auth/interfaces';
67import { AuthenticationService } from 'src/app/auth/services' ;
78
89export abstract class BaseAuth {
9- /**
10- * Constructor of the class. This is called from classes that extends this
11- * abstract class.
12- */
13- protected constructor ( protected router : Router , protected authenticationService : AuthenticationService ) { }
10+ private readonly router : Router = inject ( Router ) ;
11+ private readonly authenticationService : AuthenticationService = inject ( AuthenticationService ) ;
1412
1513 /**
1614 * Helper method to make check if user needs to be authenticated or not. This
1715 * is used from following guards:
1816 * - AnonymousGuard
1917 * - AuthenticationGuard
2018 *
21- * By default this method will redirect user either to `/` or `/auth/login`
22- * depending if user needs to be authenticated or not.
19+ * By default, this method will redirect user either to `/` or `/auth/login`
20+ * depending on if user needs to be authenticated or not.
2321 *
2422 * You can override this behaviour by setting `data` option to your route
2523 * definition where you can configure following;
Original file line number Diff line number Diff line change 1+ import { inject } from '@angular/core' ;
12import { Router , UrlTree } from '@angular/router' ;
23import { Store } from '@ngrx/store' ;
34import { Observable } from 'rxjs' ;
@@ -7,11 +8,8 @@ import { RoleGuardMetaDataInterface } from 'src/app/auth/interfaces';
78import { authenticationSelectors } from 'src/app/store' ;
89
910export abstract class BaseRole {
10- /**
11- * Constructor of the class. This is called from classes that extends this
12- * abstract class.
13- */
14- protected constructor ( protected router : Router , protected store : Store ) { }
11+ private readonly router : Router = inject ( Router ) ;
12+ private readonly store : Store = inject ( Store ) ;
1513
1614 /**
1715 * Helper method to make check if user has certain role or not. This is used
@@ -21,8 +19,8 @@ export abstract class BaseRole {
2119 * - RoleRootGuard
2220 * - RoleUserGuard
2321 *
24- * By default this method will redirect user either to `/` or `/auth/login`
25- * depending if user is not logged in or user doesn't have the specified
22+ * By default, this method will redirect user either to `/` or `/auth/login`
23+ * depending on if user is not logged in or user doesn't have the specified
2624 * role.
2725 *
2826 * You can override this behaviour by setting `data` option to your route
Original file line number Diff line number Diff line change 1- import { Injectable , inject } from '@angular/core' ;
2- import { ActivatedRouteSnapshot , Router , UrlTree } from '@angular/router' ;
3- import { Store } from '@ngrx/store' ;
1+ import { Injectable } from '@angular/core' ;
2+ import { ActivatedRouteSnapshot , UrlTree } from '@angular/router' ;
43import { Observable } from 'rxjs' ;
54
65import { Role } from 'src/app/auth/enums' ;
@@ -10,20 +9,6 @@ import { BaseRole } from 'src/app/auth/guards/base-role';
109 providedIn : 'root' ,
1110} )
1211export class RoleAdminGuard extends BaseRole {
13- protected readonly router : Router = inject ( Router ) ;
14- protected readonly store : Store = inject ( Store ) ;
15-
16- /**
17- * Constructor of the class, where we DI all services that we need to use
18- * within this guard.
19- */
20- public constructor ( ) {
21- const router : Router = inject ( Router ) ;
22- const store : Store = inject ( Store ) ;
23-
24- super ( router , store ) ;
25- }
26-
2712 /**
2813 * Purpose of this guard is to check that user has `Role.ROLE_ADMIN` or not.
2914 * This method is used within route definition `canActivate` definition.
Original file line number Diff line number Diff line change 1- import { Injectable , inject } from '@angular/core' ;
2- import { ActivatedRouteSnapshot , Router , UrlTree } from '@angular/router' ;
3- import { Store } from '@ngrx/store' ;
1+ import { Injectable } from '@angular/core' ;
2+ import { ActivatedRouteSnapshot , UrlTree } from '@angular/router' ;
43import { Observable } from 'rxjs' ;
54
65import { Role } from 'src/app/auth/enums' ;
@@ -10,20 +9,6 @@ import { BaseRole } from 'src/app/auth/guards/base-role';
109 providedIn : 'root' ,
1110} )
1211export class RoleALoggedGuard extends BaseRole {
13- protected readonly router : Router = inject ( Router ) ;
14- protected readonly store : Store = inject ( Store ) ;
15-
16- /**
17- * Constructor of the class, where we DI all services that we need to use
18- * within this guard.
19- */
20- public constructor ( ) {
21- const router : Router = inject ( Router ) ;
22- const store : Store = inject ( Store ) ;
23-
24- super ( router , store ) ;
25- }
26-
2712 /**
2813 * Purpose of this guard is to check that user has `Role.ROLE_LOGGED` or not.
2914 * This method is used within route definition `canActivate` definition.
Original file line number Diff line number Diff line change 1- import { Injectable , inject } from '@angular/core' ;
2- import { ActivatedRouteSnapshot , Router , UrlTree } from '@angular/router' ;
3- import { Store } from '@ngrx/store' ;
1+ import { Injectable } from '@angular/core' ;
2+ import { ActivatedRouteSnapshot , UrlTree } from '@angular/router' ;
43import { Observable } from 'rxjs' ;
54
65import { Role } from 'src/app/auth/enums' ;
@@ -10,20 +9,6 @@ import { BaseRole } from 'src/app/auth/guards/base-role';
109 providedIn : 'root' ,
1110} )
1211export class RoleRootGuard extends BaseRole {
13- protected readonly router : Router = inject ( Router ) ;
14- protected readonly store : Store = inject ( Store ) ;
15-
16- /**
17- * Constructor of the class, where we DI all services that we need to use
18- * within this guard.
19- */
20- public constructor ( ) {
21- const router : Router = inject ( Router ) ;
22- const store : Store = inject ( Store ) ;
23-
24- super ( router , store ) ;
25- }
26-
2712 /**
2813 * Purpose of this guard is to check that user has `Role.ROLE_ROOT` or not.
2914 * This method is used within route definition `canActivate` definition.
Original file line number Diff line number Diff line change 1- import { Injectable , inject } from '@angular/core' ;
2- import { ActivatedRouteSnapshot , Router , UrlTree } from '@angular/router' ;
3- import { Store } from '@ngrx/store' ;
1+ import { Injectable } from '@angular/core' ;
2+ import { ActivatedRouteSnapshot , UrlTree } from '@angular/router' ;
43import { Observable } from 'rxjs' ;
54
65import { Role } from 'src/app/auth/enums' ;
@@ -10,20 +9,6 @@ import { BaseRole } from 'src/app/auth/guards/base-role';
109 providedIn : 'root' ,
1110} )
1211export class RoleUserGuard extends BaseRole {
13- protected readonly router : Router = inject ( Router ) ;
14- protected readonly store : Store = inject ( Store ) ;
15-
16- /**
17- * Constructor of the class, where we DI all services that we need to use
18- * within this guard.
19- */
20- public constructor ( ) {
21- const router : Router = inject ( Router ) ;
22- const store : Store = inject ( Store ) ;
23-
24- super ( router , store ) ;
25- }
26-
2712 /**
2813 * Purpose of this guard is to check that user has `Role.ROLE_USER` or not.
2914 * This method is used within route definition `canActivate` definition.
You can’t perform that action at this time.
0 commit comments