Skip to content

Instantly share code, notes, and snippets.

@jermsam
Last active June 10, 2020 21:29
Show Gist options
  • Save jermsam/f6b6ca47a903179d53e5b0c04c81e096 to your computer and use it in GitHub Desktop.
Save jermsam/f6b6ca47a903179d53e5b0c04c81e096 to your computer and use it in GitHub Desktop.
logout http only nextApiResponse
import { NextApiRequest, NextApiResponse, } from "next"
import {serialize} from 'cookie'
export default async (req:NextApiRequest, res:NextApiResponse) => {
res.statusCode = 200
console.log(req.statusCode)
if(req.method==='POST'){
res.setHeader('Set-Cookie',serialize('auth','',{
httpOnly:true,
secure:process.env.NODE_ENV!=='development',
sameSite:'strict',
maxAge:0,
path:'/'
}))
// res.json({authToken})
res.json({message:'You are logged out'})
}else{
res.status(405).json('We only support POST')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment