LittleLily
LittleLily
TtRPC
Created by yaba101 on 12/1/2023 in #❓-help
Have anyone tried migration from TRPC router to app router api
You can use trpc with app router API routes, and trpc-openapi can generate rest api endpoints based on your trpc procedures
2 replies
TtRPC
Created by K1|ller on 12/3/2023 in #❓-help
Page couldn't be rendered statically because it used `cookies`
Even though the detection of dynamic routes/pages is mentioned in the docs somewhere, I think it would be better if it was made a little more obvious and upfront in the docs that the detection of dynamic vs static routes isn't always going to work, and I think it should recommend that you should probably just explicitly set force dynamic on routes that you know will use cookies, because otherwise the build will just decide to fail randomly one day when you refactor code that is functionally identical but stumps the detection in nextjs
9 replies
TtRPC
Created by K1|ller on 12/3/2023 in #❓-help
Page couldn't be rendered statically because it used `cookies`
It seems like the most likely cause for getting the error is the failure of the nextjs auto-detection of dynamic routes based on use of cookies/etc due to it not being able to follow the chain of calls that results in cookies being used. It's happened to me a few times where I had a page that used cookies, then I moved the cookie usage to an external file that the page imported instead, and that must break the auto-detection and so nextjs thinks the page can be statically rendered even though it can't in reality. If that's the situation you're in then setting force-dynamic is the correct solution since it likely already needed to be dynamic, it just wasn't able to be detected.
9 replies
TtRPC
Created by 1Sonny on 11/22/2023 in #❓-help
Error building create-t3-app: Page couldn't be rendered statically because it used `cookies`
It's specifically only occurring when I make a trpc call on a page/server component to a procedure that requires auth from cookies. Weirdly though if I call the same authentication function that trpc uses directly from the page instead it works, just not when trpc does it
4 replies
TtRPC
Created by 1Sonny on 11/22/2023 in #❓-help
Error building create-t3-app: Page couldn't be rendered statically because it used `cookies`
Dealing with the same error currently as well. Not using t3 app but am using trpc + next 13 app dir
4 replies
TtRPC
Created by justindgm on 11/28/2023 in #❓-help
Vanilla Client Error Handling
also interested in knowing what the best solution for globally handling errors when using createTRPCProxyClient is. I found this discussion https://github.com/trpc/trpc/discussions/2036 but none of the solutions there seem to really be what I want. I'd like to be able to return custom responses to the client like 302 redirects on auth failures and such, but it seems like only createTRPCNext really supports that with its responseMeta field.
10 replies
TtRPC
Created by Mohammed Anas on 11/18/2023 in #❓-help
How does trpc typing work
The benefit of having a nested structure like that is the inner functions have easy access to all the generic types and variables/args from the outer functions
8 replies
TtRPC
Created by Mohammed Anas on 11/18/2023 in #❓-help
How does trpc typing work
Something like this:
const api = () => ({
input: <T extends ZodTypeAny>(inputSchema: T) => ({
mutate: <U>(mutateFn: (data: z.infer<T>) => U) =>
(data: unknown) =>
mutateFn(inputSchema.parse(data))
})
})

// Create and use the api
const numberApi = api().input(z.number().min(1).max(10)).mutate(data => `Hello ${data}`)
const x = numberApi(9) // returns "Hello 9"
const y = numberApi(100) // throws Zod validation error since schema had max(10)
const api = () => ({
input: <T extends ZodTypeAny>(inputSchema: T) => ({
mutate: <U>(mutateFn: (data: z.infer<T>) => U) =>
(data: unknown) =>
mutateFn(inputSchema.parse(data))
})
})

// Create and use the api
const numberApi = api().input(z.number().min(1).max(10)).mutate(data => `Hello ${data}`)
const x = numberApi(9) // returns "Hello 9"
const y = numberApi(100) // throws Zod validation error since schema had max(10)
8 replies
TtRPC
Created by Mohammed Anas on 11/18/2023 in #❓-help
How does trpc typing work
And you probably want to use method chaining like trpc does, which means instead of setting a property on a class, you have a method which returns a new class instance containing the functions that can be called from that point (I prefer implementing that without classes at all and just returning objects with functions inside them)
8 replies
TtRPC
Created by Mohammed Anas on 11/18/2023 in #❓-help
How does trpc typing work
You need the class itself to have a generic arg
8 replies
TtRPC
Created by syedahnb on 11/14/2023 in #❓-help
Can You Provide Guidance on Implementing RBAC and Share GitHub Examples?
Can you access metadata like the name of a procedure inside a middleware?
13 replies