Skip to content

alexechoi/nhost-next-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

19 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Nhost Next.js + shadcn/ui Template

A production-ready, full-stack authentication boilerplate built with Next.js 15, Nhost.io, and shadcn/ui. This template provides a complete authentication system with email verification, protected routes, and a modern design system.

Nhost + Next.js shadcn/ui TypeScript Tailwind CSS

✨ Features

πŸ” Complete Authentication System

  • Email/Password Authentication with Nhost
  • Email Verification Flow with resend functionality
  • Smart Routing based on authentication and verification status
  • Persistent Auth State across page refreshes
  • Automatic Redirects for protected routes

🎨 Modern UI/UX with shadcn/ui

  • shadcn/ui Design System - Professional, accessible components
  • Clean, Modern Interface - No gradients, authentic shadcn styling
  • Lucide React Icons - Consistent iconography throughout
  • Responsive Design that works on all devices
  • Dark Mode Support with system preference detection
  • Smooth Animations and loading states
  • Accessible Components with proper ARIA labels

πŸ›‘οΈ Security & Best Practices

  • Protected Routes with authentication guards
  • Email Verification Required for dashboard access
  • Secure Environment Variables handling
  • TypeScript for type safety
  • Error Handling with user-friendly messages

πŸ”§ Developer Experience

  • Next.js 15 with App Router
  • shadcn/ui - Modern component library
  • Tailwind CSS for styling
  • TypeScript for type safety
  • Lucide React for icons
  • ESLint & Prettier configured
  • Hot Reload development server
  • Comprehensive Documentation

🎯 Live Demo

  • Coming Soon

πŸš€ Quick Start

Prerequisites

1. Clone & Install

git clone https://github.com/your-username/nhost-next-template.git
cd nhost-next-template/nhost-next
npm install

2. Set up Nhost Project

  1. Create Nhost Project:

    • Go to Nhost Dashboard
    • Click "Create New Project"
    • Choose your region and project name
  2. Get Project Credentials:

    • Copy your Subdomain and Region from the dashboard
  3. Configure Environment:

    cp .env.example .env.local

    Update .env.local:

    NEXT_PUBLIC_NHOST_SUBDOMAIN=your-project-subdomain
    NEXT_PUBLIC_NHOST_REGION=your-project-region

3. Set up Sample Database (Optional)

For the movies demo data, run this SQL in your Nhost SQL Editor:

CREATE TABLE movies (
  id SERIAL PRIMARY KEY,
  title VARCHAR(255) NOT NULL,
  director VARCHAR(255),
  release_year INTEGER,
  genre VARCHAR(100),
  rating FLOAT
);

INSERT INTO movies (title, director, release_year, genre, rating) VALUES
  ('Inception', 'Christopher Nolan', 2010, 'Sci-Fi', 8.8),
  ('The Godfather', 'Francis Ford Coppola', 1972, 'Crime', 9.2),
  ('Forrest Gump', 'Robert Zemeckis', 1994, 'Drama', 8.8),
  ('The Matrix', 'Lana Wachowski, Lilly Wachowski', 1999, 'Action', 8.7);

Important: Enable "Track this" and set permissions for the public role.

4. Run Development Server

npm run dev

Open http://localhost:3000 to see your app! πŸŽ‰

πŸ“± Authentication Flow

πŸ”„ Complete User Journey

  1. Landing Page (/)

    • Shows different content for authenticated/unauthenticated users
    • Beautiful feature showcase
    • Call-to-action buttons
  2. Authentication (/auth)

    • Sign Up: Creates account + sends verification email
    • Sign In: Logs in existing users
    • Smart Redirects: Based on verification status
  3. Email Verification (/auth/verify-email)

    • Required for new users
    • Resend Email functionality
    • Clear Instructions and status updates
  4. Dashboard (/dashboard)

    • Protected Route - requires verified email
    • User Information display
    • Sample Data from GraphQL API
    • Sign Out functionality

πŸ›‘οΈ Route Protection Logic

// AuthWrapper handles all routing logic
if (!authenticated) {
  redirect('/auth')  // Public pages only
}

if (authenticated && !emailVerified) {
  redirect('/auth/verify-email')  // Must verify email
}

if (authenticated && emailVerified) {
  redirect('/dashboard')  // Full access
}

πŸ“ Project Structure

