rustclan
Explore posts from serversBest way to update a TRPC useQuery response without refetching
Hey,
I currently have a trpc useQuery endpoint which retrieves a series of form submissions for a user to review. I have a mutation which allows the user to delete a specific submission, which is working fine. However, I'm wondering what the best way of updating the submissions after I have just deleted the submission in question? I don't want to refetch the entire list of submissions as thats not very efficient, it would be best to just delete the specific submission from the submissions list if the delete mutation suceeded.
2 replies
What is a useSuspenseQuery?
Hi, I'm wondering what a useSuspenseQuery is, im looking at the docs but it doesn't explain it anywhere?
https://trpc.io/docs/client/react/suspense
3 replies
TTCTheo's Typesafe Cult
•Created by rustclan on 9/3/2023 in #questions
TRPC error handling
Hey guys. I'm currently looking for some advice in regards to handling errors on my trpc endpoints.
My current implementation is as follows:
This is a quick example showing what i would like to display when an error occurs, but it doesn't feel very nice... is there any alternatives?
4 replies
TTCTheo's Typesafe Cult
•Created by rustclan on 4/30/2023 in #questions
TRPC ratelimiting endpoints (race conditions)
I am currently having some problems with a race condition in my TRPC nextJS api.
Essentially what is happening is I have a
enforceGuildPermissions
method, which basically checks if the user who is making the request has permission to get the data for that guild.
The data is stored in my Redis cache for 3 seconds. This works okay sometimes, but other times because there is 3-4 different trpc requests running for a single page which are guild, role and channel. It causes the last request (channel) to get rate limited by the discord API because they are all running concurrently, this means it doesn't give my caching code chance to update it before the next one runs.
middleware route procedure:
3 replies
TRPC ratelimiting endpoints
I am currently having some problems with a race condition in my TRPC nextJS api.
Essentially what is happening is I have a
enforceGuildPermissions
method, which basically checks if the user who is making the request has permission to get the data for that guild.
The data is stored in my Redis cache for 3 seconds. This works okay sometimes, but other times because there is 3-4 different trpc requests running for a single page which are guild, role and channel. It causes the last request (channel) to get rate limited by the discord API because they are all running concurrently, this means it doesn't give my caching code chance to update it before the next one runs.
middleware route procedure:
20 replies
trpc rate limiting
hi
I am currently having some problems with a race condition in my TRPC nextJS api.
Essentially what is happening is I have a
enforceGuildPermissions
method, which basically checks if the user who is making the request has permission to get the data for that guild.
The data is stored in my Redis cache for 3 seconds. This works okay sometimes, but other times because there is 3-4 different trpc requests running for a single page which are guild, role and channel. It causes the last request (channel) to get rate limited by the discord API because they are all running concurrently, this means it doesn't give my caching code chance to update it before the next one runs.
3 replies
trpc pipe middleware
Hey all.
I'm currently trying to create a middle ware on endpoints using the new
pipe
API.
This is on a specific route which is formatted like:
http://localhost:3000/dashboard/811452295324762131/page
Is it possible to retrieve the dynamic id
which is in this URL, in my middleware? I really need to access this for the middleware to be possible to use.
Essentially I need to check if the current user has permission to access this guildId.
There unfortunetly doesn't seem to be any req
property in the pipe api which could give me router information.4 replies
trpc query running twice
Hey guys. I have a trpc endpoint which makes a request to the discord api to fetch a list of the users guilds.
It works fine. However, because this is in my dev environment the TRPC query runs two times, which causes the request to fail due to discord ratelimits. I am using nextjs and I am unsure how I can resolve this.
Up until now, I have always used my own api on my server using python, so I could cache things. But with vercel you cannot cache results. Does anybody have any suggestions?
10 replies
TRPC global loading page
Hey. With trpc/nextjs I'm wondering if its possible to have a global loading context/state which is used across my whole app, whenever a TRPC endpoint
.isFetched
property is false, it will display a "loading" symbol.
Currently I have to do something like this on every page:
4 replies
TTCTheo's Typesafe Cult
•Created by rustclan on 12/4/2022 in #questions
TRPC cache (with vercel, but not working locally too)
Hello.
I am using TRPC to make a site which integrates with a third party API. I need to add caching to some of my routes.
I have tried to implement a temporary global cache, as seen below. In order to stop rate limits for the third party api.
However, the cache-control header does not get changed, and nothing is cached. Mutiple requests are still made to the third party API.
The
cache
code does run, as the console.log(2)
appears in console.
Any clue whats wrong?2 replies
TTCTheo's Typesafe Cult
•Created by rustclan on 11/30/2022 in #questions
TRPC max retries on endpoint
15 replies
calling api endpoints from within a trpc api endpoint?
Hey all.
I have a series of api endpoints which may have to be reused across other api endpoints. I was wondering if this is possible?
As you can see, my
checkGuildAccess
needs access to the users access token. So I call the getAccessToken
endpoint from within the checkGuildAccess
endpoint. Is this valid? I am getting an error.
2 replies
TRPC waiting until the query has completed
Hey. I've just found out about TRPC and I love it. However, I was wondering if there is a way to make it so the code below my query doesn't run until the query has completed, without having to make an external function or make use of a useeffect hook in order to use await?
Is there a property of some sort which I can use to stop the page from rendering?
The code below causes an infinite
signIn
loop due to the data
not being there on the initial page render. But, I can't check if !guilds.data
, because sometimes it wont return anything, due to an invalid token. Which means there is no good way to identify when to force a signIn
for the user.
19 replies
TTCTheo's Typesafe Cult
•Created by rustclan on 11/20/2022 in #questions
invalid environment variables
27 replies