I want each workspace to a have a url extension that is just the name, so…

merged…
osebo37d ago

I want each workspace to a have a url extension that is just the name, so evenings.forum/threads as an example

8 repliesoldestnewest
Osebotfable-5-137d ago

Plan: give every workspace a slug and make /<slug> its home.

  • Schema: workspaces.slug (text, NOT NULL, UNIQUE), migration drizzle/0011 backfills from the name (Threads → threads, lowercase, non-alphanumerics → -, de-duplicated with -2, -3…). New workspaces derive it on create; owners can edit it on the manage page (PATCH /api/workspaces/[id] {slug}).
  • Route: new app/[workspace]/page.tsx renders what /?workspace=<id> renders today (thread list + composer for that workspace). / just redirects to the remembered / first workspace's slug; /?workspace=<id> and /threads/new?workspace= redirect to the slug URL so old links keep working. Anonymous visitors get the sign-in gate + link preview like /workspaces/[id].
  • Reserved slugs: paths that already exist at the root (workspaces, about, faces, themes, signin, join, api, settings, Next internals) can't be taken. threads is allowed on purpose: /threads has no page of its own, so evenings.forum/threads works while /threads/<id> stays a thread page.
  • Links: header dropdown navigates to /<slug>; thread crumbs and the /workspaces cards link the workspace name to /<slug>; "manage" keeps pointing at /workspaces/[id].

APIs stay id-based; only page URLs change.

Osebotfable-5-137d agothreadide@29f6992

Done: every workspace now lives at /<slug>, so the Threads workspace is evenings.forum/threads. Pushed to thread/62fc04e6 (29f6992).

What changed

  • workspaces.slug (unique), migration drizzle/0011 backfills it from the name: Threads → threads, My Shop List!! → my-shop-list, duplicates get -2, -3…, and names that collide with an existing page (Workspaces, About) get workspaces-2 / about-2. New workspaces derive it on create; owners can change it in a new Address section on the manage page (PATCH /api/workspaces/[id] {slug}; 400 on bad shape or a reserved path, 409 if taken).
  • app/[workspace]/page.tsx is the workspace home: the thread list + composer that /?workspace=<id> used to render. / is now a redirect only (remembered workspace from the header cookie → first workspace you belong to → first there is). /?workspace=<id> and /threads/new?workspace= still work and bounce to the slug URL, keeping ?q, ?status, etc.
  • Header dropdown navigates between /<slug> pages; thread crumbs, the name on /workspaces cards and the invite landing all point at /<slug>. "manage/view" still goes to /workspaces/[id].
  • Anonymous visitors to /<slug> get the sign-in gate with the link preview (200 for crawlers), like /workspaces/[id].
  • threads is allowed as a slug on purpose: /threads has no page of its own, so /threads is the workspace while /threads/new and /threads/<id> stay what they are. The one wrinkle: a sibling opengraph-image.tsx there would resolve to /threads/[id], so the slug page's og:image reuses /workspaces/<id>/opengraph-image.
  • Side fix: workspace previews (gate, og description, invite text) always said "0 threads" because drizzle rendered the count subquery's column as a bare "id" (saved as a gotcha note).

Verified with a real Postgres 17 in the sandbox and the built app: migrations 0000→0011 apply; backfill output matches slugify() on tricky names; / → /threads when signed in; /threads 200 (home or gate), /about still a page, /nope 404; PATCH validation; second "Threads" workspace → threads-2. tsc, lint, next build clean. Screenshots attached.

Deploy note: the migration runs on the production build (scripts/migrate.ts). Preview deploys of this branch will 500 on workspace pages until it merges, since the shared DB has no slug column yet. If you'd rather keep the manage page at /<slug>/settings or want slugs to follow renames automatically, say so and I'll follow up.

Signed in, `/` redirected to `/threads`: the Threads workspace's home (thread list + composer), header dropdown on Threads
Signed in, `/` redirected to `/threads`: the Threads workspace's home (thread list + composer), header dropdown on Threads
/workspaces/[id] manage page: the address line under the title and the owner-only Address form (origin prefix + slug field)
/workspaces/[id] manage page: the address line under the title and the owner-only Address form (origin prefix + slug field)
Anonymous visit to /threads: sign-in gate with the workspace preview (now counts threads correctly)
Anonymous visit to /threads: sign-in gate with the workspace preview (now counts threads correctly)
oseboasked Osebot37d ago

Before moving forward with this is it better than slug.evenings.forum?

Osebotfable-5-137d ago

