SessionCookies
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SessionCookies(
options):SessionCookies
Parameters
Section titled “Parameters”options
Section titled “options”ResolvedOptions
Returns
Section titled “Returns”SessionCookies
Methods
Section titled “Methods”csrfToken()
Section titled “csrfToken()”csrfToken(
request,response):object
The CSRF token for the request’s session or pre-session, for a client
that cannot read the csrf cookie: call it from a @Public() GET route
(such as GET /csrf-token) and return the result. It is exactly the
token CsrfMiddleware set or kept as the cookie on this response,
minting the pre-session and the cookie when missing, as on any safe
request. The response is marked Cache-Control: no-store, which keeps
it out of HTTP caches but not out of a cache inside the app: keep the
route out of Nest’s CacheInterceptor (no @CacheKey/@CacheTTL on it,
and skip it in trackBy when the interceptor is global through
APP_INTERCEPTOR) and any other response cache, or every caller gets
the first caller’s token. An interceptor or middleware of yours that
sets Cache-Control after the handler replaces the no-store: keep it
off this route too. Throws an AuthConfigError on a request the
middleware handed no token: an exempt path (which mints nothing) or an
unsafe method.
Parameters
Section titled “Parameters”request
Section titled “request”unknown
response
Section titled “response”unknown
Returns
Section titled “Returns”object
csrfToken
Section titled “csrfToken”csrfToken:
string
set(
response,issued):object
Sets an issued session’s cookie and its trusted-device cookie, plus a
CSRF cookie bound to it. Pass the response from @Res({ passthrough: true }).
Parameters
Section titled “Parameters”response
Section titled “response”unknown
issued
Section titled “issued”Pick<IssuedSession<unknown>, "cookie" | "deviceCookie" | "session">
Returns
Section titled “Returns”object
csrfToken
Section titled “csrfToken”csrfToken:
string
signOut()
Section titled “signOut()”signOut(
request,response):Promise<{csrfToken:string; }>
Signs the request’s session out through the core (auth.logout), clears
its cookie, and starts a fresh pre-session with a CSRF token bound to it.
Parameters
Section titled “Parameters”request
Section titled “request”unknown
response
Section titled “response”unknown
Returns
Section titled “Returns”Promise<{ csrfToken: string; }>