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

tRCP can I subscribe to a query?

hi everyone! is there a way of subscribing directly to a query and or invalidate a query directly from the tRCP router? I am using create-t3-app + NextJs + Prisma (pg) Thank you in advance!...

Resources to use work training budget

Hi all, I get a yearly budget to use for training and I’m not sure what to spend it on. Does anyone have any recommended resources or courses that are paid for? Happy to hear about anything; I’m a mid level front end engineer looking to go more full stack so something back end focused would be cool. If i can’t find anything I’ll probably buy a copy of Refactoring UI....

sync realtime DB ( or query sub) to global store

Hey 🙂 I am doing some realtime experiments (nextJS + Supabase or nextJS + tRPC) . In general, have my basic queries/mutations/subs up and running but because the data can/will be used within different components I feel the need of syncing these values into a global store ( Recoil or Redux). Which way do you think it would be best? I am thinking to create a global data wrapper provider but I wonder how scalable this can be and if there are better solutions....

Nextauth Credentials provider

I setup up the Github provider and added the Credentials provider to login with an email and password. The Github provider works fine, but now I tried to add the Credentials provider with jwt, but I can't make it work. Currently I get this error if I try to sign in: ```ts...

NextAuth user in middleware

Hi, I want to get user in the middleware so I can do conditional redirection of the users that don't have specific property yet defined. Like an onboarding screen. How can i get user in the middleware to have something like this: ```ts export function middleware(request: NextRequest) { const isUserOnboarded = sessionData?.user?.isOnboarded; ...

JWT and refresh tokens

I need some advice on how to handle refresh tokens 😦 Is it "good enough" if I generate two JWT tokens (accessToken, refreshToken), and let the resfrehToken just contain one claim, being the userID? And whenever I do a api call from the client and it returns a 401, I then call a /refresh api call, to get a new accessToken and retry the request - as long as the refreshToken is valid?

Proper way to declare with Zod

hi guys, Noob question: Is it better to: A) create types and then check them with zod? or B) better to create Zod objects and then infer types from them? I think i would prefer to do A since it appears cleaner to me, but i also dont see them doing it like this in the docs, so i wonder why?...

Using a Custom Server

Has anyone attempted implementing a custom server for their T3/NextJS project? I have a project currently built on CRA/Express written in JS that I would love to port over to the T3 stack. However, we will still need support for things such as session based auth (using some middleware like express-session) and web sockets. Both of these requirements seem to lend themselves to using a custom server in a NextJS app. Ideally, we would be able to use Fasitfy, if so. Curious to hear any thoughts/suggestions....

Type error with Zod

I haven't worked with Zod yet, I need to fix this error what am I missing here?...

new params when calling trpc

im building new project and using the newest create.t3.app and came across this new params, can anyone tell me what is this? thankss...

Modularized Imports

Is there a way to read variable {{member}} in the following image? I want to pass modified {{member}} into there.

How can I efficiently retrieve settings from my database?

I am saving certain setting keys in my database using a model called "Settings," which has fields for "id," "server_id," "key," and "value." I often need to retrieve multiple settings at the same time, such as "applications enabled" and "applications channel." I think this method is not efficient, so I want to know if there are other ways to retrieve data from this table using Prisma that would be more efficient.

how to add user role to session.user and conditionally render something based on role

I made a new router called userRouter that is enabled when there is a session but the issue is it takes a full second before the condition user.role === something turns from undefined to true

trpc and node express server without react query

Please how can bootstrap a full backend project With trpc and node express server without bundling react query I want the front-end developer to use any library of his choice like axios or fetch just like a regular express app...

Managing tailwind breakpoints and SSR

I asked a similar question yesterday (https://discord.com/channels/966627436387266600/1063696594140139530) but this is more about how the original problem relates to SSR. I have a application that I developed for desktop that I am trying to make responsive. Yesterday I asked about how to access tailwind breakpoints in my js. After getting some answers and doing some more googling I came up with a custom hook for detecting screen size and stashing it in a context for any of my components to use. However, the hook is based on reading window.innerWidth and window.innerHeight inside of a useEffect() so SSR ends up kinda broken. The app loads in assuming it is a desktop app and then runs the hook and the layout shifts. The only way I can think to avoid this is to use (for example) className="hidden lg:block" . To me, the idea that each page has all components for every size variation baked in seems like a nightmare to manage. It also seems like it will bloat my code significantly. For instance, I am using some MUI buttons that i want to be size=large on desktop and size="medium" on mobile. If I am going to do this in tailwind alone ill need to have multiple copies of the same button in the DOM each with different props....

npx prisma migrate dev

I'm trying to create my first migration with npx prisma migrate dev, but when I run the command, it seems to be stuck in an endless loop, in this screenshot, the command was executed ~20 minutes ago, and it's still stuck.

prisma.user.create type is 'any'

I defined the prisma schema, but when i try to add a user to the database, it's type is 'any', isn't prisma supposed to generate type definitions for my schema?

Is Postgres RLS a must have?

Hi guys, if I'm using TRPC's protectedProcedure in my routers, is it recommended to enable and set up row-level-security for my Postgres DB? Or do protected routers in TRPC make RLS redundant? Thanks!

handling tailwind breakpoints in react

I am trying to figure out how to turn my webapp which was built for desktop into something more responsive. I am using t3 stack with tailwind. I know that tailwind provides breakpoints (sm, md, lg, etc), but im struggling to figure out a good way to change my layouts based on this. For instance, I have a sidebar in the desktop app that i want to turn into a bottom bar for the mobile app which uses a completely different component. How can my react code know if the screen size is sm, md, or lg?

Optimizations tradeoff

As the title says, what are the trade offs when loading components lazily? I haven't seen any in my application yet, but my theory is that the tradeoff, most of the time, would be aesthetical? For example, the components would pop into existence if I don't design it well and it's not gonna look good...