# Landing Page as Homepage Implementation Plan

> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task.

**Goal:** Make the static HTML landing page (`public/landing/index.html`) serve as the homepage for unauthenticated users while preserving the authenticated redirect to `/dashboard`.

**Architecture:** Remove the React-based redirect page (`app/page.tsx`) and let Next.js serve `public/index.html` directly. Middleware handles the auth check and redirects authenticated users to `/dashboard` before the static file is served.

**Tech Stack:** Next.js 14 middleware, NextAuth JWT tokens, static HTML

---

## Task 1: Move Landing Page to Root

**Files:**

- Move: `public/landing/index.html` → `public/index.html`

**Step 1: Move the file**

```bash
cd /home/momentary/repos/amsoil-dlp/.worktrees/landing-refactor
mv public/landing/index.html public/index.html
```

**Step 2: Verify the file exists at new location**

```bash
ls -la public/index.html
```

Expected: File exists, ~690 lines

**Step 3: Commit**

```bash
git add public/landing/index.html public/index.html
git commit -m "refactor: move landing page to public/index.html"
```

---

## Task 2: Update Proxy for Root Auth Redirect

**Files:**

- Modify: `proxy.ts:82-92`

**Step 1: Read current proxy public routes section**

The current code at lines 82-92:

```typescript
// Allow public routes (skip authentication check)
if (
  pathname.startsWith('/api/auth') ||
  pathname.startsWith('/auth/signin') ||
  pathname.startsWith('/auth/error') ||
  pathname === '/' ||
  pathname.startsWith('/api/webhooks') ||
  pathname.startsWith('/api/revalidate')
) {
  return NextResponse.next();
}
```

**Step 2: Update to handle root path with auth check**

Replace the above block with:

```typescript
// Allow public routes (skip authentication check)
if (
  pathname.startsWith('/api/auth') ||
  pathname.startsWith('/auth/signin') ||
  pathname.startsWith('/auth/error') ||
  pathname.startsWith('/api/webhooks') ||
  pathname.startsWith('/api/revalidate')
) {
  return NextResponse.next();
}

// Root path: redirect authenticated users to dashboard, serve static landing for others
if (pathname === '/') {
  const token = await getToken({ req: request, secret: NEXTAUTH_SECRET });
  if (token) {
    return NextResponse.redirect(new URL('/dashboard', getSiteUrl().origin));
  }
  return NextResponse.next(); // Serves public/index.html
}
```

**Step 3: Verify no TypeScript errors**

```bash
npx tsc --noEmit
```

Expected: No errors

**Step 4: Commit**

```bash
git add proxy.ts
git commit -m "feat: redirect authenticated users from / to /dashboard"
```

---

## Task 3: Remove App Router Root Page

**Files:**

- Delete: `app/page.tsx`

**Step 1: Verify current file contents**

```bash
cat app/page.tsx
```

Expected: Simple redirect component (~13 lines)

**Step 2: Delete the file**

```bash
rm app/page.tsx
```

**Step 3: Verify no TypeScript errors**

```bash
npx tsc --noEmit
```

Expected: No errors (no other files import this)

**Step 4: Commit**

```bash
git add app/page.tsx
git commit -m "refactor: remove app/page.tsx, let static index.html serve root"
```

---

## Task 4: Clean Up Landing Rewrites (Optional)

**Files:**

- Modify: `next.config.mjs:118-129`

**Step 1: Read current rewrites**

Current code:

```javascript
  async rewrites() {
    return [
      {
        source: '/landing',
        destination: '/landing/index.html',
      },
      {
        source: '/landing/',
        destination: '/landing/index.html',
      },
    ];
  },
```

**Step 2: Update to redirect /landing to root**

Since the landing page is now at `/`, redirect `/landing` there for any old bookmarks:

```javascript
  async rewrites() {
    return [];
  },
  async redirects() {
    return [
      {
        source: '/landing',
        destination: '/',
        permanent: true,
      },
      {
        source: '/landing/',
        destination: '/',
        permanent: true,
      },
    ];
  },
```

**Step 3: Remove empty landing directory**

```bash
rmdir public/landing 2>/dev/null || true
```

**Step 4: Verify build works**

```bash
npm run build
```

Expected: Build succeeds

**Step 5: Commit**

```bash
git add next.config.mjs
git commit -m "refactor: redirect /landing to / for backwards compatibility"
```

---

## Task 5: Manual Testing

**Step 1: Start dev server**

```bash
cd /home/momentary/repos/amsoil-dlp/.worktrees/landing-refactor
npm run dev
```

Server runs on port 3018

**Step 2: Test unauthenticated access**

Open incognito browser to `http://localhost:3018/`

Expected: See the static landing page with pricing tiers

**Step 3: Test authenticated redirect**

1. Sign in via `http://localhost:3018/api/auth/signin`
2. Navigate to `http://localhost:3018/`

Expected: Redirects to `/dashboard`

**Step 4: Test /landing redirect**

Navigate to `http://localhost:3018/landing`

Expected: Redirects to `/` (301 permanent)

**Step 5: Test subscribe buttons**

Click any "Subscribe" button on landing page

Expected: Redirects to sign-in → OAuth flow starts

---

## Verification Checklist

- [ ] `public/index.html` exists and contains landing page
- [ ] `app/page.tsx` does not exist
- [ ] Unauthenticated users see landing page at `/`
- [ ] Authenticated users redirect to `/dashboard` from `/`
- [ ] `/landing` redirects to `/`
- [ ] Subscribe buttons trigger OAuth flow
- [ ] Build succeeds (`npm run build`)
- [ ] No TypeScript errors (`npx tsc --noEmit`)
