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?
1 Reply
markr
markr3mo ago
Hmm this all looks correct, if you enable debug logging https://docs.uploadthing.com/api-reference/server#config do you get any more details about the 500?
Want results from more Discord servers?
Add your server