Derock
Derock
TtRPC
Created by Derock on 6/3/2024 in #❓-help
is it possible to send error codes that aren't listed (eg 503 - service unavailable)
When creating a TRPCError you can specify a code out of the ones listed on the docs But out of these, the only 5xx error is internal server error. I would like to send a 503 to indicate that the request was properly formatted, but the server isn't ready to handle it yet. It's not necessarily a server error.
2 replies
TtRPC
Created by Derock on 1/13/2024 in #❓-help
is there a way to send a streaming response
I'm not talking about batching multiple requests, but more of a one-way websocket-like channel between the server and client using HTTP streaming.
6 replies
TtRPC
Created by Derock on 11/11/2023 in #❓-help
Is it possible to only use WebSockets when necessary, otherwise use httpbatch or http?
I have an application, and on certain pages I need live data. Is there a way to only have tRPC open a websocket for subscriptions and then use another link otherwise? I would like for the solution to disconnect from WS when all subscriptions have been ended, so no dangling WS connections.
15 replies
TtRPC
Created by Derock on 11/4/2023 in #❓-help
How to set cookies in trpc response?
I have an app dir project that was created using this t3-app PR. On the client I have a form and I am using the trpc react client:
import { api } from "~/trpc/react";
[...]
const login = api.auth.login.useMutation({ ... });
import { api } from "~/trpc/react";
[...]
const login = api.auth.login.useMutation({ ... });
and I have the following route defined:
import { cookies } from "next/headers";

publicProcedure
.input(...)
.mutation(async ({ ctx, input }) => {
[...]

// somehow set a cookie
cookies().set("session", session.data.token, {
httpOnly: true,
});

[...]
}),
import { cookies } from "next/headers";

publicProcedure
.input(...)
.mutation(async ({ ctx, input }) => {
[...]

// somehow set a cookie
cookies().set("session", session.data.token, {
httpOnly: true,
});

[...]
}),
This does not set the cookie though -- no Set-Cookie header is in the response. I have no idea how to access the response manually to add the header in either.
11 replies