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

next auth with custom backend

I have a nextjs web app. I have a backend that is managed as a separate server, repo, etc. The backend is where it checks for user role to change the responses, or prevent some users from using some routes etc. How should I go about connecting these two? I tried including credentials from the front end fetch requests but the backend won’t receive the next auth set cookies since they’re not set by the same server....

Migrate from nextjs supabase project to t3 stack

I recently discovered the t3 stack and made a project with it. I love it and I am wondering if it would be a great idea to migrate a current project using Nexjs, Supabase, Typescript and SWR to the T3 stack. However, this would takes some time for sure and there are a few question hanging around : - Does it mean I am loosing all my unit tests on my db (using pgtap) because prisma handle the schema ? - Do I have to replace these tests by something else ? - Do I lost all my RLS ? Is it safe ? Should I use another db maybe ?...

Next 13 middleware breaks page

Hi, Have some simple middleware ```ts export const config = { matcher: ["/((?!login).*)"]...

How React query is being used in T3 App?

Hey folks! I've been tinkering around with a T3-App project and I've stumbled upon something weird. React Query seems to be working just fine, but here's the catch - its provider isn't imported or used in any of my .tsx files. I'm scratching my head here. Anyone got any ideas how this magic is happening? Cheers!

How do I fetch from server side with useMutation?

Hello, I'm trying to do a server side fetch from the mutations that I made in the backend of my t3 app but I'm struggling to understand some things can someone help me please? I'm trying to pass the data from both the queries as props. What would be the most optimal approach to this? This is my code ```export const getStaticProps: GetStaticProps = async ({ locale = "en" }) => { ...

Zod File Upload validation

I'm currently making a file upload form is there any way to validate a file in zod? I tried this https://github.com/colinhacks/zod/issues/387#issuecomment-1191390673 but it didn't seem to work No matter what file i upload it just says image is required...

render canvas on pdf using react

I want to render canvas on my pdf(I can render if there is single page, I want to do it on multiple pages) using react can anyone help me?

Sorting imports

Which of these options is the best for sorting imports? I guess Prettier plugin because sorting imports it's more like the specialization of formatter? 1. trivago/prettier-plugin-sort-imports 2. Build-in to ESlint sort-imports 3. eslint-plugin-import (import/order)...

Prisma Return Type

Hello, I have the following: ```ts async findOne<T extends Prisma.UserSelect>( email: string,...

Need help with dynamically typed rest parameters

```ts type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never; type LastOf<T> = ...

Prisma MySQL findMany problem with chirp tutorial

So my experience is in raw JS and PHP etc, and I have been trying the chirp tutorial to dive into this tech stack. I started chirp about 2.5 months ago before some work commitments called me away. I am now back giving it another try with a fresh install and I am STUMPED. Previously I managed to get posts appearing and had started styling (let's just say, I got up to about 30 mins in through the tutorial https://www.youtube.com/watch?v=YkOSUVzOAA4). Currently I have fallen a bit short of that because I continually get an error from prisma regarding the findMany query....
Solution:
Whelp, it's solved and I have no idea how. Things started working when I commented out the mysql url and provider in the prisma schema while adding the sqlite provider and url.... and then it kept working when I commented out the sqlite provider and url and uncommented the mysql provider and url. Literally no other code was changed. throws hands up in the air I'm guessing the swap between the db types rejigged something in prisma? I'll leave this all here in case someone else comes across this problem and they can try this as a 'solution'....

What is the unofficial name for this CSS effect?

In the video, there is text that shifts down at the end of the title "Plays well with others even...". I've tried Googling this effect but I can find it. Anyone have suggestions?
Solution:
Never mind, I eventually cobbled together my own solution without ever figuring out the name. sadge

DI libraries and using Singletons in NextJS / T3?

Hey guys, I'm just curious if I'm using a Dependency Injection (DI) library within the T3 stack (using NextJS + TRPC), is there any benefit at all to using services as singletons? Wouldn't my container definitions and everything basically just get restarted for every request, thus not really mattering since the same instance won't be used?...

Accessing cookies set by API in Astro frontmatter

I have an external API that we use for login. It sets a cookie on the client browser. The Astro frontmatter however does not see that cookie, as it is unauthorized when trying to access routes that are blocked by login status. But the client can access them fine, making me think its Astro not having the cookie. Any ideas how we can fix this or get around it? I have a feeling a similar type of thing would happen in Next on server components.

Turborepo: prisma-kysely type generation

Weirdest thing: It worked before, and all of a sudden it doesn't. I switched to using prisma-client-js and switch it back to prisma-kysely, then it didn't work. Error log: ``` @thing/db:db:generate: [Error: ENOENT: no such file or directory, open '/Users/me/WorkDir/RepoName/thing/db/types.ts'] { @thing/db:db:generate: errno: -2,...
Solution:
ok fixed. deleted the whole repo and clone it again. thanks for @Tonya (Rustular CTO)

State manager for a realtime chat app?

Im developing a react native chat app. What state manager would you recommend? I've tried redux and valtio, and both seem fitting for this. There will be multiple active chats, group chats, and realtime messaging, so the state will be somewhat complex and dynamic....

enum-union readme review and critique

Hey Guys, I released this little neat enum library a few days ago and posted it into r/typescript and cloud digest messaged me saying the really enjoyed the idea of the library and wanted to feature it on their newsletter which was cool. I was just hoping I could get some feedback on the readme so that way if there are any glaring holes that could complicate understanding for someone I can address it today. https://github.com/codymurphyjones/enum-union...

I want to use Middleware with Database strategy.

Hi, I'd like to use the nextjs middleware using the database sessions strategy for next auth. In the cookies we get the property 'next-auth.session-token', which contains a value of the session's id stored in my database. I could theoretically do a lookup in my DB if this session exists and is linked to a valid user. I'd like some opinions on this, is this a good approach on it? My usecase is securing an admin page for a website, of which I need to acess the user's information in the user table. ``` export function middleware(req: NextRequest) { const session = req.cookies.get('next-auth.session-token'); // Here I could do a call to my API endpoint which will perform a lookup on my database...

good website examples

any publicly shared example of a website, maybe that is a bit more complex than standard app? something with multiple pages, example of front end / back end rendering, good organizational practice as far as code/security, and makes use of next-auth / tailwind / jwt / etc? just wanted to get a bigger picture view of a well coded site thats a bit deeper than t3 if anyone knows any 🙂