Theo's Typesafe Cult

TTC

Theo's Typesafe Cult

Join the community to ask questions about Theo's Typesafe Cult and get answers from other members.

Join

Is it secure to include the 'admin' api in the 'standard' trpc api?

I'm building a standard B2B app, which obviously has a trpc api. I'm looking to add an admin area, which allows me to manage the B2B customers. This will include tasks, like listing the customers' (confidential) data. Obviously the api route itself is going to be protected by authentication, but I still obviously wouldn't want normal users,...

Send large data (~5MB) to trpc backend

I need to build a feature that reads sqlite files in memory, my idea is to upload the file, parse it and pass it to my trpc backend that will create an in memory sqlite db to perform some queries. However, it seems passing large payloads takes ages (never finished) even locally, im not sure if trpc is not equipped to handle huge payloads. Please share if you have a solution or even a better way to do it....

Attempted to access server-side environment variable 'NODE_ENV' on the client Error

Hi, i am trying to call a trpc user mutation that will update the user settings ( name, email and avatar), whenever i call the mutation it returns the error on the title, i don't know why, if i use an alternative method ( via nextjs request ) , it works perfectly. Here's my code:

Properly call trpc from state (Mobx, Zustand etc.)

I'm currently struggling to find the proper way to use trpc, to make an api call from a state management library such as MobX. I'm fully aware of react-query, but because of the complexity of my use-case I decided to use MobX for some routes. Because of the 'useQuery' function, I came up with this (ugly) code snippet: `async getData() {...

Static type checking between resolvers and typedef

```ts // A schema is a collection of type definitions (hence "typeDefs") // that together define the "shape" of queries that are executed against // your data....

How to setup grapql(t3 stack) with typeschecking?

I want to use the @apollo/server and @apollo/client

What is the best way to type an API Response

I'm currently trying to type my API Response for a user login what would be the best way to type that response that could take either a 404 error or a successful ok response. This is somewhat correct but forces me to ensure that data is not null, but this doesn't seem like the correct approach when typing this response type. Is there a different way I can approach this by combining an error type and an ok type?...

useEffect being weir - EventListener

So... I have this listener that listens for the position of selectedItem when I scroll on its parent. Why is it not unbinding when selectedItem changes? the cleanup function doesn't work. I have no idea of what is wrong lol. when I change the selectedItem, it creates a new listener for that and they keep stacking. please send help. images attached....

Next Image Height

``<Link href={{ pathname: /shop/${shop.id}` }}> <div className="cursor-pointer flex-col gap-3 transition duration-200 ease-in-out hover:bg-white hover:opacity-80"> {shop.imageURL && <Image src={shop.imageURL} alt="My Image" width={500} height={200} />} <div className="mt-3 text-lg font-semibold decoration-8">{shop.title}</div> {shop.rating && shop.price ? (...

dnd-kit with trpc animation glitch on reorder

i'm having this issue with trpc and https://dndkit.com/ (sortable preset), where the reorder of an item works, but causes a weird jump in the card, originating from the top of the viewport. if anything, i think it has to do with react-query fetching behavior, but i'm entirely lost as to what could be causing this. i simplified the components below, and this is the general idea of what they look like: ```ts // fetches and renders the list (near identical to the docs) const BasicListEditor = () => { const { data: selections } = api.selection.getOwnSelections.useQuery();...

Is it not reccomended to inline SVGs as JSX?

I prefer doing this so as to have the svg be a component that I can pass style props to easily. But for some reason, one svg in particular is around 1KB gzipped! Here's the code for reference:

Recursive Queries - Not supported by Prisma (yet)

Prisma does not support recursive queries (ie. get all nested self relations until there is no data). https://github.com/prisma/prisma/issues/4562 Has anyone here come across any fancy work around? Any ORMs that support this that could be integrated within T3 somehow?...

Log management for the server

It is the first time I need to implement logging and I am not sure who to ask. There is a 2 kind of informations I want to track : - how long each request take server side - for each user what are the request they make and on which frequency...

How to fall under api limitations with on demand data?

I have a react application that displays a map and the current vehicle position that is updated every 10 seconds. Api limits me to 150 requests every 15 min which is not an issue for myself, however if I am expecting to launch this to 50+ daily users. What would be best way to still serve the most up to date information while still falling under api limitations?

Single element type of inferred router output array type

I'm trying to type a single object from an array but I don't want to manually create it. I've been using inferRouterOutputs so I was wondering if it's possible to remove the [] from the type so that it is just an object. ``` type RouterOutput = inferRouterOutputs<AppRouter>;...

Compiling TailwindCSS for Monorepos

I have a monorepo with workspaces - ui and client. I want to create components in ui and use them in client. I am using tailwindcss as my style provider, but am having a very hard time compiling it. I am not going to publish them on NPM, and it just need to work in client which is a nextjs project. Any help is appreciated....

How to transform type of object with TS so that the values are of same type but wrapped in Array

Can someone pls help with this issue I'm having. I have a type like so: ``` const myZodType = z.object({ name: z.string(), ...})...

How to deal with more complex / repeating backend logic?

Sometimes, when developing an application, more complex situations occur. For example, I have a category, which is assignable to either a post or a user, with the post and user obviously being to different entities in the db. Let's say I want to use the post and user, populated with their assigned categories in the frontend....

Where the heck do you collect data for analytics?

Attached is an excalidraw screenshot to hopefully explain this better, I'm struggling to figure out where to put analytics to be collected In my application, there are a lot of sources that data can come in from, lets take a user changing their consent for example. This event can come in from:...