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

How to redirect with new headers back to the same page?

User goes to page /foo, we check if this page is protected, if it is, we rewrite the page to something else using middleware, now this identical page has a password form. The goal is to authenticate the password, and if its correct, redirect them back to the original page with headers pretty much allowing the user to skip the rewrite in the middleware and view the protected page. Is this possible?...

The Edge - what's the point

so as far as i know the edge move a server close as possible to your user right? but then what's the point of the edge if the database is server located in one region which is depend one the user if the request gonna be fast or slower right? i see the edge fit for applications where there's no database maybe? i'm new to all of these so if you can explain when should i use the edge or i'm missing something with all of that...
Solution:
Cold starts bad

cloudflare R2 in Versel?

Has anyone here used R2 in their NextJS app hosted on Versel? Trying to save money on bandwidth What are the challenges to this...

React.FC equivalent for RSC

Is there a "React.FC" equivalent for React Server Components?

How do I use the return type of a function with overloads that will be returned in the same function

I'm creating a library, but I have a problem when I use a function with overloads to return itself in some instances. It won't be able to determine the right type.
Solution:

Media not rendering on first try, only after a refresh

Hey, first of all, this is my first complex Next.js project, so it is very probable that I am doing something stupid. So the problem is that, on the homepage of my app I have a video (1) and an image (2) that render only after a refresh, they won't show the first time the website is accessed. Both of them are stored locally in the /public folder. I have attached a before and an after-refresh screenshot with the problem. You can test this live here: https://moodvie.edwardcs.com/...

Route Guarding with nextjs

How do you implement route guarding with nextjs? Not too sure what would be the recommended way to do it. Basically what I is use a context provider then “useeffect“ my way into route guarding Context: Firebase for backend and auth...

the URL must start with the protocol `mongo`

I have been geting this error recently, and I have no idea why. my mongodb DATABASE_URL is without " ", I have tried deleting and installing node_modules again and again. Building the app works, dev mode works too. But "prisma db push" and other commands show the attached error.

Read and Write in Next Js Is not working in production (vercel)

this code is working in local environment but not working in production can anyone tell me how to resolve this issue? ```js import { NextResponse } from "next/server"; import { promises as fs } from "fs"; import path from "path";...

Desperate for help with Trpc resolver.

How can i get resolve({ default: base64Data }); to only trigger once trpc has returned success or failure. class MyUploadAdapter { private loader: any; private mutation: any;...

useRouter query

How do y'all handle typescript with nextjs's query params? Currently I'm doing
const cartId = query.cartId as string;
const cartId = query.cartId as string;
, but I'd rather not use the "as" keyword. query.cartId is of type string | string[] | undefined...

Password hashing on EDGE?

I'm making an app and noticing that vercel's serverless functions are taking very much time to complete So, I tried migrating to the EDGE runtime as I saw theo suggest in his video, however I get an error as soon as I try to build bcrypt (since it uses node-gyp and everything) And I wanted to know how you guys handled authentication, and more specifically, password hashing, on the edge...

Auth.js Muti-device Support

I'm implementing auth right now in a site that the user will likely be switching from mobile to desktop with frequently. I wanted to make sure that just because they do this their JWT is not going to just expire and force them to log back in when they swap devices. Thanks!...
Solution:
the client can have multiple devices signed at the same time

NextJS should I use a headless CMS?

Hello I am working on a project that is a multi user blog where anyone can create a post and comment. I was curious if I should try to use a headless CMS for something like this (I am getting mixed signals on this) Or should I just roll my own postgresSQL database with Prisma....

How to define this exact relation on prisma

Given this two models, how could I implement a relation between them, where a duel has 2 user Ids in it, one in the loser column, and one in the winner column, how should I define this? Prisma screams at me for putting 2 user relations on the same model. ```typescript model User { id Int @id @default(autoincrement())...

How much do y'all charge for your apps?

I have created two complete custom apps for clients, took 40-60 hours a piece. Just curious how y'all price your stuff....

Drizzle client side vs server side?

hi can someone help explain to me a bit about drizzle? as far as i can tell, its doing client side api calls and requires me to use NEXT_PUBLIC env variables which isnt secure right? is it possible to put my drizzle calls into server and therefore not need to expose the env variable to browser?

t3-turbo + next-i18n + tRPC doesn't work on Vercel only locally

Hi. I tried to implement server side localisation in tRPC according to this article https://levelup.gitconnected.com/add-i18n-to-t3-stack-apps-8010e88a3a81 and this linked repo https://github.com/EugenVolosciuc/t3-i18n-demo. It is not turbo repo (just create-t3-app) and works both locally and on Vercel. My implementation with turbo repo https://github.com/martin-prochazka/create-t3-turbo-next-i18n works only locally (it is fork of create-t3-turbo simplified for this showcase): https://create-t3-turbo-next-i18n-nextjs.vercel.app/...

Anyone have an exampe of two nextjs applications in a single repo?

Basically I want to have a website for the customer facing site and another for the admin portal to manage customers. I am planning on having it share Prisma schema.