Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F61563453
auth.guard.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, May 7, 11:37
Size
869 B
Mime Type
text/x-java
Expires
Thu, May 9, 11:37 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
17528719
Attached To
rDDJUDGECLIENT JudgeMyRace Client
auth.guard.ts
View Options
import { Injectable } from '@angular/core';
import { Router, CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { AuthenticationService } from '../_services';
// Authentication guard -> manage authentication and redirect if not connected
@Injectable({ providedIn: 'root' })
export class AuthGuard implements CanActivate {
constructor(
private router: Router,
private authenticationService: AuthenticationService
) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const currentUser = this.authenticationService.currentUserValue;
if (currentUser) {
// authorised so return true
return true;
}
// not logged in so redirect to login page with the return url
this.router.navigate(['/login'], { queryParams: { returnUrl: state.url }});
return false;
}
}
Event Timeline
Log In to Comment