mohsin-shaikh / saas-template

SaaS Starter Template build with Next JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SaaS Template - Advanced Guide (2024)

image

This is a repository for SaaS Template - Advanced Guide (2024)

Warning This project is still in development and is not ready for production use.

It uses new technologies which are subject to change and may break your application.

Tech Stack

Features

  • Authentication
    • ๐Ÿ” Next-auth v5 (Auth.js)
    • ๐Ÿš€ Next.js 14 with server actions
    • ๐Ÿ”‘ Credentials Provider
    • ๐ŸŒ OAuth Provider (Social login with Google & GitHub)
    • ๐Ÿ”’ Forgot password functionality
    • โœ‰๏ธ Email verification
    • ๐Ÿ“ฑ Two-factor verification
    • ๐Ÿ‘ฅ User roles (Admin & User)
    • ๐Ÿ”“ Login component (Opens in redirect or modal)
    • ๐Ÿ“ Register component
    • ๐Ÿค” Forgot password component
    • โœ… Verification component
    • โš ๏ธ Error component
    • ๐Ÿ”˜ Login button
    • ๐Ÿšช Logout button
    • ๐Ÿšง Role Gate
    • ๐Ÿ” Exploring next.js middleware
    • ๐Ÿ“ˆ Extending & Exploring next-auth session
    • ๐Ÿ”„ Exploring next-auth callbacks
    • ๐Ÿ‘ค useCurrentUser hook
    • ๐Ÿ›‚ useRole hook
    • ๐Ÿง‘ currentUser utility
    • ๐Ÿ‘ฎ currentRole utility
    • ๐Ÿ–ฅ๏ธ Example with server component
    • ๐Ÿ’ป Example with client component
    • ๐Ÿ‘‘ Render content for admins using the RoleGate component
    • ๐Ÿ›ก๏ธ Protect API Routes for admins only
    • ๐Ÿ” Protect Server Actions for admins only
    • ๐Ÿ“ง Change email with new verification in the Settings page
    • ๐Ÿ”‘ Change password with old password confirmation in the Settings page
    • ๐Ÿ”” Enable/disable two-factor auth in the Settings page
    • ๐Ÿ”„ Change user role in Settings page (for development purposes only)
  • Data Table Server Side Renderings
    • Server-side pagination, sorting, and filtering (useTable hook)
    • Customizable columns (dataTable and columns props)
    • Dynamic debounced search inputs (searchableColumns prop)
    • Dynamic faceted filters (filterableColumns prop)
    • Optional notion like advanced filtering (advancedFilter prop)
    • Optional floating bar on row selection, rendered at the bottom (floatingBarContent prop)
    • Action to delete rows (deleteRowsAction prop)

Prerequisites

  • Node version 18.x.x
  • Postgres DB or MySQL DB

Cloning the repository

git clone https://github.com/mohsin-shaikh/saas-template.git

Install packages

npm install

Setup .env file

# POSTGRES
POSTGRES_USER=postgres
POSTGRES_PASSWORD=
POSTGRES_DB=saas_template

# Nest run locally
DB_HOST=localhost
# Nest run in docker, change host to database container name
# DB_HOST=postgres
DB_PORT=5432
DB_SCHEMA=public

# Prisma database connection
DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${DB_HOST}:${DB_PORT}/${POSTGRES_DB}?schema=${DB_SCHEMA}&sslmode=prefer
DIRECT_URL=${DATABASE_URL}

AUTH_SECRET="<Auth Secret>"

GITHUB_CLIENT_ID=
GITHUB_CLIENT_SECRET=

GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

RESEND_API_KEY="<Resend API Key>"

NEXT_PUBLIC_APP_URL="http://localhost:3000"

Setup Prisma

npx prisma generate
npx prisma db push

Start the app

npm run dev

Bugs / Issues

  • Use uniformed icons
  • Table selection should reset on-page changes in the data table
  • Consolidate Server Action in a common folder
  • Settings pages are not up to the mark
  • Remove (protected) routes which are not in use

Special Thanks

License

Licensed under the MIT license.

About

SaaS Starter Template build with Next JS

License:MIT License


Languages

Language:TypeScript 99.2%Language:CSS 0.5%Language:JavaScript 0.3%