# Yories Games — New Website

A modern rebuild of [yoriesgames.com](https://yoriesgames.com) inspired by [gunjanappstudios.com](https://gunjanappstudios.com), with a self-managed admin panel for the games catalogue.

**Stack**

- Next.js 14 (App Router) · React · Tailwind CSS · Framer Motion
- MongoDB Atlas + Mongoose
- JWT session cookies (jose) · bcryptjs

---

## 1. Local setup

```bash
# install dependencies
npm install

# copy env template and fill in values
cp .env.local.example .env.local
```

Edit `.env.local`:

```
MONGODB_URI=mongodb+srv://USER:PASSWORD@cluster.xxxxx.mongodb.net/yories
ADMIN_JWT_SECRET=<generate a long random string, 32+ chars>
ADMIN_BOOTSTRAP_EMAIL=admin@yoriesgames.com
ADMIN_BOOTSTRAP_PASSWORD=<a secure password, 8+ chars>
```

> **Tip:** Get a free MongoDB cluster at [cloud.mongodb.com](https://cloud.mongodb.com).
> For `ADMIN_JWT_SECRET`, run `openssl rand -hex 32` in a terminal.

---

## 2. Create the first admin

```bash
npm run create-admin
```

This reads `ADMIN_BOOTSTRAP_EMAIL` and `ADMIN_BOOTSTRAP_PASSWORD` from `.env.local` and creates (or updates) an admin user.

---

## 3. Seed games from the existing site (one-time)

```bash
npm run seed
```

Scrapes [yoriesgames.com](https://yoriesgames.com) and inserts every game into MongoDB. Re-running updates existing games (matched by slug) instead of duplicating.

---

## 4. Run locally

```bash
npm run dev
```

- Public site → http://localhost:3806
- Admin panel → http://localhost:3806/admin (you'll be redirected to login)

---

## 5. Day-to-day: adding a new game

1. Open `/admin/login` and sign in.
2. Click **+ New game**.
3. Fill in title, descriptions, store URLs, icon/banner image URLs.
4. Toggle **Live on website** on (default).
5. Save — your game shows up immediately at `/games/<slug>` and on the homepage.

To hide a game without deleting it, just toggle **Live** off in the games list.

---

## 6. Deploy to Vercel

1. Push this repo to GitHub.
2. Import it at [vercel.com/new](https://vercel.com/new).
3. Add the same environment variables (`MONGODB_URI`, `ADMIN_JWT_SECRET`, etc.) in the Vercel project settings.
4. Deploy. Your domain (e.g. yoriesgames.com) can be pointed at Vercel via DNS.
5. SSH/run `npm run create-admin` once locally pointed at the **production** `MONGODB_URI` to bootstrap the admin.

---

## Project structure

```
app/
  page.js                  ← Homepage
  games/page.js            ← All games
  games/[slug]/page.js     ← Game detail
  about/page.js
  contact/page.js
  admin/
    login/page.js
    page.js                ← Dashboard
    games/page.js          ← Games list
    games/new/page.js
    games/[id]/page.js     ← Edit
  api/
    games/route.js         ← GET (public list), POST (admin create)
    games/[id]/route.js    ← GET, PATCH, DELETE
    auth/login/route.js
    auth/logout/route.js
    contact/route.js
components/                ← Public site UI
  admin/                   ← Admin UI
lib/
  db.js                    ← Mongoose connection (cached)
  auth.js                  ← JWT session helpers
models/
  Game.js
  Admin.js
middleware.js              ← Protects /admin/*
scripts/
  seed-from-yories.mjs     ← One-time scraper
  create-admin.mjs         ← Bootstrap admin user
```

---

## Notes

- `/admin` is protected by a JWT cookie set on login. Middleware redirects unauthenticated requests to `/admin/login`.
- Game pages are revalidated every 60 seconds (`revalidate = 60`) — when you publish a game, it appears within ~1 minute or on next request.
- Image hosting: the form takes URLs (Cloudinary, Imgur, etc.). For drag-and-drop uploads, wire up Cloudinary or UploadThing later.