Short answer: for what Evenings Forum is today, evenings.forum/threads is the better choice, and the branch leaves the door open to threads.evenings.forum later. Here's the comparison against this codebase specifically.

What a subdomain per workspace would cost here

  • Sign-in stops being shared. Auth.js keeps its session cookie host-only (auth.ts sets no cookies.domain). Every *.evenings.forum host would be signed out until we scope the cookie to .evenings.forum, and the GitHub/Google OAuth callback can only live on one host, so sign-in from threads.evenings.forum has to bounce through the apex and back (Auth.js rejects cross-origin callbackUrls by default, so that needs a custom redirect callback too).
  • Theme and palette are per origin. They live in localStorage (components/theme-toggle.tsx), which the browser partitions by host. A palette picked on /themes would not apply on any workspace subdomain; each workspace would need its own pick, or the theme has to move into a cookie.
  • Switching workspaces becomes a full page load. The header dropdown does router.push today; across origins that's a hard navigation. Fine, but it stops feeling like one app, which is how workspaces are used right now (members hop between a few of them).
  • Previews break or need a second routing mode. Vercel's preview hosts (*.vercel.app) only carry one wildcard level, so threads.thread-xyz.vercel.app has no certificate. Every preview of this repo would have to fall back to path routing, meaning we maintain both. Production wildcard also requires the domain's nameservers to be on Vercel.
  • Every absolute link needs to know the host. lib/site.ts siteUrl() is a single origin used for metadataBase, emails, PR footers and link previews; it would become per-workspace.
  • Local dev needs lvh.me-style hosts and a matching OAuth app.

None of that is hard individually, but it's a week of plumbing that touches auth, and it buys nothing until the workspaces are genuinely separate sites.

What subdomains would buy

  • Nicer-looking addresses, and no reserved-name problem (/about, /workspaces and so on can't be workspace slugs today; a workspace called "About" gets about-2).
  • A natural path to custom domains per workspace (forum.someclient.com), since host-based routing is the same mechanism.
  • Cookie/storage isolation between workspaces, which only matters once workspaces belong to different organisations that shouldn't share a session.

When I'd switch: if workspaces become products with their own audience (public, their own domain, their own branding) rather than rooms inside one forum shared by the same people. At that point the move is a Next middleware.ts that rewrites Host: <slug>.evenings.forum to /<slug>/... plus the cookie/auth scoping above. The slug column, lib/slug.ts and app/[workspace]/page.tsx from this branch are exactly what that middleware would route to, so nothing here is thrown away.

A cheap middle ground if you just want the vanity address: once the domain has a wildcard on Vercel, a ~10-line middleware can 302 threads.evenings.forum → evenings.forum/threads. Links in the wild get the pretty form, the app keeps one origin, one session, one theme. I can add that whenever the DNS is in place.

So my recommendation is to merge the path version as is. Want me to go ahead with that, or would you rather I prototype the subdomain route so you can compare them for real?

oseboasked Osebot37d ago

Okay. Let’s go with the current approach

Osebotfable-5-137d ago

Going with the path-based /<slug> version. Remaining work before this merges:

  1. Main has moved by two PRs since 29f6992 (#121 composer padding, #122 thread crumb → /?workspace=<id>). #122 touches the same crumb link this branch repoints at /<slug>, so I'll merge main into the branch and resolve that in favour of the slug URL.
  2. Re-run tsc / lint / next build, push, and refresh the PR description so it matches the final state.

No new feature work; the decision (path, not subdomain) is already saved as a memory note.

Osebotfable-5-137d agothreadide@52a2545

Branch is ready to merge: PR #123 (thread/62fc04e6, now at 52a2545).

This step

  • Merged main into the branch (PRs #121 and #122 landed after 29f6992). The only conflict was the thread crumb: #122 pointed the workspace name at /?workspace=<id>, this branch points it at /<slug>. Kept the slug link; the intent of #122 (crumb leads back to the workspace's thread list and that workspace becomes the remembered one) still holds, because components/header-workspace.tsx writes the workspace cookie whenever you land on /<slug>.
  • tsc --noEmit and next build clean after the merge. (There is no lint script in the repo; the earlier "lint" mention was just tsc.)
  • PR description refreshed to match the final state, including the path-vs-subdomain decision.

Reminder for whoever merges: the slug migration (drizzle/0011) only runs on the production build, so preview deploys of this branch 500 on workspace pages until it merges. After the deploy, evenings.forum/threads is the Threads workspace; / redirects to the remembered workspace.

The decision to stay path-based (and what a later subdomain move would need) is saved as a workspace memory note.

Osebot36d ago

Merged threadide #123 by @osebo (merge, ae2f668).