🌟 Fix download button (#210)
* Add auth cookie to avoid using auth token in the url * Fix all download button * Refactor some of the places where we download file
This commit is contained in:
Generated
+21
@@ -504,6 +504,22 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"@fastify/cookie": {
|
||||
"version": "6.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@fastify/cookie/-/cookie-6.0.0.tgz",
|
||||
"integrity": "sha512-Luy3Po3dOJmqAuPCiPcWsX0tV5+C3AOnULSdlsGjNGOvyE7jqzysp8kT9ICfsUvove+TeUMgTWl1y9XS3ZPPMg==",
|
||||
"requires": {
|
||||
"cookie-signature": "^1.1.0",
|
||||
"fastify-plugin": "^3.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"fastify-plugin": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmjs.org/fastify-plugin/-/fastify-plugin-3.0.1.tgz",
|
||||
"integrity": "sha512-qKcDXmuZadJqdTm6vlCqioEbyewF60b/0LOFCcYN1B6BIZGlYJumWWOYs70SFYLDAH4YqdE1cxH/RKMG7rFxgA=="
|
||||
}
|
||||
}
|
||||
},
|
||||
"@fastify/error": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@fastify/error/-/error-2.0.0.tgz",
|
||||
@@ -3152,6 +3168,11 @@
|
||||
"resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.2.tgz",
|
||||
"integrity": "sha512-aSWTXFzaKWkvHO1Ny/s+ePFpvKsPnjc551iI41v3ny/ow6tBG5Vd+FuqGNhh1LxOmVzOlGUriIlOaokOvhaStA=="
|
||||
},
|
||||
"cookie-signature": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.1.tgz",
|
||||
"integrity": "sha512-78KWk9T26NhzXtuL26cIJ8/qNHANyJ/ZYrmEXFzUmhZdjpBv+DlWlOANRTGBt48YcyslsLrj0bMLFTmXvLRCOw=="
|
||||
},
|
||||
"core-util-is": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz",
|
||||
|
||||
@@ -105,6 +105,7 @@
|
||||
"@fastify/caching": "^7.0.0",
|
||||
"@fastify/formbody": "^6.0.0",
|
||||
"@fastify/static": "^5.0.1",
|
||||
"@fastify/cookie": "^6.0.0",
|
||||
"@ffprobe-installer/ffprobe": "^1.4.1",
|
||||
"@sentry/node": "^6.19.7",
|
||||
"@sentry/tracing": "^6.19.7",
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
import { FastifyPluginCallback, FastifyRequest } from "fastify";
|
||||
import fastifyJwt from "fastify-jwt";
|
||||
import cookie from "@fastify/cookie";
|
||||
import fp from "fastify-plugin";
|
||||
import config from "../../../../config";
|
||||
import { JwtType } from "../../types";
|
||||
|
||||
const jwtPlugin: FastifyPluginCallback = (fastify, _opts, next) => {
|
||||
fastify.register(cookie);
|
||||
fastify.register(fastifyJwt, {
|
||||
secret: config.get("auth.jwt.secret"),
|
||||
cookie: {
|
||||
cookieName: "X-AuthToken",
|
||||
signed: false,
|
||||
},
|
||||
});
|
||||
|
||||
const authenticate = async (request: FastifyRequest) => {
|
||||
|
||||
@@ -76,14 +76,14 @@ const routes: FastifyPluginCallback = (fastify: FastifyInstance, _options, next)
|
||||
fastify.route({
|
||||
method: "GET",
|
||||
url: `${serviceUrl}/:id/download`,
|
||||
preValidation: [fastify.authenticateOptional],
|
||||
preValidation: [fastify.authenticate],
|
||||
handler: documentsController.download.bind(documentsController),
|
||||
});
|
||||
|
||||
fastify.route({
|
||||
method: "GET",
|
||||
url: `${serviceUrl}/download/zip`,
|
||||
preValidation: [fastify.authenticateOptional],
|
||||
preValidation: [fastify.authenticate],
|
||||
handler: documentsController.downloadZip.bind(documentsController),
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user