🌟 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:
@@ -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