Install with npm

Drop the guestbook into your existing Next.js app.

Check Dependencies

Ensure you have your required dependencies, which Next.js and React should already satisfy:

From your terminal at your application project root run:

npm ls next react react-dom @supabase/supabase-js @supabase/ssr

Installing

Install Guestbook Package

From your existing Next.js app root, install y2k-guestbook from GitHub:

npm install y2k-guestbook@github:beck-chan/y2k-guestbook @supabase/supabase-js @supabase/ssr

Set Up Environment Variables

  1. Copy the .env.example file to .env.local:

    cp node_modules/y2k-guestbook/.env.example .env.local
    
  1. Fill in values from your Supabase project and site origin:

    # Supabase project URL
    NEXT_PUBLIC_SUPABASE_URL=https://<your-database-url>.supabase.co
    
    # Supabase publishable key (browser-safe, RLS still applies)
    NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=sb_publishable_<your-publishable-key>
    
    # Secret key. Local ONLY — for `npx y2k-guestbook allow-admin`
    SUPABASE_SECRET_KEY=sb_secret_<your-secret-key>
    
    # App origin for OAuth return. Used to build redirectTo on the server.
    SITE_URL=http://localhost:3000
    
    # Supabase pooler URI — for rate limiting
    DATABASE_URL=postgresql://postgres.<your-database-url>:[YOUR-PASSWORD]@<your-database-region>.pooler.supabase.com:<port>/postgres
    
    # Optional admin URL prefix (default /admin). No trailing slash.
    # NEXT_PUBLIC_GUESTBOOK_ADMIN_PATH=/admin
    

Enable Authentication Hook

  1. Copy the contents of schema.sql to your clipboard.

  2. Within Supabase, select SQL Editor from the left sidebar, then paste in the contents of schema.sql.

  3. Click Run to execute the schema.

  4. If you receive a Potential issue detected popup, click Run query to execute the schema.

Allow Your Admin User

From your Next.js app root, allow-list a Google account as your admin user:

npx y2k-guestbook allow-admin you@gmail.com

You'll need to authorize Google to connect on your first sign in.

Configuring the Application

Protect Admin Login

Next only runs auth/session files from your project. Add three small files. Put proxy.ts next to app/ (repository root, or src/proxy.ts if you use src/app) — not inside app/.

Create proxy.ts to keep the Supabase session fresh and block the admin path (default /admin) unless app_metadata.role === "admin". Next needs config.matcher as a constant in this file:

export { proxy } from "y2k-guestbook/proxy";

export const config = {
  matcher: [
    "/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp|css)$).*)",
  ],
};
  • The admin login link stays visible, but users without proper access are booted back to the public guestbook comment board and presented with an error.
  • Error message copy is hardcoded in src/components/_shared/AdminAuthErrorOverlay.tsx — not accessible through the admin dashboard settings.

Add Guestbook Pages

Next only serves pages from your app/ directory. Re-export the packaged entrypoints:

  1. Create page.tsx for your public guestbook comment board where you want it to live:

    export {
     GuestbookPublicPage as default,
     guestbookPublicMetadata as metadata,
    } from "y2k-guestbook";
    export const dynamic = "force-dynamic";
    
  2. Set NEXT_PUBLIC_GUESTBOOK_PATH in .env.local according to where your public comment board lives (no trailing slash).

    Default is the root of your domain (/):

    • app/page.tsx — When the guestbook is the site, omit the variable (or set NEXT_PUBLIC_GUESTBOOK_PATH=/).
    • app/guestbook/page.tsx — When / (root) is already your site, set NEXT_PUBLIC_GUESTBOOK_PATH=/guestbook.

Configure Next.js

withGuestbookConfig adds transpilePackages so Next can compile the GitHub-installed package, externalizes pg for rate limiting, and rewrites the view example CSS URL. It reads NEXT_PUBLIC_GUESTBOOK_ADMIN_PATH for that rewrite (default /admin/example.css).

In your next.config.ts (or next.config.js), wrap your existing config with withGuestbookConfig:

import type { NextConfig } from "next";
import { withGuestbookConfig } from "y2k-guestbook/config";

const nextConfig: NextConfig = {
  // your existing options
};

export default withGuestbookConfig(nextConfig);

Run Development Server

To preview your application locally, run:

# Serves by default at `http://localhost:3000` 
npm run dev

Your interface should initially mimic the demo guestbook, but with no hit counter:

Serve Your Guestbook

To build the application locally to upload manually to your hosting provider:

# Linter check for errors
npm run lint
# Compile
npm run build
# Serve build 
npm run start

What's Next

Manage admin authentication and add analytics to display a hit counter: