Skip to content

fix(api): add GET /v1/profiles/slug/{slug} so public profiles resolve - #439

Merged
thinkclay merged 3 commits into
mainfrom
claude/xenodochial-kirch-cdb272
Jul 30, 2026
Merged

thinkclay merged 3 commits into
mainfrom
claude/xenodochial-kirch-cdb272

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Problem

The SDK's getProfileBySlug has always called /v1/profiles/slug/{slug}, but the api router only ever defined GET /{username}. Every public profile page (/users/[slug]) 404'd and rendered Profile Not Found.

Why add the endpoint instead of repointing the SDK

core.users.slug is an independent column — unique-indexed, seeded from the username at signup (004_functions.sql), then user-changeable via the vanity-URL panel with a 30-day cooldown and a core.slug_change_history audit trail (018_vanity_url_support.sql). Slugs are designed to diverge from usernames, so a slug lookup can't be folded into the username route. This also keeps the fix out of the SDK submodule (no PR + dist rebuild + pointer bump).

The envelope

The new route is unenveloped, unlike /{username}, /organizations/{slug} and /employers/{slug}. packages/sdk/src/http/client.ts returns await response.json() verbatim and ProfileBySlug expects fields at the top level — a {data} wrapper would have produced a 200 with every field undefined rather than an error. /general and /slug/history in the same router are already bare for this reason.

Privacy note

Section visibility is read with the service-role client. core.preferences is RLS-scoped to its owner (preferences_own_all), so a public viewer's anon client reads nothing and every hidden section would silently fall back to the permissive default.

Also fixed on the same page

  • SSR loader now uses the new endpoint, so server render and client query agree once a slug diverges. Its own comment documented this gap.
  • The not-found branch was keyed on error ||, so a transient client-query failure discarded good SSR data and rendered a 404. Now keyed on absent data.
  • Loader visibility is passed through, keeping hidden sections out of the server-rendered HTML crawlers see.

Verification

Exercised the router in-process against the local stack (the edge container mounts the main checkout, not the worktree, so this could not go through Kong):

  • diverged slug resolves by slug
  • legacy rows without a backfilled slug fall back to username
  • unknown slug → 404
  • /slug/history is not shadowed by the new param route (401, not 404)
  • with education/reviews false in preferences, the response reports them false — confirming the service-role read

deno lint clean, tsc --noEmit clean, pnpm prepush green (build + test).

Not browser-verified end-to-end — that needs the api served from this worktree.

5 regression tests added in profiles.test.ts. Note assertSuccessResponse requires a data key, so the unenveloped tests use assertStatus.

Follow-up (not in this PR)

