Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //api.service.ts
- import { Injectable } from '@angular/core';
- import { Router } from '@angular/router';
- @Injectable({
- providedIn: 'root'
- })
- export class ApiService {
- router: Router
- constructor(router: Router) {
- this.router = router
- }
- public isLoggedIn():boolean {
- let token = localStorage.getItem('forum-token')
- // TODO check expiration date etc.
- let tokenExpireString = localStorage.getItem('forum-token-expiration')
- return token !== null
- }
- public canActivate():boolean{
- if(!this.isLoggedIn()){
- this.router.navigate(['/login'])
- return false;
- }
- return true;
- }
- //private tokenExpired(token: string) {
- //const expiry = (JSON.parse(atob(token.split('.')[1]))).exp;
- //const expiry = token;
- //return (Math.floor((new Date).getTime() / 1000)) >= expiry;
- //}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement