@piggly/fastify-chassis
Version:
An ESM/CommonJS toolkit to help you to do common operations in your back-end applications with Fastify and NodeJS.
31 lines (30 loc) • 1.17 kB
TypeScript
import type { HookHandlerDoneFunction, FastifyRequest, FastifyReply } from 'fastify';
import type { CSRFTokenService } from '../services/index.js';
/**
* CSRF token middleware.
*
* When method.from is cookie, will get the "param"
* value from cookie. E.g: request.cookies[param].
*
* When method.from is header, will get the "param"
* value from header. E.g: request.headers[param].
*
* If csrf token is invalid for any reason, it will:
* - Publish UnauthorizedAccessEvent.
* - Return InvalidCSRFTokenError.
*
* @param {Object} method The method to get the csrf token.
* @param {string} method.from The source of the csrf token.
* @param {string} method.param The parameter name to get the csrf token.
* @param {Object} deps The dependencies.
* @param {CSRFTokenService} deps.CSRF_SERVICE The csrf token service.
* @returns Callback function.
* @since 7.0.0
* @author Caique Araujo <caique@piggly.com.br>
*/
export declare const CSRFTokenMiddleware: (method: {
from: "header" | "cookie";
param: string;
}, deps: {
CSRF_SERVICE: CSRFTokenService;
}) => (request: FastifyRequest, reply: FastifyReply, done: HookHandlerDoneFunction) => void;