siobe
`useQuery` not working?
Here, give this should explain it:
https://www.youtube.com/watch?v=PmBfq-SpzCU
14 replies
`useQuery` not working?
Only applies if you're using t3 with app router:
If you're trying to use API in a client component then API needs to be imported from /trpc/react
If you're using API in an rsc or anything on the server, you import from /trpc/server
14 replies
Error in tRPC with Clerk in t3-app router
This doesn't really solve the issue with Clerk but if anyone wants an alternative I used @supabase/ssr and got auth working. It's a bit more hands on than Clerk in that you have to write your own middleware function
10 replies
Error in tRPC with Clerk in t3-app router
Also some additional info, if you try to use Clerk's
getAuth()
or auth()
methods in an rsc page, it'll work fine there too. Just won't work when trying to use it in the /server/api/trpc
file which actually sort of makes sense for the auth()
method because it only works when you're in a child of ClerkProvider but with that being said, it should work in the route handler no? Just can't tell if it's my lack of understanding of app router or an actual issue10 replies
Error in tRPC with Clerk in t3-app router
Couldn't figure it out tbh, I'm wondering if it's an issue with Clerk's
authMiddleware
method not fully passing the request through NextResponse to the tRPC route handler in /app/api/trpc/[trpc]/route.ts
. But the ppl over at Clerk are definitely smarter than me so it must just be some dumb mistake I can't quite pin down10 replies
Error in tRPC with Clerk in t3-app router
i've also been having a ton of issues getting clerk to work with trpc in t3 app router, taking a quick look through your repo --- in
middleware.ts
, i found that you have to add your /api/trpc
to the publicRoutes
of Clerk's authMiddleware
method....sorta like this:
authMiddleware({publicRoutes: ["/api/trpc/(.*)"]})
Just posting more of my findings below in the hopes we both can find the solution
even after you do that though you'll run into additional authentication issues within the src/server/api/trpc.ts
file when trying to implement protectedProcedure's.
I find the options are:
1. Use Clerk's auth()
method which always returns a userId of null
2. Use Clerk's getAuth()
method which you need to pass the req object to. But this also just always returns a userId of null
Btw if you try to hit trpc from a client component, it'll work fine no issues. The userId will only return null when you try to access trpc from within rsc's. This makes me think the request object we're getting doesn't have everything we need? idk tho10 replies
How do I setup App router + TRPC + Lucia Auth? (protected routes)
"But the session is not passed into ctx resulting in always getting the unauthorized error. Does someone know what I did wrong to make this work?"
I'm running into the exact same issue trying to get Clerk working with app router (Theo's Chirp video showed it working in pages router, not in app router).
How did you manage to get the ctx to pass the request with the auth info in this line:
const session = await getDefaultSession(req)
With Clerk I'm trying to get the auth session with const auth = getAuth(req)
and it always returns null7 replies
Issue with trpc fetch when trying to pass Clerk auth to context
i'm new here so sorry if i'm asking in the wrong place, but did this code snippet work for you when using the app router or pages router?
been trying to implement Clerk authentication with t3 using the app router and running into issues with Clerk's getAuth() and auth() methods both returning null for auth specifically in this line:
auth: getAuth(req),
in the createInnerTRPCContext
method53 replies