Implements

Constructors

Properties

Methods

Constructors

Properties

#private: any

Methods

  • Astro.cookies.delete(key) is used to delete a cookie. Using this method will result in a Set-Cookie header added to the response.

    Parameters

    • key: string

      The cookie to delete

    • Optional options: AstroCookieDeleteOptions

      Options related to this deletion, such as the path of the cookie.

    Returns void

  • Astro.cookies.get(key) is used to get a cookie value. The cookie value is read from the request. If you have set a cookie via Astro.cookies.set(key, value), the value will be taken from that set call, overriding any values already part of the request.

    Parameters

    Returns undefined | AstroCookie

    An object containing the cookie value as well as convenience methods for converting its value.

  • Astro.cookies.has(key) returns a boolean indicating whether this cookie is either part of the initial request or set via Astro.cookies.set(key)

    Parameters

    Returns boolean

  • Astro.cookies.header() returns an iterator for the cookies that have previously been set by either Astro.cookies.set() or Astro.cookies.delete(). This method is primarily used by adapters to set the header on outgoing responses.

    Returns Generator<string, void, unknown>

  • Astro.cookies.set(key, value) is used to set a cookie's value. If provided an object it will be stringified via JSON.stringify(value). Additionally you can provide options customizing how this cookie will be set, such as setting httpOnly in order to prevent the cookie from being read in client-side JavaScript.

    Parameters

    • key: string

      The name of the cookie to set.

    • value: string | Record<string, any>

      A value, either a string or other primitive or an object.

    • Optional options: AstroCookieSetOptions

      Options for the cookie, such as the path and security settings.

    Returns void

  • Behaves the same as AstroCookies.prototype.headers(), but allows a warning when cookies are set after the instance is consumed.

    Parameters

    Returns Generator<string, void, unknown>