simplestake
simplestake
WWasp-lang
Created by simplestake on 8/21/2023 in #🙋questions
rawBody through apiNamespace
import express from "express"; import { MiddlewareConfigFn } from "@wasp/middleware"; import bodyParser from "body-parser"; interface CustomRequest extends express.Request { rawBody?: Buffer; } const PayMiddleware: express.RequestHandler = bodyParser.json({ verify: (req: CustomRequest, res, buf) => { req.rawBody = buf; }, }); export const rawBodyNamespaceMiddlewareFn: MiddlewareConfigFn = ( middlewareConfig ) => { middlewareConfig.set("context", PayMiddleware); return middlewareConfig; }; I haven't found a way to get a request's raw body. It seems wasp's preceding middleware conflicts.
10 replies
WWasp-lang
Created by simplestake on 6/24/2023 in #🙋questions
context.user through middlewareConfigFn
I’ve created an API that uses multer to upload a file via the middlewareConfig, but I’d like to make use of auth to prevent unauthorized access to the route. Context.user returns undefined even when the API is called through the client. Also, even if it were to return an authorization header, how do I prevent the file from uploading before it it reaches the (!contex.user) if statement? I’ve read through the docs, but there is nothing too detailed regarding the use of auth through APIs declared in main.wasp.
11 replies