Skip to content

feat(api): add GET /v1/profiles/slug/:slug for vanity-URL profiles - #457

Closed
thinkclay wants to merge 1 commit into
mainfrom
claude/profile-by-slug
Closed

thinkclay wants to merge 1 commit into
mainfrom
claude/profile-by-slug

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Follow-up to #441, which added GET /v1/profiles/slug/check and PATCH /v1/profiles/slug. This adds the last of the four SDK vanity-URL methods still hitting a route that did not exist: getProfileBySlug.

What this adds

GET /v1/profiles/slug/{slug} → ProfileBySlug, unenveloped (the SDK's http client returns the body verbatim, so a { data } wrapper would deserialize into the wrong shape without failing loudly).

Public by design — no requireAuth — matching the legacy tRPC publicProcedure this is ported from.

Registration order is load-bearing and covered by a test. The route is registered after the static /slug/check and /slug/history routes from #441. Both check and history satisfy the 3–50 char ^[a-z0-9-]+$ slug rule, so a param route registered first would swallow them.

One deliberate departure from the tRPC original

profile_visibility is read with the service client, not the request-scoped one.

core.preferences is owner-only under RLS (preferences_own_all), so the RLS client returns no row for any visitor except the owner, and the tRPC version then fell through to its permissive defaults. A profile owner who hid their work history had it advertised as visible to every anonymous visitor. The data behind those sections is separately RLS-gated, so this was not a data leak — but the vanity page would render sections the owner had switched off.

The service-role read is scoped to one column for the one profile being rendered. Defaults still apply when no row exists, with contact_info: false so the only PII-bearing flag fails closed.

Covered by honours the owner's visibility settings, which sets flags as the owner and asserts an anonymous visitor sees them.

Tests

6 new cases in profiles.test.ts, taking the slug suite from 11 to 17: profile resolution, visibility honouring, the contact_info default, the static-route shadowing guard, 404, and 400. They use assertStatus rather than assertSuccessResponse, which requires a data key.

The resolution test asserts response shape rather than seeded values, because createTestUserProfile's core.users insert is a silent no-op — a trigger already creates the row on auth signup, so the insert fails on the pkey and the fixture never checks the error. That same fixture bug is why three /{username} tests fail on main; fixing it is out of scope here.

17/17 green locally against this branch's base, stable across runs. pnpm prepush passes (build + test + Deno load probe).

CI

Checks on this PR are uninformative: every job fails in 3–5s with "The job was not started because recent account payments have failed or your spending limit needs to be increased." No job starts, and main's own runs fail identically.

🤖 Generated with Claude Code

Completes the vanity-URL surface: the SDK's `getProfileBySlug` was the
last of the four slug methods still hitting a route that did not exist.
Public by design (no requireAuth, matching the legacy tRPC
publicProcedure) and registered after the static /slug/check and
/slug/history routes, which would otherwise be swallowed as slugs —
"check" and "history" both satisfy the slug pattern. Response is
unenveloped to match SDK ProfileBySlug.

Reads profile_visibility with the service client rather than the
request-scoped one. core.preferences is owner-only under RLS
(preferences_own_all), so the RLS client returns nothing for every
visitor except the owner — which would hand each visitor the permissive
defaults and render sections the owner had hidden. This is a deliberate
departure from the tRPC original, which had that bug. Defaults still
apply when no row exists, with contact_info false so the one PII-bearing
flag fails closed.

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

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #439, which does the same thing better.

I built this without realising #439 was already open and adding the same endpoint. #439 is the more complete implementation:

  • Proper OpenAPI route + profileBySlugSchema, rather than a bare handler.
  • Returns location, bio, created_at, and the full_name/current_position aliases the SSR loader and JSON-LD consume — mine returned only the raw core.users columns.
  • Updates the actual consumers (apps/scaffald/app/(public)/users/[slug].tsx, public-content-loader.ts), which mine did not touch.
  • Adds the contract-test baseline.

It also already reads profile_visibility with the service client for the same reason I did — core.preferences is owner-only under RLS, so the request-scoped read returns nothing for a public viewer and the caller would otherwise fall through to permissive defaults. So there is nothing here worth salvaging.

Verified that #439 still merges cleanly onto main now that #441 has landed, and that route registration order survives the merge: static /slug/check and /slug/history come before the /slug/{slug} param route, so they are not shadowed.

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