Skip to main content

Function: ensureCsrfCookie()

ensureCsrfCookie(req, res, options?): string

Defined in: service-core/src/http/csrf/csrf.ts:166

Ensures the caller holds a CSRF cookie, issuing one via Set-Cookie if it doesn't already have a valid one — the standard "set on first visit" double-submit pattern (matches Django/Rails), and what lets a service that never itself issues auth cookies (e.g. server/restapi, which only ever verify a jwt cookie someone else set) still adopt this mechanism on its own. Returns the (possibly freshly-generated) token value.

Parameters​

req​

HttpRequest

res​

HttpResponse

options?​

CsrfCheckOptions = {}

Returns​

string