import { getRequestHeader, getRequestURL } from 'h3' /** * HTTPS 요청 여부를 판별해 Secure 쿠키 사용 여부를 반환한다. * 운영 환경이라도 HTTP로 접속하면 쿠키가 저장되지 않는 문제를 막는다. * @param {import('h3').H3Event} event - 요청 이벤트 * @returns {boolean} Secure 쿠키 사용 여부 */ export const shouldUseSecureSessionCookie = (event) => { const forwarded = String(getRequestHeader(event, 'x-forwarded-proto') || '') .split(',')[0] .trim() .toLowerCase() if (forwarded) { return forwarded === 'https' } try { return getRequestURL(event).protocol === 'https:' } catch { return false } }