From 68e84b07c6a94e278c9a9123d10d052e6a7b897a Mon Sep 17 00:00:00 2001 From: Anton Franzluebbers Date: Tue, 19 Oct 2021 23:47:25 -0400 Subject: [PATCH] set cookie properly --- velconnect/static/js/util.js | 8 ++++++++ velconnect/templates/pair.jinja | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/velconnect/static/js/util.js b/velconnect/static/js/util.js index fda7514..8580903 100644 --- a/velconnect/static/js/util.js +++ b/velconnect/static/js/util.js @@ -31,6 +31,14 @@ function httpPostAsync(theUrl, data, callback, failCallback) { xmlHttp.send(JSON.stringify(data)); } +function setCookie(cname, cvalue, exdays) { + const d = new Date(); + d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); + let expires = "expires=" + d.toUTCString(); + document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; +} + + function getCookie(cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); diff --git a/velconnect/templates/pair.jinja b/velconnect/templates/pair.jinja index 1655050..9efee2d 100644 --- a/velconnect/templates/pair.jinja +++ b/velconnect/templates/pair.jinja @@ -78,7 +78,7 @@ console.log(resp); let respData = JSON.parse(resp); if (respData['hw_id'] != '') { - document.cookie = "hw_id=" + respData['hw_id'] + "; SameSite=None; Secure"; + setCookie('hw_id', respData['hw_id'], 60); window.location.href = "/"; } }, (status) => {