Auth Module with Supabase SSR + Optional 2FA

By (author)Hafsa Ather Khan

Tech stack:
TS
Supabase
Next.js
TW
React

A production-ready, plug-and-play authentication module built with Next.js 14 App Router and Supabase SSR. Drop it into any Next.js project to get a f...
read more
AI Contributions:9
Published At:August 12, 2026
Files Included:1 file(s)
Updated At:October 23, 2026

Read Me

Authentication


A production-ready, plug-and-play authentication module built with Next.js 14 App Router and Supabase SSR. Drop it into any Next.js project to get a fully working auth system in minutes — no boilerplate needed.

What's included:

Core Authentication

  • Email/password sign up & sign in with server actions
  • Google OAuth sign in (one-click setup)
  • Secure session management using @supabase/ssr (no deprecated helpers)
  • Protected routes via middleware with smart redirect logic
  • Logout with session cleanup

Two-Factor Authentication (TOTP) — Optional per user

  • Per-user opt-in 2FA using Supabase's built-in MFA API
  • QR code enrollment flow compatible with Google Authenticator, Authy, and any TOTP app
  • Manual secret key fallback for users who can't scan QR codes
  • Session AAL2 enforcement in middleware — protects all routes automatically
  • Enable/disable 2FA from the profile security panel at any time

UI Components (Tailwind CSS)

  • Login form with OAuth button
  • Signup form with validation
  • 6-digit OTP verification screen
  • 2FA security settings panel with status badge, QR code display, and disable flow

API Routes (App Router)

  • /api/auth/mfa/status — check enrollment status
  • /api/auth/mfa/enroll — start TOTP enrollment, returns QR code
  • /api/auth/mfa/verify — verify TOTP code
  • /api/auth/mfa/unenroll — disable 2FA

How to use:

  1. Copy the files into your Next.js 14 project
  2. Add your Supabase credentials to .env.local
  3. Enable TOTP in your Supabase Dashboard → Authentication → MFA
  4. Done — login, signup, OAuth, and 2FA are all working

🛠 Tech Stack

TechnologyVersion / Details
Next.js14 (App Router)
TypeScript5+
Supabase@supabase/ssr ^0.5
Supabase AuthEmail/Password + Google OAuth + TOTP MFA
Tailwind CSS3.x
React18 (Server + Client Components)

 

📋 Required Environment Variables

env
 
NEXT_PUBLIC_SUPABASE_URL=your_supabase_project_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
NEXT_PUBLIC_SITE_URL=http://localhost:3000

Loading

Loading

Loading

More like this View all

Smart Inventory & Auto-Merging Catalog API

Production-ready Next.js 14 inventory system with real-time catalog search, quantity auto-merging logic, and Supabase RLS security.

  • 0

    Ratings

  • 1

    Files

    • Next.js
    • TS
    • +5

    Tech stack

AI WhatsApp Message Drafts (Gemini, Roman Urdu)

AI-written WhatsApp confirmations, payment reminders, out-for-delivery and thank-you messages in Roman Urdu, Urdu or English. Gemini + zod, model fallback, offline templates.

  • 0

    Ratings

  • 11

    Files

    • Next.js
    • React
    • +3

    Tech stack

Multi-Step Onboarding & Team Setup Engine

Middleware-protected Next.js 14 onboarding wizard with dynamic team/household inputs and relational Supabase DB inserts.

  • 0

    Ratings

  • 1

    Files

    • Next.js
    • TS
    • +4

    Tech stack