Nextjs Jwt Auth Boilerplate

screenshot of Nextjs Jwt Auth Boilerplate
nextjs
react
chakra-ui
prisma

NextJS + ChakraUI + Prisma + JWT-based Authentication + Two-Factor Authentication + Sentry

Overview:

This project is a NextJS JWT authentication boilerplate developed as an example of JWT token-based authentication in a web environment for a research project at the University of Applied Sciences of Southern Switzerland. It includes features such as Sentry error tracking, login with email and password, role-based access control, automatic JWT access token refresh, two-factor authentication via email, and protected routes and pages.

Features:

  • Sentry error tracking
  • Fully-typed with TypeScript
  • Login with email and password (hashed with bcrypt)
  • Role-based access control (User, Admin)
  • Automatic JWT access token refresh
  • Two-factor authentication via email
  • Front-end useAuth hook for user session management
  • User session persistence via cookies and local storage
  • New flexible back-end middleware management system

Prerequisites

  • Node.js v14.17.0 or higher
  • Yarn v1.22.10 or higher
  • PostgreSQL v13.3 or higher

Configuration

  1. Install the required packages.
  2. (Optional) Create a new PostgreSQL container with Docker.
  3. Copy the .env.example file to .env and fill in the required environment variables.
  4. Push the database schema and seed data to the database.
  5. Start the development server.

Summary:

This NextJS JWT authentication boilerplate provides a fully functional two-factor authentication system based on JWT tokens. It includes features such as error tracking using Sentry, login with email and password, role-based access control, automatic token refresh, two-factor authentication via email, and protected routes and pages. The installation process requires Node.js, Yarn, and PostgreSQL, and involves installing packages, configuring environment variables, and setting up the database.

nextjs
Next.js

Next.js is a React-based web framework that enables server-side rendering, static site generation, and other powerful features for building modern web applications.

react
React

React is a widely used JavaScript library for building user interfaces and single-page applications. It follows a component-based architecture and uses a virtual DOM to efficiently update and render UI components

chakra-ui
Chakra UI

Chakra UI is a popular open-source React component library that provides a set of accessible and customizable UI components to help developers create modern web applications.

prisma
Prisma

Prisma is a server-side library that helps developers read and write data to the database in an intuitive, efficient and safe way.

fullstack
Fullstack

A fullstack boilerplate provides a starter application that includes both frontend and backend. It should include database, auth, payments, user roles and other backend services to build a fully featured saas or webapps.

eslint
Eslint

ESLint is a linter for JavaScript that analyzes code to detect and report on potential problems and errors, as well as enforce consistent code style and best practices, helping developers to write cleaner, more maintainable code.

framer-motion
Framer Motion

Alpine.js is a lightweight JavaScript framework that simplifies the process of creating dynamic, reactive user interfaces on the web. It uses a declarative syntax that offers a higher level of abstraction compared to vanilla JavaScript, while being more performant and easier to use than jQuery.

typescript
Typescript

TypeScript is a superset of JavaScript, providing optional static typing, classes, interfaces, and other features that help developers write more maintainable and scalable code. TypeScript's static typing system can catch errors at compile-time, making it easier to build and maintain large applications.

react-hook-form
React Hook Form

React Hook Form is a performant, flexible, and extensible form library for React with easy validation. It reduces re-renders and improves performance by using uncontrolled components and native HTML validation, making form handling simple and efficient.