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

Typed API contract builder

I've external third party API which doesn't expose any types (no typescript compatible). I would like to be able to define type safe contracts for that API so body, query params, response type etc. is all type safe. Ideally it should be based/wrapped on fetch or implemented with https://github.com/elbywan/wretch or https://github.com/unjs/ofetch. This won't be exposed for anyone. It will be used only internally and only on the backend side so no need for any browser compatibilty. I just want an easy type safe way to define input/outputs and use it from within my express/trpc calls ...

Empty JWT payload, persisting role permissions and "jankiness" with next-auth

Hello lads. I'm struggeling to get next-auth up and running. It has been working decently, but I have several issues that I'm unable to resolve, even after days of trying out different solutions, package versions and more. Here's what I'm trying to do:...

CORS Issue on only some API calls

I have multiple API calls on my project deployed to vercel but only some of them face CORS issues, for example: ``` import { db } from "../../lib/db"; ...
Solution:
```ts //You can do it like this. export async function GET(request: Request) { return new Response('Hello, Next.js!', {...

How to make protected routes in nextjs appdir

Hello! So I’m doing authentication and I want to make it so I fetch the user data on first load, but then reuse this data to check on all protected pages. How do I go about this? . I thought about fetching this data each time they go to protected routes but isn’t that ineffective (spends more time)...
Solution:
Hello! So I’m doing authentication and I want to make it so I fetch the user data on first load, but then reuse this data to check on all protected pages. How do I go about this? . I thought about fetching this data each time they go to protected routes but isn’t that ineffective (spends more time)...

re-send email verification endpoint

Hi guys, what would be the best way to achieve 'send verification email' in t3? I couldn't get my head around exposing 'resendEmailVerification' endpoint to client using trpc. I want users to be able to receive Verification Email inside my profile page....

Animation: Slide-In on Scroll

What is the best library or resources for implementing a cool slide-in on scroll in react or Next.js application... I've search but no solution. I used framer-motion for other animation but can't seem to get a slide-in on scroll preference. Please help with a perfect resources🙏

implement discord-like account switching

I want the user to be able to sign in with multiple accounts, then switch between them similar to how you switch account in discord. However, I could not find any information on how to implement this with next-auth (or just implementing it in general). How can I implement this? Tysm in advance! For additional context, I am using appdir, and there is an external server that I will be authenticating against, which returns me a JWT when the user signs in (me sending them a request with username & password). This server is outside of my control....

tRPC failed on <no-path>: Invalid API key

im not really understanding why this is happening. ``` page.tsx:80 Uncaught (in promise) TRPCClientError: Invalid API key at TRPCClientError.from (webpack-internal:///(app-client)/./node_modules/@trpc/client/dist/transformResult-9a244fe7.mjs:9:20)...

How to implement different not-found pages for diffrent routes in next js app dir

Hi trying to implement a different 404 page for different parts of an app separated by route groups https://nextjs.org/docs/app/building-your-application/routing/route-groups Is there currently any way to do this apart from checking the pathname in the root app/not-found file. ( Tried putting a not-found file in the separate route groups also but doesn't seem to be working ). ty : D...

dumb async questions

Hi, I never really was able to deeply await promises and async functions. I have a couple of questions on error handling. (axios) How can I save a variable from an async get or post using .then on the top scope. Is it possible to error handle an await statement instead of it always crashing my run...

Planetscale - New field with default(uuid) erroring out?

```model Server { apikey String @unique @default(uuid()) }...
Solution:
FIXED! Terrifying though, unsure if correct. I updated the database to have the apikey field. String?. ...

How to use Datadog APM with Next.js on Vercel?

Hey folks! I'm trying to configure Datadog's APM to work with Next.js on Vercel. As far as I understand, running dd-trace requires a Datadog "agent" to be installed on the target platform. I'm assuming that it's not possible on Vercel, so I'm wondering if there's a workaround for that?...

Do people still use Redux Saga ?

I was casually learning redux where I came across Redux Saga. I have used Redux Thunk before. But when I saw the Redux Toolkit documentation I found this (attached screenshot). So what's the opinion on this topic ? Do we need Sagas or is it just better to go along with Thunks.

Downgrading zod version to 3.21.1 to be able to use zod-prisma-types

There were some changes in zod 3.21.2 which breaks functionality fo zod-prisma-types, when I try to downgrade the version there is problem with env.mjs especially files like db.ts or auth.ts which are using .env variables. Error in typescript Unsafe member access .NODE_ENV on an any value.

index files consuming a lot of memory

Does using index file to gather exports from multiple files to get shorter import consume a lot of memory? 🤔 Someone here that has a solution on how we can use imports like in the first image without using a lot more memory?...

Questions about GPL licensing

I am going to be using a GPL licensed application for a project. I self host the application. I use the provided api to interact with it on my front end in another application. With GPL do I have to open source and make public my front end entirely? I’m basically getting confused on using GPL licensed things in other applications but not modifying or rereleasing them

where clause in drizzle insert

```js await db .insert(trackingQuestions) .values({ questionNumber: questionNumber,...

Secure way of previewing PDF in react app (without storing locally in readable way)

I have a client that wants to securely preview PDF on a public PC. Normally, PDF is generated on a backend and downloaded to PC. However, if the user is on a public PC they don't want to store the PDF locally, to prevent a third party from obtaining it. ...

Prisma Transaction not executing properly in a Production environment

I have a Heavy Prisma transaction that skips the Promise.all portion in production in other computers but works find on my laptop in production. what is the issue?

Tailwind compiler not working properly with Turborepo

I am using @marminge 's acme-corp as a template and I have a UI component which is pretty much exactly the one in his project, same tailwind config, same everything. However, in the nextjs project the compiler does see some styles and applies them but not all of them, see the photos added. Here are also the tailwind configurations and my repo. https://github.com/DavidIlie/laundrey UI tailwind config:...