GabrielDSFS
Explore posts from serversTTCTheo's Typesafe Cult
•Created by GabrielDSFS on 5/8/2024 in #questions
How to make a fully public page with TRPC requests on T3?
11 replies
TTCTheo's Typesafe Cult
•Created by GabrielDSFS on 12/19/2023 in #questions
TRPC request stays as 'paused' and is never run?
Some of my users are having their TRPC requests stay as "paused" indefinitely. I have a T3 app that uses TRPC, and I have some pretty straight forward dashboard UI.
This doesn't happen at my machine but happens on some of the user's machines, here's a sample code that is run inside a react hook:
console.log("Fetching products!!!");
const products = api.product.getAllWithRelations.useQuery({
includeLocations,
includeProcesses,
includeManufacturers,
});
console.log("Product status:", products);
Which the user has it eternally on "isLoading: true" and the fetchStatus is accused as "paused" for some reason? After logging the status, that's what my user sees:
data: undefined
dataUpdatedAt: 0
error: null
errorUpdateCount: 0
errorUpdatedAt: 0
failureCount: 0
failureReason: null
**fetchStatus: "paused"**
**isError: false**
isFetched: false
isFetchedAfterMount: false
isFetching: false
isInitialLoading: false
**isLoading: true**
isLoadingError: false
**isPaused: true**
isPlaceholderData: false
isPreviousData: false
isRefetchError: false
isRefetching: false
isStale: true
isSuccess: false
As seen, I'm not pausing the request myself for whatsoever reason.
The only special thing I'm doing is running a middleware for sentry and Clerk authorization.
const sentryMiddleware = t.middleware(
Sentry.Handlers.trpcMiddleware({
attachRpcInput: true,
})
);
const enforceUserIsAuthorized = t.middleware(async ({ ctx, next }) => {
if (!ctx.currentUser)
throw new TRPCError({
code: "UNAUTHORIZED",
message: "You need to be authorized to do this.",
});
return next({ ctx: { currentUser: ctx.currentUser } });
});
export const privateProcedure = t.procedure
.use(sentryMiddleware)
.use(enforceUserIsAuthorized);
2 replies