import { serialize } from "cookie" ; import { Cookie } from "../core/lib/cookie" ; export function setCookie ( res , cookie ) { let setCookieHeader = res . getHeader ( "Set-Cookie" ) ?? [ ] ; if ( ! Array . isArray ( setCookieHeader ) ) { setCookieHeader = [ setCookieHeader ] ; } const { name , value , options } = cookie ; const cookieHeader = serialize ( name , value , options ) ; setCookieHeader . push ( cookieHeader ) ; res . setHeader ( "Set-Cookie" , setCookieHeader ) ; } /** Extract the host from the environment */ export function detectHost ( forwardedHost ) { if ( process . env . VERCEL ) return forwardedHost ; return process . env . NEXTAUTH_URL ; }