'use strict';

const uuidv4 = require('uuid/v4');

// TODO init that sets cookie name?

const sessionIdent = 'tiny-ident';

const get = (req, res) => {
  let uuid;

  if ((req.cookies || {})[sessionIdent]) {
    uuid = req.cookies[sessionIdent];
  } else {
    // generate unique session-id
    uuid = uuidv4();
  }

  set(res, uuid);

  return uuid;
};

// TODO: update cookie expire-time when used

const set = (res, uuid) => {
  // maxAge = one year from now.
  const maxAge = 1000 * 60 * 60 * 24 * 365;

  // Date object set at one year from now.
  const expires = new Date();
  expires.setFullYear(expires.getFullYear() + 1);

  if (res.cookie) {
    res.cookie(sessionIdent, uuid, {
      httpOnly: true,
      expires: expires,
      maxAge: maxAge
    });
  }
};

module.exports = {
  get
};

@@ -315,17 +315,28 @@
 %7D%0A%0A  set
-(
+Cookie(req, 
 res, uui
@@ -363,54 +363,8 @@
 %7D;%0A%0A
-// TODO: update cookie expire-time when used%0A%0A
 cons
@@ -368,20 +368,31 @@
 onst set
+Cookie
  = (
+req, 
 res, uui
@@ -399,16 +399,49 @@
 d) =%3E %7B%0A
+  console.log(req.get('host'));%0A%0A
   // max
@@ -691,16 +691,47 @@
 uuid, %7B%0A
+      domain: req.get('host'),%0A
       ht
@@ -788,16 +788,42 @@
 : maxAge
+,%0A      sameSite: 'strict'
 %0A    %7D);

Make cookie a little more robust