File tree Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Expand file tree Collapse file tree 3 files changed +40
-2
lines changed Original file line number Diff line number Diff line change 24
24
" styles.css"
25
25
],
26
26
"scripts" : [
27
- " ../node_modules/jquery/dist/jquery.min.js"
27
+ " ../node_modules/jquery/dist/jquery.min.js" ,
28
+ " ../node_modules/bootstrap/dist/js/bootstrap.min.js"
28
29
],
29
30
"environmentSource" : " environments/environment.ts" ,
30
31
"environments" : {
Original file line number Diff line number Diff line change @@ -2,11 +2,26 @@ import { Injectable } from '@angular/core';
2
2
import { CanActivate , ActivatedRouteSnapshot , RouterStateSnapshot } from '@angular/router' ;
3
3
import { Observable } from 'rxjs/Observable' ;
4
4
5
+ import { AuthService } from './auth.service' ;
6
+ import { Router } from '@angular/router' ;
7
+
5
8
@Injectable ( )
6
9
export class AuthGuard implements CanActivate {
10
+
11
+ constructor (
12
+ private authService : AuthService ,
13
+ private router : Router
14
+ ) { }
15
+
7
16
canActivate (
8
17
next : ActivatedRouteSnapshot ,
9
18
state : RouterStateSnapshot ) : Observable < boolean > | Promise < boolean > | boolean {
19
+
20
+ if ( ! this . authService . isLoggedIn ) {
21
+ this . router . navigate ( [ '/home' ] ) ;
22
+ return false ;
23
+ }
24
+
10
25
return true ;
11
26
}
12
27
}
Original file line number Diff line number Diff line change 1
1
import { Injectable } from '@angular/core' ;
2
+ import { environment } from './../../environments/environment' ;
3
+ import { Router } from '@angular/router' ;
2
4
3
5
@Injectable ( )
4
6
export class AuthService {
5
7
6
- constructor ( ) { }
8
+ authenticated : boolean ;
7
9
10
+ constructor ( private router : Router ) {
11
+ this . checkIfLoggedin ( ) ;
12
+ }
13
+
14
+ //let options = new RequestOptions({ headers: headers, withCredentials: true });
15
+ //this.http.post(this.connectUrl, <stringified_data> , options)
16
+
17
+ checkIfLoggedin ( ) {
18
+ //ask api
19
+ //to-do use environment.apiUrl+'/isLoggedIn' returns yes, no
20
+ this . authenticated = false ;
21
+ }
22
+
23
+ get isLoggedIn ( ) : boolean {
24
+ // Check if current date is greater
25
+ // than expiration and user is logged in
26
+ //const expiresAt = JSON.parse(localStorage.getItem('expires_at'));
27
+ //return Date.now() < expiresAt && this.authenticated;
28
+ return this . authenticated ;
29
+ }
8
30
}
You can’t perform that action at this time.
0 commit comments