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

Prisma find is acting very weird

I have a user table with a relation field of posts. When I try to use "findFirst" for a user by id, and get the posts using "include: true", I get returned a user with an empty posts array. The array shouldn't be empty. I tried "findMany", and what happens is that it returns ALL USERS in the db, which shouldn't happen, cause there's only 1 user who has this unique id, but the users ARE coming back with a none-empty posts array....

What is the best practice to upload file using multer and create a record in Prisma

Recently I have been obsessed with uploading files with trpc, I have files that I do not want to keep on the cloud server and I want to keep them locally. I've done the uploads with Multer, but how do I associate them to my Prisma, for example Patient table? What is the best practice for this situation?

How to implement this feature using tailwind

In the video they use MaterialUI and StyledFIrebaseUi which for some reason doesn't work now, So I'm trying to implement this sign-in flow using tailwind but I'm not sure how to do this using one modal only

create-t3-turbo naming in package.json files

What does @acme/ stand for? I mostly see it in package.json files.

instagram-reddit type app with socket io

so i am making an instagram/reddit type app where its just a bunch of posts and likes/dislikes/comments I want to implement web sockets so that you can see the likes and dislikes for every post updating live instead of having to refresh page so one way i can do that is when each time a person likes/dislikes then the server will emit to all the other clients and update their data ...

Protect certain route after auth ? NextAuth middleware

Hi is there any possible way to protect my pages after auth in middleware ? i dont want to do it in client side since it will flash the content for a second , and if i do it with unstable_getServerSession it feels kinda toomuch code duplication ? if i have auth i want to protect page A,B,C,D but if i dont have auth i want to protect page E,F,G,H ...

Best database setup

Hello all. I’m starting a fresh app and I wanted to know what are your favorite Postgres database setups with prisma and why. I am intrigued by pocketbase, even though that’s not Postgres, but I wanna know what else is out there. Seems like PlanetScale is standard but I would love to know more about Xata.

Is There A Better Way To Communicate With A TRPC Endpoint When You Don't Want To Re-render?

Hello, I was wondering if there is a better way to send and receive data than useQuery() / useMutate() if you do not want to re-render at all and what you are doing is purely for internal data stuff. I could still just use useMutate(), and then have a effect that is subscribed to its value and then update state but than seems like alot of hoops to jump through....

Make Intellisense Show Programmatic Option First Instead of Component Provider Emmet Abbreviation

Hello, Is there a way to make VSCode show the programatic method of writing a query/mutation instead of the provider method first when using TRPC? Thanks in advance for the help!...

Migrating from Prisma client to Kysely issue

I am evaluating various aspects of changing from Prisma client to Kysely but i seem to have hit a small snag basic tutorial i followed was from nexxel https://www.nexxel.dev/blog/typesafe-database in my prisma schema i have ...

clean way to protect page and redirect

What is the clean way to dont allow not authenticated user access to the page and instead redirect him to sign in?

Correct way to tell typescript object's index is not undefined when mapping over keys ?

As shown in the example I am mapping over the keys of an object so if I am not wrong the value obtained should never be undefined so how do I tell typescript that without using as <typeof_value_here>.
Is using type casting here with as the correct way to do it or is there a better way to do it ?...

Overwrite the default types of AdapterUser

Hey 👋 I'm writign a custom adapter for Next Auth, and it breaks quite a lot of the default behavior, so I'd like to modify the default types provided. For some reason, it's not letting me, any ideas why?...

How to handle multiple react-query `Providers`?

Working on a codebase that uses TRPC and a library called WAGMI that uses react-query. Since both TRPC and WAGMI provide their own QueryClientProviders I'm trying to figure out what the right way is to go about managing both of them

how to better handle client side validations in svelte-kit?

I'm working on a side project with svelte-tailwind-typescript-zod and I can't for the love of god figure out how to improve client side validations. for now I'm using html validations but if i could use Zod then that would be a hoot!! any thoughts?...

Non strict string literal types

Hey everyone. I want to keep intellisense suggestions when defining something like this:
type SuggestedStrings = "cat" | "dog" | string;
type SuggestedStrings = "cat" | "dog" | string;
I want to be able to accept any other string but have suggestions when defining a variable....

Checking for a cookie as a TRPC middleware

Hello, For a certain group of TRPC routes I would like to check if a certain cookie has a certain value (If it does not, I would like to prevent the request from proceeding). What would be the best way to go about doing this? At the moment, I do not believe that data such as cookie is provided in any sort of context. I would also like it if it could be middleware-like, so that any route using that procedure is guaranteed to be authenticated already. Thanks for the help!...

Chat App Input Text with emojis?

Hi guys, Happy New Year. Well, my problem is that i'm building a chat app, and i'm trying to build an input that allow the user to insert an Emoji, just like Whatsapp or any other pro chat app. Well the problem is that for doing that, you have to a div contenteditable, because i need to show the images for Apple Emoji for example, not html pure emojis. So i'm a little stuck here, because i need to have in mind the cart selection, parsing html, turing back to html, in the end is a hell. Does anyo...

Prisma many-to-many self-relation

I want to have multiple m2m self-relation fields. For a user I need fields for parents, friends, partners, etc, and all of them are users as well. Prisma let me have 2 fields like this, but generates weird syntax if I do more than 2. Anyone experienced with this?...

NextJS middleware

Hello, In the middleware file, I want to check if the user is authenticated and allowed to visit specific pages. Currently how I do it is as following:...