Repository navigation
feat(api): implement the two missing vanity-URL slug endpoints - #441
Merged
Merged
Conversation
The SDK's `checkSlugAvailability` and `updateSlug` both called routes that
were never ported out of the legacy tRPC vanity router, so every request
404'd. The Vanity URL panel could list slug history and nothing else.
Adds, in the static-route block ahead of every param route:
GET /v1/profiles/slug/check?slug=... -> { available, suggestions }
PATCH /v1/profiles/slug -> { success, slug, nextChangeAllowed }
Both responses are unenveloped: the SDK's http client returns the body
verbatim, so a `{ data }` wrapper would deserialize into the wrong shape
without failing loudly.
updateSlug enforces the same 30-day cooldown that GET /slug/history
reports (400 carrying nextChangeAllowed/daysRemaining), answers 409 with
alternatives when another user holds the slug, and records the change in
core.slug_change_history. The history insert is best-effort — a failed
insert is logged rather than surfaced, since it cannot undo a slug change
that already committed.
Slug normalization matches migration 018's users_slug_format_check:
lowercased and trimmed, 3-50 chars, ^[a-z0-9-]+$.
Test slugs carry a per-run token. core.users.slug is globally unique and
outlives a crashed run, so fixed literals collide with leftovers and fail
on the second run.
Co-Authored-By: Claude Opus 5 <[email protected]>
This was referenced Jul 30, 2026
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The SDK's
checkSlugAvailabilityandupdateSlugboth called routes that were never ported out of the legacy tRPC vanity router, so every request 404'd. The Vanity URL panel could list slug history (GET /slug/historyexists) and nothing else.What this adds
Two handlers in
packages/supabase/functions/api/routes/profiles.ts, bothrequireAuth, both in the static-route block ahead of every param route:GET /v1/profiles/slug/check?slug=…{ available, suggestions }PATCH /v1/profiles/slug{ success, slug, nextChangeAllowed }Responses are deliberately unenveloped. The SDK's http client returns
await response.json()with no unwrapping, so a{ data }wrapper would deserialize into the wrong shape without failing loudly.checkSlugAvailabilityexcludes the caller's own slug from the taken check — re-saving your current slug is a no-op, not a conflict.updateSlugenforces the same 30-day cooldown thatGET /slug/historyreports (400 carryingnextChangeAllowed/daysRemaining), answers 409 with alternatives when another user holds the slug, and records the change incore.slug_change_history. The history insert is best-effort: a failed insert is logged rather than surfaced, since it cannot undo a slug change that already committed.Slug normalization matches migration 018's
users_slug_format_check— lowercased and trimmed, 3–50 chars,^[a-z0-9-]+$.generateSlugSuggestionsis ported from the tRPC vanity router unchanged.Follow-up
GET /v1/profiles/slug/{slug}(SDKgetProfileBySlug) was still missing after this PR — see the follow-up PR for it.Tests
11 new cases in
profiles.test.tsusingassertStatus(notassertSuccessResponse, which requires adatakey): availability, own-slug-is-available, suggestions, 400/401, a successful change verified down to theslug_change_historyrow, case/whitespace normalization, cooldown, and 409.Test slugs carry a per-run token.
core.users.slugis globally unique and outlives a crashed run, so fixed literals collide with leftovers and fail on the second run. The fixture helper also throws if the admin slug seed fails instead of silently proceeding.Verified green locally, 11/11, stable across consecutive runs.
🤖 Generated with Claude Code