cookies, headers and authentication

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
Unknown User
Unknown User524d ago
Message Not Public
Sign In & Join Server To View
oscarama
oscarama524d ago
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?
Unknown User
Unknown User524d ago
Message Not Public
Sign In & Join Server To View
SmoothNanners
SmoothNanners523d ago
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.
SmoothNanners
SmoothNanners523d ago
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
GitHub
GitHub - austins/sveltekit-customauth: An experiment.
An experiment. Contribute to austins/sveltekit-customauth development by creating an account on GitHub.
oscarama
oscarama523d ago
that helps, thank you a bit annoying to do in the +page.server.ts but works 🤷‍♂️
oscarama
oscarama522d ago
Balázs Orbán (@balazsorban44)
Announcing Auth.js! 🔒Authentication for the Web. - Brand new @​auth/core package, - Runtime/framework agnostic - Web standard APIs - Builds on NextAuth.js conventions/API - Decoupled from Next.js & Node.js. We're adding official support for new frameworks...
Likes
412
Twitter
oscarama
oscarama522d ago
arrived right on time
SmoothNanners
SmoothNanners520d ago
That's awesome, thanks for sharing!
More Posts
remove queryis there any api on the trpc client to instantly remove the query out of the query cache? Basicallytrpc 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 anyCannot find namespace 'trpc'I'm getting this error when trying to access <trpc.Provider ...>. Any idea what might be going on?use 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 :/How can I use a fork of trpc-next?Hey there, I've made a fork of @trpc in order to fix an issue inside of @trpc/next. I can build it atrying 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(