From 12d9d5255529ea5bba814bd1ce09e96fc75e2064 Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Wed, 8 Aug 2018 11:30:59 +0530 Subject: [PATCH] self.js: delete invalid cookie before redirecting --- frontend/js/self.js | 6 ++++++ frontend/js/utils.js | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/frontend/js/self.js b/frontend/js/self.js index 09751db..395aaf1 100644 --- a/frontend/js/self.js +++ b/frontend/js/self.js @@ -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; } diff --git a/frontend/js/utils.js b/frontend/js/utils.js index bd0c2c8..849dec8 100644 --- a/frontend/js/utils.js +++ b/frontend/js/utils.js @@ -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);