Skip to content

Commit 5657d8c

Browse files
auth guard moved to auth folder
1 parent 7376b0c commit 5657d8c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { TestBed } from '@angular/core/testing';
2+
import { CanMatchFn } from '@angular/router';
3+
4+
import { authGuard } from './auth.guard';
5+
6+
describe('authGuard', () => {
7+
const executeGuard: CanMatchFn = (...guardParameters) =>
8+
TestBed.runInInjectionContext(() => authGuard(...guardParameters));
9+
10+
beforeEach(() => {
11+
TestBed.configureTestingModule({});
12+
});
13+
14+
it('should be created', () => {
15+
expect(executeGuard).toBeTruthy();
16+
});
17+
});

src/app/auth/_guards/auth.guard.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
import { inject } from '@angular/core';
22
import { CanMatchFn, Router } from '@angular/router';
3+
<<<<<<< HEAD
34
import { AuthService } from '../auth.service';
45
import { Roles } from '../../shared/_enums/roles';
6+
=======
7+
import { Observable } from 'rxjs';
8+
import { map, take } from 'rxjs/operators';
9+
import { AuthService } from '../auth.service';
10+
>>>>>>> 2ca65a2 (auth guard moved to auth folder)
511

612
export const authGuard: CanMatchFn = (): boolean => {
713
const authService = inject(AuthService);
814
const router = inject(Router);
15+
<<<<<<< HEAD
916

1017
if (authService.user$()?.roles?.includes(Roles.ADMIN)) {
18+
=======
19+
console.log('GUARD', authService.isAdmin$());
20+
if (authService.isAdmin$()) {
21+
>>>>>>> 2ca65a2 (auth guard moved to auth folder)
1122
return true;
1223
} else {
1324
router.navigate(['/posts']);
1425
return false;
1526
}
27+
<<<<<<< HEAD
28+
=======
29+
30+
>>>>>>> 2ca65a2 (auth guard moved to auth folder)
1631
};

0 commit comments

Comments
 (0)