"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createTokenWriter = void 0;

var _milliseconds = _interopRequireDefault(require("milliseconds"));

var _cookie = require("./cookie");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const createTokenWriter = ({
  name = 'token',
  domain
}) => {
  const writeToken = token => {
    (0, _cookie.writeCookie)(name, token, {
      maxAge: _milliseconds.default.days(180),
      secure: true,
      domain
    });
  };

  const readToken = () => (0, _cookie.readCookie)(name);

  const clearToken = () => (0, _cookie.deleteCookie)(name, domain);

  return {
    writeToken,
    readToken,
    clearToken
  };
};

exports.createTokenWriter = createTokenWriter;