0

i created this cookie in node js:

res.cookie('DKNS', username, {maxAge: 10000 });

but it is created in the browser, but I don't know why it is not deleted after 10 seconds, I want it to be deleted after 10 seconds and once it is deleted it will redirect me to my login route, I have this function in javascript that would serve to check if the cookie exists:

function checkCookie(){                              
 if(document.cookie.indexOf("DKNS") == (-1)) {         
  window.location.replace = "/login";                 
 }
setTimeout(checkCookie, 1000)
}

but it doesn't work can someone help me with this, please?

  • How did you check that your cookie is created in browser? – IvanD Oct 22 '20 at 05:33
  • so it doesn't check, but it was to check why the javascript function is correct. – Leticia Oct 22 '20 at 05:42
  • Look at this answer: https://stackoverflow.com/questions/14176432/cant-set-cookie-expires-or-maxage-in-node-js-using-express-3-0 – G.Vitelli Oct 22 '20 at 09:14
  • yes friend, it is expiring, but now my problem is ,. how will I validate this cookie on the client with my javascript function – Leticia Oct 22 '20 at 16:59

0 Answers0