From the course: Master React 19 and Next.js 16 with Hands-On Projects and Real-World Applications
Unlock this course with a free trial
Join today to access over 25,200 courses taught by industry experts.
Include user and course when posting a message
From the course: Master React 19 and Next.js 16 with Hands-On Projects and Real-World Applications
Include user and course when posting a message
Hello and welcome. In this session, I will guide you through the process of enhancing our chat application. Our main goal is to ensure that when a user posts a message, it is intelligently linked to both the currently logged in user and the specific course chat room they are in. This is a fundamental feature for any multi-user, multi-room chat system, it allows us to correctly attribute messages and display them in the right context. We will be working on both the client-side form submission in our Next.js component and the server-side API endpoint that handles saving the message to the database. We will not use a server action for posting messages because it is not compatible with SSE events in Next.js. Okay, let's begin by importing a new hook from React. At the top of the file, I am adding useRef to the import statement from React. The useRef hook is a powerful tool that allows me to create a mutable reference to a DOM element. I'm going to use this to get direct access to our…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Introduction to Next.js and project setup15m 30s
-
(Locked)
File-based routing and navigation5m 57s
-
(Locked)
Layouts vs. old custom app component9m 9s
-
(Locked)
Nested layout3m 59s
-
(Locked)
Next.js 16: SSR / ISR / SSG16m 41s
-
(Locked)
Client components and server components9m 54s
-
(Locked)
Passing data from server to client components6m 37s
-
(Locked)
Interleaving server and client components11m 40s
-
(Locked)
Context providers19m 22s
-
(Locked)
Third-party components16m 7s
-
(Locked)
Next.js 16 API routes and fullstack features30m 28s
-
(Locked)
Using a database in Next.js (fullstack data persistence)11m 40s
-
(Locked)
Server-sent events in Next.js (SSE)20m 59s
-
(Locked)
Database relationships (users + messages)17m 42s
-
(Locked)
Building a functional contact form31m 13s
-
(Locked)
Server actions, a powerful Next.js feature11m 27s
-
(Locked)
Add metadata to client and server components9m 24s
-
(Locked)
Build a database viewer19m 30s
-
(Locked)
Build a courses table and seed it with courses data8m 43s
-
(Locked)
Switching from API to database data + image optimization17m 34s
-
(Locked)
Next.js params15m 40s
-
(Locked)
Authentication: Users table creation and seeding15m 47s
-
(Locked)
Authentication: Configuration with JWT26m 35s
-
(Locked)
Authentication: Building an auth-aware navigation bar20m 6s
-
(Locked)
Authentication: Login27m 13s
-
(Locked)
Authentication: Signup28m 9s
-
(Locked)
Authentication: Email verification11m 54s
-
(Locked)
Authentication: Restrict pages6m 51s
-
(Locked)
Authentication: Password reset37m 43s
-
(Locked)
Authentication: Google login16m 52s
-
(Locked)
Authentication: GitHub login5m 54s
-
(Locked)
Adding foreign keys for course in messages9m 34s
-
(Locked)
Add Zod validation to message form9m 4s
-
(Locked)
Restrict chat rooms to a single course13m 46s
-
(Locked)
Using ErrorBoundary and Suspense for safe component rendering10m 28s
-
(Locked)
Pull messages using a server action10m 21s
-
(Locked)
Implementing pagination for message history15m 35s
-
(Locked)
Include user and course when posting a message14m 36s
-
(Locked)
Broadcast new message to connected users12m 17s
-
(Locked)
Optimistically delete a message and notify all users in real time19m 29s
-
(Locked)
Optimistically edit a message and notify all users in real time21m 19s
-
(Locked)
Next.js 16 middleware: Restrict protected route13m 22s
-
(Locked)
Next.js 16 middleware: Restrict admin page7m 33s
-
(Locked)