Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit e7272c0

Browse files
committed
Fixes #76 by safely handing missing expiries in localstorage
1 parent b0a5f66 commit e7272c0

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/idle/idle.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
119119
function getExpiry() {
120120
var obj = LocalStorage.get('expiry');
121121

122-
return new Date(obj.time);
122+
return obj && obj.time ? new Date(obj.time) : null;
123123
}
124124

125125
function setExpiry(date) {
@@ -148,7 +148,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
148148
},
149149
isExpired: function() {
150150
var expiry = getExpiry();
151-
return expiry && expiry <= this._getNow();
151+
return expiry !== null && expiry <= this._getNow();
152152
},
153153
running: function() {
154154
return state.running;

src/idle/idle.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,10 @@ describe('ngIdle', function() {
342342
expect(Idle.isExpired()).toBe(true);
343343
});
344344

345+
it ('isExpired() should return false if there is no expiry yet', function() {
346+
expect(Idle.isExpired()).toBe(false);
347+
});
348+
345349
it ('interrupt() should broadcast $timeout if running and past expiry', function() {
346350
spyOn($rootScope, '$broadcast');
347351

0 commit comments

Comments
 (0)