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
Installation:
To get started with this theme, you’ll need to follow these steps:
Prerequisites
- Node.js v14.17.0 or higher
- Yarn v1.22.10 or higher
- PostgreSQL v13.3 or higher
Configuration
- Install the required packages.
- (Optional) Create a new PostgreSQL container with Docker.
- Copy the
.env.examplefile to.envand fill in the required environment variables. - Push the database schema and seed data to the database.
- 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.