set cookie properly

dev
Anton Franzluebbers 2021-10-19 23:47:25 -04:00
parent 00ae355cf1
commit 68e84b07c6
2 changed files with 9 additions and 1 deletions

View File

@ -31,6 +31,14 @@ function httpPostAsync(theUrl, data, callback, failCallback) {
xmlHttp.send(JSON.stringify(data)); 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) { function getCookie(cname) {
let name = cname + "="; let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie); let decodedCookie = decodeURIComponent(document.cookie);

View File

@ -78,7 +78,7 @@
console.log(resp); console.log(resp);
let respData = JSON.parse(resp); let respData = JSON.parse(resp);
if (respData['hw_id'] != '') { if (respData['hw_id'] != '') {
document.cookie = "hw_id=" + respData['hw_id'] + "; SameSite=None; Secure"; setCookie('hw_id', respData['hw_id'], 60);
window.location.href = "/"; window.location.href = "/";
} }
}, (status) => { }, (status) => {