Skip to content

Instantly share code, notes, and snippets.

@Ethaan
Created March 1, 2021 17:51
Show Gist options
  • Select an option

  • Save Ethaan/bbcce08106e5e6c68f6fe10f69bc4468 to your computer and use it in GitHub Desktop.

Select an option

Save Ethaan/bbcce08106e5e6c68f6fe10f69bc4468 to your computer and use it in GitHub Desktop.

Revisions

  1. Ethaan created this gist Mar 1, 2021.
    23 changes: 23 additions & 0 deletions register.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    import cookie from 'cookie';

    // types
    import type { NextApiResponse, NextApiRequest } from 'next';

    // mocks
    import { mockUser } from 'mocks/user';

    const handler = (req: NextApiRequest, res: NextApiResponse) => {
    if (req.method === 'POST') {
    res.setHeader(
    'Set-Cookie',
    cookie.serialize('token', '123456', {
    httpOnly: true,
    })
    );
    return res.status(200).json(mockUser());
    } else {
    return res.status(500).send('Weirdo');
    }
    };

    export default handler;