T
tRPC

โ“-help

cookies not being set in procedure

Pprop7/19/2023
This is all the code for setting my cookie
import { publicProcedure, router, userProcedure } from '$lib/trpc/t'

export const user = router({
testCookie: publicProcedure
.query(async ({ ctx: { cookies } }) => {
cookies.set("name", "value", {
path: '/'
})
})
})
import { publicProcedure, router, userProcedure } from '$lib/trpc/t'

export const user = router({
testCookie: publicProcedure
.query(async ({ ctx: { cookies } }) => {
cookies.set("name", "value", {
path: '/'
})
})
})
I'm using svelte-kit, but this doesn't set the cookie
AKAlex / KATT ๐Ÿฑ7/19/2023
you probably need to set it on the response object
Pprop7/19/2023
@alex / KATT yeah, how do I get access to that in the context?
AKAlex / KATT ๐Ÿฑ7/19/2023
you can pass it in your createContext-fn
export async function createContext(
opts: trpcNext.CreateNextContextOptions,
) {
return { req: opts.req, res: opts.res }
}
export async function createContext(
opts: trpcNext.CreateNextContextOptions,
) {
return { req: opts.req, res: opts.res }
}
Pprop7/20/2023
@alex / KATT I donโ€™t have access to opts, can this be because Iโ€™m using trpc/sveltekit? This is how my createContext looks like
import type { RequestEvent } from '@sveltejs/kit';
import type { inferAsyncReturnType } from '@trpc/server';
import { prisma } from '$lib/prisma';

export async function createContext(event: RequestEvent) {
let cookies = event?.cookies
return {
cookies,
prisma
};
}

export type Context = inferAsyncReturnType<typeof createContext>;
import type { RequestEvent } from '@sveltejs/kit';
import type { inferAsyncReturnType } from '@trpc/server';
import { prisma } from '$lib/prisma';

export async function createContext(event: RequestEvent) {
let cookies = event?.cookies
return {
cookies,
prisma
};
}

export type Context = inferAsyncReturnType<typeof createContext>;
Found this workaround https://github.com/icflorescu/trpc-sveltekit/issues/78#issuecomment-1500908054

Looking for more? Join the community!

T
tRPC

โ“-help

Join Server
Recommended Posts
useSubscription simplified with react queryHi Guys, looking for a way to simplify the use of useSubscription. Currently I do the following: 1Next.js app router catch-all HTTP methodsThe app router already supports the catch-all file for route resolution, but AFAIK still expects sepTRPC Vanilla Client (T3 stack)I'm using the T3 stack (Next + TRPC + etc) and I'm trying to figure out how to do vanilla queries thMultiple Inputs on TRPC Procedure?Essentially I'm trying to pass a cart (array of objects) into a public procedure (doing so fine). I adapter for hono or hattip?weโ€™ve got adapters for express, stand alone node and next. I wonder how easy would it be to make adKeep getting 500 error response I can't figure outWith both queries and mutations I get back this response saying that there's html in the response antRPC & redux toolkit queryNode 18, pnpm, ts, vite, toolkit. Cant find any proper info how to use tRPC with toolkit query; If Ihow can I globally set a "middleware" callback for all onErrors on my React Query calls?this is a little specific but Im struggling on it Im using the TRPC server as a BFF for my backend Upgrading from tRPC v9 and NextJS v12. Should I upgrade NextJS first or tRPC?I have an app built from the tRPC + NextJS + Prisma starter, and I'd like to upgrade from tRPC v9 anprefetchinfinite not working when inputs are differentIve been trying to figure out why prefetching doesnt work when the inputs are different between preftRPC + App directory + SSR - current state?What is the current state of the technologies working together with or without SSR? It looks like soHydration failed because the initial UI does not match what was rendered on the server```Unhandled Runtime Error Error: Hydration failed because the initial UI does not match what was reReact tsc starts checking server typesMy tsconfig files are different on the server and client. When I run "tsc" on react client, It is trNextJS 13 Build failingIssue also seen in this PR ย https://github.com/trpc/trpc/pull/4574 I found. None of the webpack workGoogle OAuth callbackany one help how to handle google oauth callbackurl using tRPCInfering query/mutation callback opts parameterHey ๐Ÿ™‚ Thanks for your hard work on this awesome library. I want to create tRPC router, but i want