Skip to content

setCookie()

Sets a cookie with the given cookie data. It may overwrite equivalent cookie if it already exists.

await setCookie("CSRFToken","csrfToken", {url: "http://the-internet.herokuapp.com"})
await setCookie("CSRFToken","csrfToken", {domain: "herokuapp.com"})
NameTypeDescription
namestringCookie name.
valuestringCookie value.
optionsObjectDefault: {}.
options.urlstringsets cookie with the URL. Default: undefined.
options.domainstringsets cookie with the exact domain. Default: undefined.
options.pathstringsets cookie with the exact path. Default: undefined.
options.securebooleanTrue if cookie to be set is secure. Default: undefined.
options.httpOnlybooleanTrue if cookie to be set is http-only. Default: undefined.
options.sameSitestringRepresents the cookie’s ‘SameSite’ status: Refer https://tools.ietf.org/html/draft-west-first-party-cookies. Default: undefined.
options.expiresnumberUTC time in seconds, counted from January 1, 1970. eg: 2019-02-16T16:55:45.529Z Default: undefined.
TypeDescription
Promise<void>