Skip to content

Cookies


parseCookies

Parse the request to get HTTP Cookie header string and returning an object of all cookie name-value pairs.

ts
import { eventHandler, parseCookies } from "vinxi/http"

export default eventHandler(async (event) => {
  const cookies = parseCookies(event) 

  cookies["authorization"] // "*******"
})
Signature
ts
export function parseCookies(event: HTTPEvent): Record<string, string>

getCookie

Get a cookie value by name.

ts
import { eventHandler, getCookie } from "vinxi/http"

export default eventHandler(async (event) => {
  const authorization = getCookie(event, "Authorization") //
  if (authorization) {
    // ...
  }
})
Signature
ts
export function getCookie(event: HTTPEvent, name: string): string | undefined

setCookie

Set a cookie value by name.

ts
import { eventHandler, setCookie } from "vinxi/http"

export default eventHandler(async (event) => {
  setCookie(event, "Authorization", "1234567") 
})
Signature
ts
export function setCookie(
  event: HTTPEvent,
  name: string,
  value: string,
  serializeOptions?: CookieSerializeOptions,
): void

deleteCookie

Delete a cookie by name

Signature
ts
export function deleteCookie(
  event: HTTPEvent,
  name: string,
  serializeOptions?: CookieSerializeOptions,
): void