import { serialize } from 'cookie';

export default async function cookieHandler(req, res) {
  const { method } = req;
  if (method === 'POST') {
    const body = JSON.parse(req.body);
    if (body.token) {
      res.setHeader(
        'Set-Cookie',
        serialize('gfw-token', body.token, {
          path: '/',
          httpOnly: true,
          maxAge: 2592000,
        })
      );
      res.status(200).end('ok');
    }
  } else if (method === 'GET') {
    res.setHeader(
      'Set-Cookie',
      serialize('gfw-token', '', { path: '/', maxAge: -1 })
    );
    res.status(200).end('ok');
  } else {
    res.setHeader('Allow', ['POST', 'GET']);
    res.status(405).end(`Method ${method} Not Allowed`);
  }

  res.status(405).end('');
}

import { serialize } from 'cookie';

export default async function cookieHandler(req, res) {
  const { method } = req;
  if (method === 'POST') {
    const body = JSON.parse(req.body);
    if (body.token) {
      res.setHeader(
        'Set-Cookie',
        serialize('gfw-token', body.token, {
          path: '/',
          httpOnly: true,
          maxAge: 315360000,
        })
      );
      res.status(200).end('ok');
    }
  } else if (method === 'GET') {
    res.setHeader(
      'Set-Cookie',
      serialize('gfw-token', '', { path: '/', maxAge: -1 })
    );
    res.status(200).end('ok');
  } else {
    res.setHeader('Allow', ['POST', 'GET']);
    res.status(405).end(`Method ${method} Not Allowed`);
  }

  res.status(405).end('');
}

--- 
+++ 
@@ -10,7 +10,7 @@
         serialize('gfw-token', body.token, {
           path: '/',
           httpOnly: true,
-          maxAge: 315360000,
+          maxAge: 2592000,
         })
       );
       res.status(200).end('ok');
Change Cookie expiration to 30 days
