How I Transitioned My Course Platform to Notion: A Developer's Perspective

Over the course of 2+ months, I dedicated my time to developing a web app using Next.js, NextAuth.js, Prisma, SQLite, and other impressive technologies. However, as my focus slowly shifted away from the actual content, I realized that I needed to make a change. That’s when I decided to migrate my course platform to Notion. Take a look at how it turned out: Although I had used Notion on and off for a few years, this summer, I made the conscious decision to fully immerse myself in it....

How to Fix the `prisma/client did not initialize yet` Error on Vercel

If you’re building an app with Next.js and Prisma and encounter the deployment error Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again when deploying it on Vercel, don’t worry. There’s a simple solution to this problem. The error occurs because the database is already initialized in your local development environment, but it needs to be properly generated and imported on the Vercel deployment....

How to resolve the error \"PrismaClient is unable to be run in the browser\" in Next.js

While working on a Next.js website, I recently encountered the error message: “PrismaClient is unable to be run in the browser.” This issue arose after I commented out a single line of code within the getStaticProps() method of my page file. In this particular line of code, I invoked a method from my Prisma instance, which I had previously imported at the top of the page file. Next.js determines which code to utilize for the backend by analyzing the code within getStaticProps(), excluding it from shipment to the frontend....

How to Reverse Order in Prisma for Fetching Data

When working with Prisma, a powerful database toolkit, you might find the need to reverse the order of your fetched data. This is particularly useful when you want to display the newest items first, similar to how Twitter operates. In this blog post, we will explore how to achieve this using Prisma’s orderBy functionality. Let’s consider a scenario where we have a Tweets table and want to fetch the tweets in reverse order, from newest to oldest....

How to Use Prisma: A Comprehensive Tutorial

Prisma is a powerful ORM (Object-Relational Mapping) tool that provides an abstraction layer over databases. In this tutorial, we will explore how to get started with Prisma and use it to build a React application based on Next.js. To begin, create a new Next.js app in a folder using the following command: npx create-next-app Next, include Prisma in your dev dependencies by running: npm install -D prisma Now, you have access to the Prisma CLI utility....

SQL Injection: Protecting Your Application from Attacks

SQL injection poses a significant threat to database-driven applications that rely on SQL queries. The vulnerability lies in the lack of input sanitization, which allows attackers to manipulate the queries’ behavior. Let’s take a look at a simple Node.js example to understand how SQL injection can occur: const color = // coming from user input const query = `SELECT * FROM cars WHERE color = '${color}'` In this case, if the value of color is a legitimate color like “red” or “blue”, the query works as intended....

Using Multiple Fields for a Unique Key in Prisma

I encountered an issue with Prisma that took up some of my time, so I wanted to share how I resolved it. In my model, I didn’t have an id field marked with @id, so I added @@unique() to define the user and tweet fields as a unique constraint. model Like { user Int tweet Int createdAt DateTime @default(now()) @@unique([user, tweet]) } This means that we cannot have duplicate entries with the same (user, tweet) combination....