File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed
apps/angular/6-structural-directive/src/app/guards Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { TestBed } from '@angular/core/testing' ;
2
+ import { CanActivateFn } from '@angular/router' ;
3
+
4
+ import { authenticatedGuard } from './authenticated.guard' ;
5
+
6
+ describe ( 'authenticatedGuard' , ( ) => {
7
+ const executeGuard : CanActivateFn = ( ...guardParameters ) =>
8
+ TestBed . runInInjectionContext ( ( ) => authenticatedGuard ( ...guardParameters ) ) ;
9
+
10
+ beforeEach ( ( ) => {
11
+ TestBed . configureTestingModule ( { } ) ;
12
+ } ) ;
13
+
14
+ it ( 'should be created' , ( ) => {
15
+ expect ( executeGuard ) . toBeTruthy ( ) ;
16
+ } ) ;
17
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { inject } from '@angular/core' ;
2
+ import { CanActivateFn , Router } from '@angular/router' ;
3
+ import { UserStore } from '../user.store' ;
4
+
5
+ export const authenticatedGuard : CanActivateFn = ( route , state ) => {
6
+ const userStore = inject ( UserStore ) ;
7
+ const router = inject ( Router ) ;
8
+
9
+ if ( userStore . currentUser ) return true ;
10
+ router . navigate ( [ '/' ] ) . then ( ) ;
11
+ return false ;
12
+ } ;
You can’t perform that action at this time.
0 commit comments