entropy
entropy
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
hmmm and sorry to ask again, but if you did auth() in your server components it returns the correct info?
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
I'm curious if you did const auth = getAuth(opt.req) and then just logged auth what that returns.
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
Let me check to see really quick this was from a while ago when I was testing for a tech stack, but decided to not go with tRPC or Clerk
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
no clue just the first thing I found sorry
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
Uh I mean really depends on what you need but I would say compared to Clerk that next-auth is a bit harder to setup. I found this github really quickly if you want to take a peak at their implementation. Otherwise I would wait for someone more knowledgeable to help out. https://github.com/solaldunckel/next-13-app-router-with-trpc
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
and in the application code you can get the session, but just not on your tRPC context?
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
Is that after you go through the sign in flow?
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
also it's redundant to have the / and /api/(.*) routes in your publicRoutes since the matcher already prevents the middleware from running on those routes.
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
They actually have a guide that can help you setup tRPC with Clerk here that I'd recommend following. https://clerk.com/docs/references/nextjs/trpc
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
you just need to add your api to your public routes on the Clerk middleware so:
export default authMiddleware({
publicRoutes: ["<YOUR API ENDPOINT>"]
})
export default authMiddleware({
publicRoutes: ["<YOUR API ENDPOINT>"]
})
Though if you are following the Clerk docs and use the matcher they have it should prevent your middleware from running on /trpc or /api endpoints
export const config = {
matcher: ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],
}
export const config = {
matcher: ['/((?!.+\\.[\\w]+$|_next).*)', '/', '/(api|trpc)(.*)'],
}
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
I see thank you for the information! It turns out that Clerk will send everything to the sign in page including api's so I just had to add my api route for trpc to my clerk middleware public routes.
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
here's a link to a repo with the same issue as well: https://github.com/Entropy-10/clerk-trpc-issue
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
So after a lot of messing around it seems to caused by something with the Clerk Middleware. I'm still not exactly sure what is the problem or why though.
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
Yep I did here's my route handler api/trpc/[trpc]/route.ts
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'

import { createContext } from '~/server/api/context'
import { appRouter } from '~/server/api/root'

const handler = (req: Request) =>
fetchRequestHandler({
endpoint: '/api/trpc',
req,
router: appRouter,
createContext
})

export { handler as GET, handler as POST }
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'

import { createContext } from '~/server/api/context'
import { appRouter } from '~/server/api/root'

const handler = (req: Request) =>
fetchRequestHandler({
endpoint: '/api/trpc',
req,
router: appRouter,
createContext
})

export { handler as GET, handler as POST }
53 replies
TtRPC
Created by entropy on 5/25/2023 in #❓-help
Issue with trpc fetch when trying to pass Clerk auth to context
Everything also seems to work fine when I log in and make a call to my protectedProcedure, it's only a problem when I log out.
53 replies