COBEAS
COBEAS
TTCTheo's Typesafe Cult
Created by COBEAS on 8/31/2024 in #questions
UT middleware with authentication and fileOverrides
I am trying to have a middleware in one of my upload routes where I authenticate a user and I want to add a customId to the upload. I can do one or the other but when I try to do both in the same middleware function I get a 500 error. This is the code snippet, in this case user logs a correct object but then throws a 500 server error. export const ourFileRouter = { // Define as many FileRoutes as you like, each with a unique routeSlug imageUploader: f({ image: { maxFileSize: "4MB", maxFileCount: 10 } }) .middleware(async ({ req, files }) => { const user = await auth(req); console.log("User in UT middleware", user); if (!user) throw new UploadThingError("Unauthorized"); const fileOverrides = files.map((file) => { const myIdentifier = file.name; return { ...file, customId: myIdentifier }; });
return { foo: "bar" as const, [UTFiles]: fileOverrides }; }) .onUploadComplete(async ({ metadata, file }) => { metadata; file.customId; }), } satisfies FileRouter; Does anybody know what I am missing here?
2 replies