<commit_before>import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';

import { API_BASE_URL } from './../app.constants';

@Injectable()
export class AuthService {

  constructor(private http: Http) {
  }

  isLoggedIn() {
    return !!this.getToken();
  }

  getToken() {
    return localStorage.getItem('token');
  }

  login(email, password) {
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');

    return this.http.post(
      `${API_BASE_URL}/authenticate`,
      JSON.stringify({ email, password }),
      { headers }
    )
      .map(res => res.json())
      .map(res => {
        let token = res.payload.token;
        if (!token) {
          throw new Error("no token in response");<commit_msg>Handle token expiration<commit_after>import { Injectable } from '@angular/core';
import { Http, Headers } from '@angular/http';
import 'rxjs/add/operator/map';

import { tokenNotExpired } from 'angular2-jwt';

import { API_BASE_URL } from './../app.constants';

@Injectable()
export class AuthService {

  constructor(private http: Http) {
  }

  isLoggedIn() {
    return tokenNotExpired('token');
  }

  getToken() {
    return localStorage.getItem('token');
  }

  login(email, password) {
    let headers = new Headers();
    headers.append('Content-Type', 'application/json');

    return this.http.post(
      `${API_BASE_URL}/authenticate`,
      JSON.stringify({ email, password }),
      { headers }
    )
      .map(res => res.json())
      .map(res => {
        let token = res.payload.token;
        if (!token) {
          throw new Error("no token in response");
{'fraction_non_alphanumeric': 0.15599051008303677, 'fraction_numerical': 0.0005931198102016608, 'mean_word_length': 2.9976303317535544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5877764', 'n_tokens_mistral': 528, 'n_tokens_neox': 524, 'n_words': 119}