src/
β”œβ”€β”€ app/
β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”œβ”€β”€ page.tsx              # πŸ” Login/Signup page (shadcn forms)
β”‚   β”‚   └── verify-email/
β”‚   β”‚       └── page.tsx          # βœ‰οΈ Email verification (shadcn cards)
β”‚   β”œβ”€β”€ dashboard/
β”‚   β”‚   └── page.tsx              # 🏠 Modern dashboard with stats
β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”œβ”€β”€ AuthWrapper.tsx       # πŸ›‘οΈ Route protection
β”‚   β”‚   β”œβ”€β”€ Providers.tsx         # πŸ”§ Context providers
β”‚   β”‚   └── ui/                   # 🎨 shadcn/ui components
β”‚   β”‚       β”œβ”€β”€ button.tsx
β”‚   β”‚       β”œβ”€β”€ card.tsx
β”‚   β”‚       β”œβ”€β”€ input.tsx
β”‚   β”‚       β”œβ”€β”€ label.tsx
β”‚   β”‚       β”œβ”€β”€ alert.tsx
β”‚   β”‚       β”œβ”€β”€ badge.tsx
β”‚   β”‚       β”œβ”€β”€ avatar.tsx
β”‚   β”‚       └── separator.tsx
β”‚   β”œβ”€β”€ layout.tsx                # 🎨 Root layout
β”‚   └── page.tsx                  # 🌟 Landing page (clean design)
β”œβ”€β”€ lib/
β”‚   β”œβ”€β”€ nhost.ts                  # βš™οΈ Nhost client config
β”‚   └── utils.ts                  # πŸ”§ shadcn/ui utilities
└── ...

🎨 shadcn/ui Components & Design

🏠 Landing Page

  • Clean Hero Section - No gradients, modern typography
  • Feature Cards - shadcn Card components with icons
  • Tech Stack Badges - shadcn Badge components
  • CTA Buttons - shadcn Button with variants
  • Responsive Grid Layout - Mobile-first design

πŸ” Authentication Forms

  • shadcn Card Layout - Professional form container
  • shadcn Input & Label - Accessible form controls
  • Toggle Sign Up/Sign In - Smooth state management
  • shadcn Alert Components - Error/success messages
  • Loading States - Lucide Loader2 icons
  • Black Background - Modern, high-contrast design

βœ‰οΈ Email Verification

  • shadcn Card Structure - Clean, organized layout
  • Lucide Icons - Mail, ArrowLeft, Loader2
  • shadcn Alert System - Status feedback
  • shadcn Buttons - Consistent interaction patterns
  • Professional Typography - Clear hierarchy

πŸ“Š Dashboard

  • Stats Overview Cards - Key metrics at a glance
  • User Profile Section - Organized with Lucide icons
  • Modern Movie Cards - Replaced table with card layout
  • Star Ratings - Visual rating system
  • Status Badges - Color-coded verification status
  • Avatar Component - User profile representation

πŸ”§ Configuration

Environment Variables

Variable Description Required
NEXT_PUBLIC_NHOST_SUBDOMAIN Your Nhost project subdomain βœ… Yes
NEXT_PUBLIC_NHOST_REGION Your Nhost project region βœ… Yes

Nhost Configuration

// src/lib/nhost.ts
export const nhost = new NhostClient({
  subdomain: process.env.NEXT_PUBLIC_NHOST_SUBDOMAIN,
  region: process.env.NEXT_PUBLIC_NHOST_REGION,
})

πŸš€ Deployment

Vercel (Recommended)

  1. Push to GitHub:

    git add .
    git commit -m "Initial commit"
    git push origin main
  2. Deploy on Vercel:

    • Connect your GitHub repository
    • Add environment variables in Vercel dashboard
    • Deploy automatically
  3. Environment Variables:

    NEXT_PUBLIC_NHOST_SUBDOMAIN=your-subdomain
    NEXT_PUBLIC_NHOST_REGION=your-region
    

Other Platforms

  • Netlify: Works out of the box
  • Railway: Add environment variables
  • Render: Configure build settings
  • AWS Amplify: Set environment variables

πŸ› οΈ Development

Available Scripts

npm run dev      # Start development server
npm run build    # Build for production
npm run start    # Start production server
npm run lint     # Run ESLint

Development Tips

  • Hot Reload: Changes reflect instantly
  • TypeScript: Full type checking
  • Console Logs: Check browser console for debugging
  • Network Tab: Monitor GraphQL requests

πŸ” Troubleshooting

Common Issues

❌ "createContext only works in Client Components"

  • βœ… Fixed: Using Providers.tsx wrapper with 'use client'

❌ Authentication not working

  • βœ… Check environment variables are set correctly
  • βœ… Verify Nhost project is active
  • βœ… Check browser console for errors

❌ Email verification not received

  • βœ… Check spam folder
  • βœ… Use resend functionality
  • βœ… Verify email settings in Nhost dashboard

πŸ“š Learn More

Documentation

Tutorials

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

πŸ“„ License

This project is open source and available under the MIT License.


Built with ❀️ using Nhost + Next.js

Happy coding! πŸš€

About

Nhost Next.js template

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published