Skip to content

SessionCookies

new SessionCookies(options): SessionCookies

ResolvedOptions

SessionCookies

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.

unknown

unknown

object

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 }).

unknown

Pick<IssuedSession<unknown>, "cookie" | "deviceCookie" | "session">

object

csrfToken: string


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.

unknown

unknown

Promise<{ csrfToken: string; }>