T
tRPC

cookies, headers and authentication

cookies, headers and authentication

Ooscarama12/12/2022
in express I can do something like res.cookie("name", "value") for example. alternatively I can do res.set"set-cookie", "name=value"). how can I do something one of the two above with trpc? or is there another, standardized way to do auth? I'm using trpc v10 and sveltekit
UUUnknown User12/13/2022
2 Messages Not Public
Sign In & Join Server To View
Ooscarama12/13/2022
ok, thank you! I'll try it out my create context stuff is ran in hooks.server.ts like:
export const handle: Handle = async ({ event, resolve }) => {
if (event.url.pathname.startsWith(`${trpcPathBase}/`)) {
const response = await fetchRequestHandler({
// ...
createContext: () => {
return createContext(event);
},
});

return response;
}

// ...
};
export const handle: Handle = async ({ event, resolve }) => {
if (event.url.pathname.startsWith(`${trpcPathBase}/`)) {
const response = await fetchRequestHandler({
// ...
createContext: () => {
return createContext(event);
},
});

return response;
}

// ...
};
but a res object is nowhere to be found. any idea how I can access it?
UUUnknown User12/13/2022
Message Not Public
Sign In & Join Server To View
SSmoothNanners12/13/2022
I tried to pass the SvelteKit cookies object into the context, but it didn't work since SvelteKit resolves the response separately. I was able to set cookies directly in the response (not using SvelteKit's cookies object) in responseMeta by checking the response and paths, but that's kinda messy. I recommend keeping the auth logic on a +page.server.js or +server.js endpoint. tRPC for everything else. There is the Lucia auth lib for SvelteKit: https://lucia-auth.vercel.app/ It sets some locals, it might be able to be passed to tRPC, but I haven't used it. I have a repo for a custom auth with GitHub OAuth using endpoints as well and passes the session to the tRPC context, feel free to check it out https://github.com/austins/sveltekit-customauth
Ooscarama12/14/2022
that helps, thank you a bit annoying to do in the +page.server.ts but works 🤷‍♂️ https://twitter.com/balazsorban44/status/1603082914362986496?t=A3E4izkLf7de4J6zIvvdfA&s=19 arrived right on time
SSmoothNanners12/16/2022
That's awesome, thanks for sharing!

Looking for more? Join the community!

T
tRPC

cookies, headers and authentication

Join Server
Recommended Posts
trpc hook pattern. This works, but I’m not convinced…I want to call my route when a button is clicked and have access to isLoading, onError etc… I have iCatch TRPCError, ZoddError on the front-endi am throwing a TRPCError in a mutation. i dont understand how to catch this error in the OnError meimplicitly has type 'any' because it does not have a type annotation and is referenced directlyRunning into this error. I feel like it's some sort of infinite recursion issue, but not sure where Why do some examples create PrismaClient in context, and others don’tIs there a specific reason to do this or not to do this? I can imagine with the new Prisma extensionAppRouter type any?I am trying to use trpc in a Turbo repo and when I export the AppRouter on the server side it is thez.map() as an inputHi, I have ```ts z.map(z.string(), z.string()) ``` as an input, but when I try to pass the map as correct way to call TRPC inside a functioni want a user to be able to sign after they have a clicked a button but i get a hooks error. can anyuse tRPC for RPC calls instead of gRPCHi, I know that tRPC and gRPC are different things - despite the similar name. Nevertheless I woutRPC caching vs Vercel dynamic edge cachingWhat is the difference, or improvements, on Vercel's dynamic edge caching? tRPC server caching worksIgnore Errors from batch callsI have some of my routers throw helpful errors for the client to use in the error message object, buAny way to view headers in middleware?Middleware `input` doesn't seem to have it :/trying to cache api routesHello. I am using TRPC to make a site which integrates with a third party API. I need to add cachinPrisma+TRPC monorepoHey, so we have a monorepo with 3 backend services and 3 frontend services. It looks like the followcalling 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. ITRPC waiting until the query has completedHey. I've just found out about TRPC and I love it. However, I was wondering if there is a way to maktrpc with headless cmsHello, Is there any example with trpc and headless CMS or is there anypoint to use trpc for project Is it possible to call a query from another query defined in the same router?Say I have some code like the following: ``` t.router({ compute_all: t.procedure .query(Testing with React Testing LibraryHi! I am trying to test my ```DestinationForm``` component using react testing library. My test is sProxy TRPC server to another clientI've two TRPC servers, one essentially acts like a proxy, it validates auth and based on a specific Unexpected tokenhi, kindly help me on this one