Table of Contents
IntroductionScott Moss introduces the course and provides course materials including the GitHub repository.
Quick Next.js ReviewScott does a brief refresh of Next.js for students skipping introduction courses, discusses file naming conventions, and Next.js's compatibility with global styling using React.js.
Course App ReviewScott briefly talks about Vercel as the deployment service to be used, walks through the files included in the repo, and gives a first look at what the application looks like in the browser. Note: Due to the older dependencies used in the repo, we recommend using Node version 10.24.1 with this application.
Dynamic Content & Static RoutesScott explains the benefits of making an application with dynamic content including increasing production by avoiding hard coded mistakes, briefly mentions headless CMS. The getStaticProps method can be used to add dynamic content to a page by making a call to a custom built CMS.
Dynamic Content & Dynamic RoutesScott briefly recaps the project files that hold application's content, implements getStaticProps on the index page to pull data from the CMS, and returns the data using a package called matter. Content routes are also implemented to pull from .mdx file systems using Next.js to avoid bundling code on the browser.
Set Up Dynamic Paths with getStaticPathsScott live codes a dynamic page with static paths using getStaticPaths to provide Next.js a path to generate at build time. The meaning of fallback is also discussed and how the fallback state effects the length of build time by altering content generation.
Dynamic Content Q&AScott answers students' questions regarding executing child processes in the background, caching in Next.js, where the CSS is located, and including getStaticProps to pull data. How to handle fallback for data that doesn't exist, if client-side data can be accessed with getStaticProps, and functions order of execution are also covered in this segment.
Render Content with getStaticPropsScott live codes page error handling using getStaticProps to check for matching slugs in the file systems and demonstrates how to render content using getStaticProps and renderToString to pull the post data.
Preview Content FeatureScott introduces a built in preview content feature in Next.js which allows users to preview dynamic content by calling an api and setting a cookie to preview content mode. This feature can be used to preview draft data before data goes public.
Implementing Preview ContentScott demonstrates how to implement the preview content and clear preview features using setPreviewData to redirect the user from the public page to draft content. This feature can be used in tandem with a GUI to easily switch between preview and public views for testing purposes.
Authentication with NextAuth.js
Auth with JWTs & NextAuth.js SetupScott demonstrates how to implement auth using the NextAuth.js package to handle user sign up, login, page protection, and database access. Configuring the Nextauth instance using a catch all route and jwt with environment variables including providers, user info, and database is also covered in this segment.
Environment Variables & Connecting to MongoScott walks through setting up environment variables including registering a new OAuth application through GitHub and creating a database cluster in MongoDB Atlas to hold the user data. Run-rs is also available to use for databases for local development.
Q&A and GitHub Auth with OAuthScott answers questions about differences in auth provider set up, what is contained in the session object, and if the session object can be used for authentication. Implementation of the sign in functionality and how to login process using Next-auth with GitHub as the OAuth provider is also covered in this segment.
Auth Q&A and Provider SetupScott answers student questions regarding the difference between sessions and JWT when signing in and opinions on using state management in React.js. The provider is then implemented on the app page to increase performance by avoiding multiple api calls to check user login status.
Protecting Pages in Server Side PropsScott demonstrates how to protect pages by using a getSession hook from Next-auth and getServerSideProps to check if a user is signed in. The home navigation bar will also use getSession to generate a reactive button based on user login status.
Server Side Props Q&AScott answers student questions about how to get refresh tokens for Next-auth.js and if getServerSideProps is hit every time or if client side routing is used.
Connecting to a DatabaseScott walks through how to connect globally to a Mongo database with MongoClient for serverless environments to be stateless. This process will avoid hitting connection limits and multiple connection calls by caching the database connection for later use.
Server Side Data FetchingScott live codes CRUD helper methods to avoid raw database queries and instead use the database created in getServerSideProps. The functions used to get, create, and update folders and docs are covered in this segment.
Data Fetching in Server Side PropsScott implements the previously built CRUD helper functions with getServerSideProps to import data from the server-side database with Next.js. The use of context (ctx) will allow getServerSideProps to determine which states are active without making API calls.
Client Side Mutations & Deployment
Auth Callback Session DataScott demonstrates how to use callbacks in Next-auth.js to create "getting started" documents and folders for new user accounts by passing the session ID and user data as a JWT payload. Once the user data is received by the database the new documents and folders are created via a template.
Setting Up API RoutesScott live codes API routes using next-connect and middleware error handlers to handle users creating new docs.
Client Side MutationsScott walks through adding a new handler for API calls when a new folder is created to merge states for an updated state. A question regarding integrating GraphQL APIs with getServerSideProps is also covered in this segment.
DeploymentScott walks through manually importing GIT repositories via the Vercel CLI, deploying the application to Vercel, and setting up Vercel environment variables so it can be pulled and used locally.