Alex
Alex
Explore posts from servers
TTCTheo's Typesafe Cult
Created by Alex on 7/25/2023 in #questions
Error when using clerk getAuth from UploadThing routes
I'll check tomorrow. But the upload works with the previous routes handler and no getAuth...
16 replies
TTCTheo's Typesafe Cult
Created by Alex on 7/25/2023 in #questions
Error when using clerk getAuth from UploadThing routes
I can see it is related to the same error. I'll follow the topic on the uploadthing channel. Meanwhile I will remove the security for development. Going to production next month. We were planning to use uploadthing but if we do not get a proper solution we will have to drop our subscription and implement something ourselves. I would realy want to avoid to do that 😦
16 replies
TTCTheo's Typesafe Cult
Created by Alex on 7/25/2023 in #questions
Error when using clerk getAuth from UploadThing routes
Yes pages dir
16 replies
TTCTheo's Typesafe Cult
Created by Alex on 7/25/2023 in #questions
Error when using clerk getAuth from UploadThing routes
16 replies
TTCTheo's Typesafe Cult
Created by Alex on 7/25/2023 in #questions
Error when using clerk getAuth from UploadThing routes
I did try to apply the solution but I'm getting another error now client side.
16 replies
TTCTheo's Typesafe Cult
Created by Alex on 7/25/2023 in #questions
Error when using clerk getAuth from UploadThing routes
Hi @Josh Thanks for pointing to the solution. I'm happy to see It is not coming from something I did wrong.
16 replies
TTCTheo's Typesafe Cult
Created by Alex on 7/25/2023 in #questions
Error when using clerk getAuth from UploadThing routes
When trying to upload a file I'm getting this error:
[UT] middleware failed to run
Error: You need to use "authMiddleware" (or the deprecated "withClerkMiddleware") in your Next.js middleware file. You also need to make sure that your middleware matcher is configured correctly and matches this route or page. See https://clerk.com/docs/quickstarts/get-started-with-nextjs
at /Users/aroba/komonco/saas/node_modules/@clerk/nextjs/dist/cjs/server/getAuth.js:45:13
at /Users/aroba/komonco/saas/node_modules/@clerk/nextjs/dist/cjs/utils/debugLogger.js:55:19
at Object.eval [as middleware] (webpack-internal:///(api)/./src/server/upload-routes.ts:22:90)
at eval (webpack-internal:///(api)/../../node_modules/uploadthing/dist/chunk-UNVWQBTP.mjs:330:46)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async eval (webpack-internal:///(api)/../../node_modules/uploadthing/dist/next-legacy.mjs:33:22)
[UT] middleware failed to run
Error: You need to use "authMiddleware" (or the deprecated "withClerkMiddleware") in your Next.js middleware file. You also need to make sure that your middleware matcher is configured correctly and matches this route or page. See https://clerk.com/docs/quickstarts/get-started-with-nextjs
at /Users/aroba/komonco/saas/node_modules/@clerk/nextjs/dist/cjs/server/getAuth.js:45:13
at /Users/aroba/komonco/saas/node_modules/@clerk/nextjs/dist/cjs/utils/debugLogger.js:55:19
at Object.eval [as middleware] (webpack-internal:///(api)/./src/server/upload-routes.ts:22:90)
at eval (webpack-internal:///(api)/../../node_modules/uploadthing/dist/chunk-UNVWQBTP.mjs:330:46)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async eval (webpack-internal:///(api)/../../node_modules/uploadthing/dist/next-legacy.mjs:33:22)
when calling dummy.ts I'm getting the userid. I'm also using getAuth from several other APIs and from my TRPC endpoints...Everything works as expected. middleware.ts:
import { authMiddleware } from '@clerk/nextjs'

export default authMiddleware({
publicRoutes: ['/(.*)'],
})

export const config = {
matcher: ['/((?!.*\\..*|_next).*)', '/(api|trpc)(.*)', '/api(.*)'],
}
import { authMiddleware } from '@clerk/nextjs'

export default authMiddleware({
publicRoutes: ['/(.*)'],
})

export const config = {
matcher: ['/((?!.*\\..*|_next).*)', '/(api|trpc)(.*)', '/api(.*)'],
}
Any idea?
16 replies
TTCTheo's Typesafe Cult
Created by Alex on 7/25/2023 in #questions
Error when using clerk getAuth from UploadThing routes
upload-routes.ts:
import { getAuth } from '@clerk/nextjs/server'
import { createUploadthing, type FileRouter } from 'uploadthing/next-legacy'
import { prisma } from '@app/db'
import { utapi } from 'uploadthing/server'

const f = createUploadthing()

// FileRouter for your app, can contain multiple FileRoutes
export const uploadRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
photos: f({ image: { maxFileSize: '4MB' } })
// Set permissions and file types for this FileRoute
.middleware(async ({ req, res }) => {
//todo:Implement the security check here

// This code runs on your server before upload
const {userId} = getAuth(req)

// If you throw, the user will not be able to upload
if (!userId) throw new Error('Unauthorized')

// Whatever is returned here is accessible in onUploadComplete as `metadata`
return {userId}
})
.onUploadComplete(async ({ metadata, file }) => {
// This code RUNS ON YOUR SERVER after upload
console.log("Upload complete for userId:", metadata.userId);

console.log('file url', file.url)
}),
} satisfies FileRouter

export type UploadRouter = typeof uploadRouter
import { getAuth } from '@clerk/nextjs/server'
import { createUploadthing, type FileRouter } from 'uploadthing/next-legacy'
import { prisma } from '@app/db'
import { utapi } from 'uploadthing/server'

const f = createUploadthing()

// FileRouter for your app, can contain multiple FileRoutes
export const uploadRouter = {
// Define as many FileRoutes as you like, each with a unique routeSlug
photos: f({ image: { maxFileSize: '4MB' } })
// Set permissions and file types for this FileRoute
.middleware(async ({ req, res }) => {
//todo:Implement the security check here

// This code runs on your server before upload
const {userId} = getAuth(req)

// If you throw, the user will not be able to upload
if (!userId) throw new Error('Unauthorized')

// Whatever is returned here is accessible in onUploadComplete as `metadata`
return {userId}
})
.onUploadComplete(async ({ metadata, file }) => {
// This code RUNS ON YOUR SERVER after upload
console.log("Upload complete for userId:", metadata.userId);

console.log('file url', file.url)
}),
} satisfies FileRouter

export type UploadRouter = typeof uploadRouter
16 replies