(Hopefully) better (cleaner) authentication mechanism now
[vchess.git] / client / src / utils / cookie.js
index b051844..57e8668 100644 (file)
@@ -1,22 +1,22 @@
 // Source: https://www.quirksmode.org/js/cookies.html
-export function setCookie(name, value)
-{
-  var date = new Date();
-  date.setTime(date.getTime()+(183*24*60*60*1000)); //6 months
-  var expires = "; expires="+date.toGMTString();
-  document.cookie = name+"="+value+expires+"; path=/";
+export function setCookie(name, value) {
+  const date = new Date();
+  date.setTime(date.getTime() + 183 * 24 * 60 * 60 * 1000); //6 months
+  const expires = "; expires=" + date.toGMTString();
+  document.cookie = name + "=" + value + expires + "; path=/;";
 }
 
 export function getCookie(name, defaut) {
-  var nameEQ = name + "=";
-  var ca = document.cookie.split(';');
-  for (var i=0;i < ca.length;i++)
-  {
-    var c = ca[i];
-    while (c.charAt(0)==' ')
-      c = c.substring(1,c.length);
-    if (c.indexOf(nameEQ) == 0)
-      return c.substring(nameEQ.length,c.length);
+  const nameEQ = name + "=";
+  const ca = document.cookie.split(";");
+  for (let i = 0; i < ca.length; i++) {
+    let c = ca[i];
+    while (c.charAt(0) == " ") c = c.substring(1, c.length);
+    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
   }
   return defaut; //cookie not found
 }
+
+export function delCookie(name) {
+  document.cookie = name + "=; Max-Age=-1;";
+}