Skip to content
This repository was archived by the owner on Feb 1, 2026. It is now read-only.

darrylb-github/fresh-auth

Repository files navigation

Fresh Auth Demo

A minimal authentication demo showcasing three different route protection patterns using Deno Fresh, Better Auth, Drizzle ORM, and Daisy UI.

🚀 Quick Demo

This demo illustrates three authentication approaches:

  1. Server-side: /dashboard - Auth check in route handler
  2. Middleware: /dashboard-middleware - Protected by Fresh middleware
  3. Unprotected: /dashboard-unprotected - No auth, unprotected

🛠️ Stack

  • Deno Fresh - Full-stack web framework
  • Better Auth - Modern authentication
  • Drizzle ORM - TypeScript-first database ORM
  • SQLite - For the auth database demo
  • Daisy UI - Tailwind CSS component library

📋 Prerequisites

  • Deno: Install Deno
  • SQLite: (Optional) - only for inspecting the created auth.db

🏃‍♂️ Quick Start

  1. Setup:

    deno task setup    # Setup database (run once)
    deno task start    # Start the server
  2. Visit: http://localhost:8000

  3. Test the demo: Create account → Try each dashboard route to see the auth differences -> Test with and without being logged in

📸 Screenshots

Login & Signup

Login Page Signup Page
Login Signup
Clean login form with demo routes sidebar Account creation with form validation

Authentication Patterns Comparison

🔐 Server-Side Auth Check (/dashboard)

Server-Side Dashboard Authentication verified in route handler on each request

🛡️ Middleware Protection (/dashboard-middleware)

Middleware Dashboard Protected by Fresh middleware with automatic redirects

⚠️ No Authentication (/dashboard-unprotected)

Unprotected No Auth Accessible to anyone

🔍 Database Inspection

After creating users, you can explore the SQLite auth database:

# Open SQLite CLI
sqlite3 db/auth.db

# View all tables
.tables

# See user accounts
SELECT id, name, email, emailVerified, datetime(createdAt, 'unixepoch') as created FROM user;

# See active sessions  
SELECT id, datetime(expiresAt, 'unixepoch') as expires, userId FROM session;

# Exit SQLite
.exit

🔍 Route Protection Patterns

Route Protection Description
/dashboard Server-side Auth check in route handler, session verified per request
/dashboard-middleware Middleware Fresh middleware protection, automatic redirects
/dashboard-unprotected None Unprotected example showing what happens if not checking session

📋 Development

Key commands:

deno task setup    # Setup database tables (run once)
deno task start    # Start dev server

Project structure:

├── routes/           # 3 dashboard routes showing different auth patterns
├── components/       # Dashboard UI component
├── islands/          # Login form + logout button
├── lib/auth/         # Better Auth configuration
├── db/               # Drizzle schema (user, session, account, verification)
└── tests/            # Integration tests

The database (db/auth.db) is created automatically on first run.

About

Authentication demo showcasing using Better Auth with Deno Fresh.

Topics

Resources

Stars

Watchers

Forks

Contributors