Last active
June 10, 2020 21:29
-
-
Save jermsam/f6b6ca47a903179d53e5b0c04c81e096 to your computer and use it in GitHub Desktop.
logout http only nextApiResponse
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 { 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