Created
March 1, 2021 17:51
-
-
Save Ethaan/bbcce08106e5e6c68f6fe10f69bc4468 to your computer and use it in GitHub Desktop.
Login user on NextJS using pages/api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment