import { SessionClient } from "../../clients" ; import { LeaveRequest } from "../../common" ; import { parseTokenFromHeader , resetTokenCookie } from "../../utilities" ; import { handler } from "../_" ; import schema = require ( "../../common/events/leave/index.json" ) ; param event return export const post = handler < { } , LeaveRequest > ( schema , async ( { headers } ) => { const token = parseTokenFromHeader ( headers . Authorization ) ; try { const session = new SessionClient ( token ) ; await session . signOut ( ) ; return { headers : { "Set-Cookie" : resetTokenCookie ( ) } } ; } catch ( err ) { err . code = err . code || err . name ; return { statusCode : err . statusCode || 400 , body : { type : err . code , message : err . message . replace ( /\.$/ , "" ) } , headers : { "Set-Cookie" : resetTokenCookie ( ) } } ; } } ) ;