self.js: delete invalid cookie before redirecting

This commit is contained in:
Adhityaa Chandrasekar 2018-08-08 11:30:59 +05:30
parent c71d634e82
commit 12d9d52555
2 changed files with 12 additions and 0 deletions

View File

@ -6,8 +6,14 @@
"ownerToken": global.cookieGet("commentoOwnerToken"),
};
if (json.ownerToken === undefined) {
document.location = "/login";
return;
}
global.post(global.commentoOrigin + "/api/owner/self", json, function(resp) {
if (!resp.success || !resp.loggedIn) {
global.cookieDelete("commentoOwnerToken");
document.location = "/login";
return;
}

View File

@ -75,6 +75,12 @@
}
// Deletes a cookie.
global.cookieDelete = function(name) {
document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
// Converts a date in the past to a human-friendly duration relative to now.
global.timeSince = function(date) {
var seconds = Math.floor((new Date() - date) / 1000);