-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2663b7
commit 84e2024
Showing
8 changed files
with
57 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { CanActivateRoutes } from './can-activate-routes.guard'; | ||
|
||
describe('CanActivateRoutes', () => { | ||
it('should create an instance', () => { | ||
expect(new CanActivateRoutes()).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { AuthService } from './auth.service'; | ||
import { Router, CanActivate } from '@angular/router'; | ||
import { Observable } from 'rxjs'; | ||
|
||
@Injectable() | ||
export class CanActivateRoutesGuard implements CanActivate { | ||
constructor(private authService: AuthService, private router: Router) {} | ||
|
||
public canActivate(): Observable<boolean> | Promise<boolean> | boolean { | ||
if (!this.authService.isSignedIn()) { | ||
this.router.navigate(['/login']); | ||
return false; | ||
} | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { AuthService } from '../auth.service'; | ||
|
||
@Component({ | ||
selector: 'app-navbar', | ||
templateUrl: './navbar.component.html', | ||
styleUrls: ['./navbar.component.css'] | ||
}) | ||
export class NavbarComponent implements OnInit { | ||
constructor(private authService: AuthService) {} | ||
|
||
constructor() { } | ||
ngOnInit() {} | ||
|
||
ngOnInit() { | ||
isSignedIn() { | ||
return this.authService.isSignedIn(); | ||
} | ||
|
||
doSignOut() { | ||
this.authService.signOut(); | ||
} | ||
} |