checkSlugAvailability (GET /slug/check) and updateSlug (PATCH /slug) are still missing from the api, so the vanity-URL panel cannot actually change a slug. Any new static /slug/* route must be registered before /slug/{slug} or it will be shadowed.

🤖 Generated with Claude Code

thinkclay and others added 2 commits July 30, 2026 04:22
The SDK's getProfileBySlug has always called /v1/profiles/slug/{slug}, but
the api router only ever defined /{username}. Every public profile page
404'd and rendered "Profile Not Found".

Adding the endpoint rather than repointing the SDK at /{username}:
core.users.slug is an independent column, seeded from the username at
signup but user-changeable via the vanity-URL panel (30-day cooldown,
audited in core.slug_change_history). Slugs are meant to diverge, so a
slug lookup can't be folded into the username route. This also keeps the
fix out of the SDK submodule.

The response is unenveloped, unlike /{username} and the organization and
employer routes. The SDK hands callers the response body verbatim, so a
{data} wrapper would have produced a 200 with every field undefined
instead of an error. /general and /slug/history are already bare for the
same reason.

Section visibility is read with the service-role client: core.preferences
is RLS-scoped to its owner, so a public viewer's client reads nothing and
every hidden section would fall back to the permissive default and leak.

Also on the same page:

- Point the SSR loader at the new endpoint so the server render and the
  client query agree once a slug diverges. Its own comment documented
  this gap.
- Stop keying the not-found branch on `error`, which threw away good
  loader data whenever the client query failed and turned a transient
  fetch error into a 404.
- Pass loader visibility through, so hidden sections stay out of the
  server-rendered HTML that crawlers see.

Verified against the local stack: diverged slug resolves by slug, legacy
rows fall back to username, unknown slugs 404, /slug/history is not
shadowed by the new param route, and preferences-driven visibility is
reflected in the response.

Co-Authored-By: Claude Opus 5 <[email protected]>
The getProfileBySlug 404 fixed in the previous commit existed because the
SDK and the Hono router drifted with nothing checking they agree. That
failure mode is silent and expensive: the request 404s and the UI renders
an empty or "not found" state with no error near the cause.

This parses both sides statically — 449 registered routes across 75
mounted sub-routers, 498 SDK call sites — and asserts every SDK path has
a matching route. Static rather than runtime because the api function
only imports inside the Supabase edge runtime; bare `hono` is not
resolvable under plain Deno.

The SDK turns out to be well ahead of the api, so KNOWN_GAPS records the
85 endpoints the SDK calls that nothing implements. The point is to stop
that list growing, not to pretend it is empty. Notable clusters:

- jobs defines no POST/PATCH/DELETE at all, so createJob, updateJob and
  deleteJob cannot work
- profiles is missing /slug/check and PATCH /slug, so the vanity-URL
  panel can read slug history but cannot change a slug
- the SDK asks for /v1/communities/posts/portfolio/{userId} where the
  route is mounted at /user/{userId} — a wrong path segment

The baseline is enforced in both directions: a new gap fails, and so does
a stale entry, so implementing an endpoint forces its line to be removed
rather than letting the baseline quietly rot.

Verified by breaking things on purpose. Renaming the /slug/{slug} route
path reproduces the original bug and the test names exactly
`GET /v1/profiles/slug/:p`; adding an already-implemented endpoint to
KNOWN_GAPS trips the stale check. Guard assertions fail the run if either
parser stops recognising a registration style, so a parser regression
cannot turn this green by accident.

Co-Authored-By: Claude Opus 5 <[email protected]>
Tasks filed in local dev do not survive `supa db reset`. The first copy of
these four was destroyed by exactly that: the stack was reset mid-session,
the seeded `dogfooding-md` tasks came back because they live here, and
everything else was gone. Filing a finding in the product is not durable
on its own.

Adds the four findings from the PR #439 session — the two remaining slug
write endpoints, the silent response-envelope inconsistency, the
contradictory dogfood-log status output, and the contract test itself
(done) — with the same fixed-UUID ON CONFLICT DO NOTHING shape as the
migrated entries, so they reconcile with the rows already in local
databases instead of duplicating them.

Verified by deleting all four and re-running the seed: all four come back
with the right punchlist, status and priority, and a second run is a
no-op.

Co-Authored-By: Claude Opus 5 <[email protected]>
@thinkclay

Copy link
Copy Markdown
Contributor Author

Heads-up from an adjacent session: #441 landed on main a short while ago, adding GET /v1/profiles/slug/check and PATCH /v1/profiles/slug to this same router.

I checked how it interacts with this branch, so you don't have to:

  • Merges cleanly. git merge-tree origin/main <this branch> reports no conflicts — feat(api): implement the two missing vanity-URL slug endpoints #441's handlers sit early in the file, this PR's OpenAPI route sits after the schema block.
  • Registration order survives the merge, which is the thing that could have broken silently. In the merged tree: /slug/check at line 118, PATCH /slug at 167, /slug/history at 305, and /slug/{slug} at 834. Static before param, so check and history aren't swallowed as slugs — both satisfy the 3–50 char ^[a-z0-9-]+$ rule, so that ordering matters.

Worth re-running the contract test after you rebase — three of the 85 baseline entries from #447 are now implemented (/slug/check, PATCH /slug from #441, plus /slug/{slug} here), so the baseline file in this PR may need those removed.

I had duplicated the /slug/{slug} work in #457 before spotting this PR; closed it in favour of this one.

@thinkclay
thinkclay merged commit 1d75a76 into main Jul 30, 2026
6 of 15 checks passed
@thinkclay
thinkclay deleted the claude/xenodochial-kirch-cdb272 branch July 30, 2026 12:21
@thinkclay

Copy link
Copy Markdown
Contributor Author

Triaged. Not redundant with #441 — but I am leaving this open rather than merging, because I could not verify it at runtime in this environment. Details below.

It is still needed

#441 ("implement the two missing vanity-URL slug endpoints") merged the two authenticated vanity endpoints. main today registers:

/current · /slug/check · PATCH /slug · /slug/history · /general · PATCH /general
{username} · /organizations/{slug} · /employers/{slug}

There is still no GET /slug/{slug} — the public lookup the SDK's getProfileBySlug calls. So the premise of this PR holds unchanged.

What I did verify

  • Merges cleanly onto current main (no conflicts).
  • Route ordering is safe. In the merged file the literal routes register at lines 118 (/slug/check) and 305 (/slug/history), before the param route /slug/{slug} at 782 — so neither is shadowed. /{username} is single-segment and cannot shadow a two-segment path either. The /slug/history regression test in this PR passes, confirming it.

What blocks final verification

The 4 new /slug/:slug tests fail, but not because the code is wrong — the endpoint under test is never reached. The local edge runtime container mounts a different worktree:

$ docker inspect supabase_edge_runtime_scaffald --format '{{range .Mounts}}...'
/host_mnt/.../.claude/worktrees/blissful-kalam-9bd0b0/packages/supabase/functions -> ...

That checkout has no /slug/{slug} route, so every request returns a generic route-miss:

GET /v1/profiles/slug/no-such-vanity-slug -> 404 {"error":"Not found"}

The tests assert response.body.message?.includes("not found"), which a bare {"error":"Not found"} fails. This is the same limitation the PR description already flagged. Confirming the artifact: on a clean DB, main baselines at 14 passed / 13 failed and this branch at 15 passed / 17 failed — exactly +5 tests, of which the 1 that does not touch the new endpoint passes.

I did not restart the edge runtime against this worktree, because another session is actively using the one currently mounted.

To finish this off

Serve the api from this branch's checkout and re-run:

pnpm supa functions serve api

then deno test --allow-all --no-check --config=functions/api/deno.json functions/api/__tests__/routes/profiles.test.ts. If the 4 slug tests go green, this is good to merge.

Given CI is still billing-blocked (#375), I did not want to merge an unverified runtime path on static review alone — that is the failure mode that has bitten this repo before.

thinkclay added a commit that referenced this pull request Jul 30, 2026
main is currently red on the contract test. #439 landed the test with an
85-entry baseline captured before #441 merged; #441 implemented two of
those entries, so the stale-entry assertion now fires on every run:

  GET /v1/profiles/slug/check
  PATCH /v1/profiles/slug

That is the assertion doing its job — it exists so a baseline cannot
quietly drift out of date — but it needs the two lines removed. Baseline
drops 85 -> 83.

Verified red before and green after: checked out origin/main in a
scratch worktree and reproduced the failure naming both entries, then
confirmed 3/3 pass with this change.

Co-authored-by: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant