Tom
Explore posts from serversis there a way to do client-side "middleware"?
My app uses Firebase Auth for authentication. While the user is logged in, they get an ID token which is valid for 1 hour (non-configurable). The front-end is supposed to call a function
await user.getIdToken()
to refresh this token.
Is there a way that I can have the frontend try a request, examine the response, potentially call this function if the server tells me the token is expired, and then retry? I want this to happen without triggering the onError() callback for all of my queries / mutations if possible.7 replies
working with custom errors and trpc errorFormatter
Hey guys. I'm trying to refactor my app so that all errors extend a BaseError class to make dealing with error codes and user-friendly messages easier. I'm having trouble converting these to the correct shape in the tRPC errorFormatter. Right now when I throw these custom errors tRPC doesnt recognize them and converts all of them to INTERNAL_SERVER_ERROR's.
I see that some error codes get translated in 3 places: the jsonrpc error code, the http status code, and an HTTP status,. There also seems to be some additional structure. My end goal is to be able to convert my errors to the 'normal' shape so that trpc-openapi can correctly return them.
Is there a reasonable way to do this in tRPC or should I do something different?
Its easy enough for me to convert one of my errors to a TRPCError, but I don't see a way to convert that to the right shape once I'm in the errorFormatter. is there a way to do this?
29 replies
TTCTheo's Typesafe Cult
•Created by Tom on 10/15/2023 in #questions
google fonts in vercel/og image
Basically the title. Does anyone have an example of using google fonts in vercel/og image generation? The examples don't have anything, but it seems weird since the rest of my fonts are managed with next/font.
2 replies
TTCTheo's Typesafe Cult
•Created by Tom on 10/8/2023 in #questions
OCR (Tesseract) not working well with very clear text (in c or js)
2 replies
TTCTheo's Typesafe Cult
•Created by Tom on 8/12/2023 in #questions
Upstash ratelimitting + trpc
In my project I use
upstash/ratelimit
(pretty much directly copy / pasted from the how-to) and trpc in my nextjs app. Right now, when people hit the ratelimit I get a TRPC error that says "Unexpected end of JSON" because upstash ratelimitting just redirects to this page (again straight from the tutorial)
Obviously this doesn't match what TRPC expects. how can I return a TRPC error from this non-trpc api route?3 replies
TTCTheo's Typesafe Cult
•Created by Tom on 8/8/2023 in #questions
How to add one-off scripts to a T3 app
I started my project with create-t3-app a long time ago. i see that they've added the new t3 env-next module for managing environment variables in a typesafe way and i decided to switch to it. However, this seems to have broken my scripts directory which can no longer run one-off db scripts because its now importing a .mjs module. What is the recommended way to run one-off typescript scripts in a ct3a project?
8 replies
TTCTheo's Typesafe Cult
•Created by Tom on 8/4/2023 in #questions
Is there a way to upgrade env vars in a ct3a project?
I have an app I created a bunch of months aho with create-t3-app. The environment variables were done with a few schema.mjs files and i never reeally knew how to use it so I just did my environment vars with
process.env.*
. it looks like there a new way to deal with them in a type-safe way. Is there a way to upgrade to the new way?
https://create.t3.gg/en/usage/env-variables5 replies
TTCTheo's Typesafe Cult
•Created by Tom on 7/11/2023 in #questions
how does vercel take screenshot?
8 replies
How to prefetch data on the client into the cache?
To simplify a bit, lets say I'm making an app that allows users to view a project. I have a top level UI route with a summary of the project and then sub-routes that display more details, some of which require more fetches. Is there a way that I can make it so that when the top-level route loads, the trpc cache automatically prefetches the data needed for the sub-routes?
Whenever I search the site for 'prefetch', I find the SSR stuff, but I'm actually trying to prefetch on the client.
Thanks.
18 replies
TTCTheo's Typesafe Cult
•Created by Tom on 6/17/2023 in #questions
Why isn't this typescript type working?
524 replies
is there a way to call useQuery() from a callback and get the return value within that callback?
I have a generic component that is effectively an autocomplete that fills in options from a web request. The component takes a callback which takes in the newest search string and should perform a web request to get the autocomplete options and return them. Is there a way I can call a trpc
useQuery()
and get the return value within this async callback? Thanks.11 replies
TTCTheo's Typesafe Cult
•Created by Tom on 5/6/2023 in #questions
Multiple Database reads in a single roundtrip with Kysely
Is it possible to do multiple SELECTs from the db without another await? I'm assuming I could do something similar with Promise.all(). Is this the best solution?
5 replies
TTCTheo's Typesafe Cult
•Created by Tom on 5/5/2023 in #questions
How to do a WHERE clause for a JSON field in kysely
Basically the title. I'm trying to convert the following prisma query to kysely and can't figure out how to do the individual statements inside the where:
data is a Jsonb column. Anybody know how to do this?
5 replies