Przeglądaj źródła

remove moment because too big

pull/342/head
Guillaume Vincent 8 lat temu
rodzic
commit
12ef523d8c
5 zmienionych plików z 613 dodań i 4862 usunięć
  1. +587
    -4831
      dist/lesspass.js
  2. +18
    -20
      dist/lesspass.min.js
  3. +0
    -1
      package.json
  4. +5
    -6
      src/api/token.js
  5. +3
    -4
      test/token.js

+ 587
- 4831
dist/lesspass.js
Plik diff jest za duży
Wyświetl plik


+ 18
- 20
dist/lesspass.min.js
Plik diff jest za duży
Wyświetl plik


+ 0
- 1
package.json Wyświetl plik

@@ -18,7 +18,6 @@
"jwt-decode": "^2.1.0",
"lesspass": "^5.1.0",
"lodash.debounce": "^4.0.8",
"moment": "^2.15.2",
"tldjs": "^1.7.0",
"vue": "^2.0.3",
"vue-router": "^2.0.1",


+ 5
- 6
src/api/token.js Wyświetl plik

@@ -1,4 +1,3 @@
import moment from 'moment';
import jwtDecode from 'jwt-decode';

export const TOKEN_KEY = 'jwt';
@@ -8,7 +7,7 @@ export default class Token {
this.name = tokenName
}

stillValid(now = moment()) {
stillValid(now = new Date()) {
try {
return this._expirationDateSuperiorTo(now);
}
@@ -17,9 +16,9 @@ export default class Token {
}
}

expiresIn(duration, unit, now = moment()) {
expiresInMinutes(minutes, now = new Date()) {
try {
const nowPlusDuration = now.add(duration, moment.normalizeUnits(unit));
const nowPlusDuration = new Date(now.getTime() + minutes*60000);
return this._expirationDateInferiorTo(nowPlusDuration);
}
catch (err) {
@@ -29,7 +28,7 @@ export default class Token {

_expirationDateInferiorTo(date) {
const expireDate = this._getTokenExpirationDate();
return expireDate.diff(date) < 0;
return expireDate < date;
}

_expirationDateSuperiorTo(date) {
@@ -38,6 +37,6 @@ export default class Token {

_getTokenExpirationDate() {
const decodedToken = jwtDecode(this.name);
return moment(decodedToken.exp * 1000);
return new Date(decodedToken.exp * 1000);
}
}

+ 3
- 4
test/token.js Wyświetl plik

@@ -1,11 +1,10 @@
import test from 'ava';
import moment from 'moment';
import Token from '../src/api/token';

test('token is near the end', t => {
const token = new Token('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MzcwMTg1ODIsImV4cCI6MTQzNzAxODU4M30.NmMv7sXjM1dW0eALNXud8LoXknZ0mH14GtnFclwJv0s');
t.true(token.expiresIn(15, 'minutes', moment(1437018283 * 1000)));
t.false(token.expiresIn(5, 'minutes', moment(1437018283 * 1000)));
t.true(token.expiresInMinutes(15, new Date(1437018283 * 1000)));
t.false(token.expiresInMinutes(5, new Date(1437018283 * 1000)));
});

test('token still valid', t => {
@@ -15,7 +14,7 @@ test('token still valid', t => {

test('token still valid check payload date', t => {
const token = new Token('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmb28iOiJiYXIiLCJpYXQiOjE0MzcwMTg1ODIsImV4cCI6MTQzNzAxODU4M30.NmMv7sXjM1dW0eALNXud8LoXknZ0mH14GtnFclwJv0s');
t.true(token.stillValid(moment(1437018283 * 1000)));
t.true(token.stillValid(new Date(1437018283 * 1000)));
});

test('token expired', t => {


Ładowanie…
Anuluj
Zapisz