Documentation
    Preparing search index...

    Cookies serializer is used to serialize a value to be set on the Set-Cookie header. You can encode, sign on encrypt cookies using the serializer and then set them individually using the set-cookie header.

    Index

    Constructors

    Methods

    Constructors

    Methods

    • Encodes value as a plain cookie. By default, the plain value will be converted to a string using "JSON.stringify" method and then encoded as a base64 string.

      You can disable cookie stringifaction by setting options.stringify = false.

       serializer.encode('name', 'virk')
      serializer.encode('name', 'virk', { stringify: false })

      Parameters

      • key: string

        The cookie key

      • value: any

        The value to encode

      • Optionaloptions: Partial<CookieOptions & { encode: boolean; stringify: boolean }>

        Cookie encoding options

      Returns null | string

      The serialized cookie string or null if encoding fails

    • Sign a key-value pair to a signed cookie. The signed value has a verification hash attached to it to detect data tampering.

      Parameters

      • key: string

        The cookie key

      • value: any

        The value to sign

      • Optionaloptions: Partial<CookieOptions>

        Cookie options

      Returns null | string

      The serialized signed cookie string or null if signing fails

    • Encrypts a key-value pair to an encrypted cookie.

      Parameters

      • key: string

        The cookie key

      • value: any

        The value to encrypt

      • Optionaloptions: Partial<CookieOptions>

        Cookie options

      Returns null | string

      The serialized encrypted cookie string or null if encryption fails