Commit Graph
3 Commits
Author SHA1 Message Date
Alaister YoungandAlaister Young be32a941cd [FE-5114] (part 4) – refactor(studio): migrate platform auth and misc routes (#54031)
## Problem

Studio's `routes/api/platform/auth/**` and platform misc/stub routes
still run legacy Next Pages Router handlers through
`compat/next/api.ts`, and 4 legacy database/props routes have no callers
left. Part 4 of 7 for
[FE-5114](https://linear.app/supabase/issue/FE-5114/rewrite-api-routes-as-native-tanstack-start-handlers-and-remove-the)
migrates the 16 active routes to native TanStack Start handlers and
removes the 4 unused ones.

## Solution

**Changed:**

- Migrated `platform/auth/$ref/{invite,magiclink,otp,recover}` to
one-line `createAuthSenderHandlers` routes, and `users/index`,
`users/$id/index`, and `users/$id/factors` to `createApiHandlers`,
preserving the FE-5124 fixes (`Promise.all` MFA factor deletion, `code
?? 500` on auth senders, `Allow: PATCH, DELETE` on `users/$id`, now
derived by `createApiHandlers`)
- Migrated 9 platform misc/stub routes (`deployment-mode`,
`integrations/{$slug,github/*}`,
`organizations/{index,$slug/billing/subscription}`, `profile/index`, and
`telemetry/event`)
- Moved the `FETCH_TYPE_BYPASS_EXCEPTIONS` entries for the four sender
routes in `eslint.config.cjs` to `lib/api/self-hosted/auth-senders.ts`

**Added:**

- `createAuthSenderHandlers(endpoint, field)` in
`lib/api/self-hosted/auth-senders.ts`: shared POST handler for the
self-hosted GoTrue `invite`, `magiclink`, `otp`, and `recover` endpoints
(forwards only `email` or `phone`, uses `constructHeaders` with the
service role key, and passes upstream errors through with `code ?? 500`)
- Regression tests for `auth/$ref/users/$id/factors`,
`auth/$ref/users/$id`, and all four auth sender routes

**Removed:**

- Removed 4 unused routes (`platform/database/$ref/pooling`,
`platform/props/org/$slug`, `platform/props/project/$ref/index`, and
`platform/props/project/$ref/api`) and regenerated `routeTree.gen.ts`

## Review instructions

1. Run `pnpm --filter studio exec vitest run
tests/routes/api/platform/auth/`.
2. On self-hosted Studio, invite/ban/delete a user, remove MFA factors
for a user, and confirm `GET /api/platform/auth/default/users/<id>`
returns `405` with `Allow: PATCH, DELETE`.

## Checklist

- [x] I have read
[CONTRIBUTING.md](https://github.com/supabase/supabase/blob/master/CONTRIBUTING.md)
- [ ] If I wrote a new docs topic or edited an existing topic, I used
the `/write-the-docs` or `/edit-the-docs` skill, which applies the docs
[style
guide](https://github.com/supabase/supabase/tree/master/apps/docs/style-guide)

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-12-01 22:30:19 +08:00
Alaister YoungandAlaister Young 1854331fb6 [FE-3106] (part 2) – refactor(studio): move api handlers into route files (#53202)
Moves every `pages/api/**` handler into its TanStack server route under
`routes/api/**` and deletes `pages/api/**`, part of the final pass of
the TanStack Start migration (FE-3106). Handlers move verbatim and still
run through `toWebHandler`, so auth (`apiWrapper`), response shapes and
headers are unchanged. Part 2 of the stack.

**Depends on:** #53199

**Changed:**
- `routes/api/**` – each route now holds its handler (formerly the
`pages/api` default export) as a local `nextHandler`/named function.
Next-only `config`/`maxDuration` exports are dropped: `vite.config.ts`
already sets the function `maxDuration`, and `toWebHandler` parses
bodies itself
- `routes/api/ai/docs.ts` – Web-native handler inlined, `NextRequest` →
`Request`
- `lib/api/apiHelpers.ts` – `getPgMetaRedirectUrl` moved here from the
old `tables` handler, which the other pg-meta routes imported it from
- `eslint.config.cjs`, `.github/CODEOWNERS` – `pages/api` paths →
`routes/api`
- `tests/routes/api/**`, `lib/api/{generate-v4,rate}.test.ts`,
`scripts/__tests__/server-source-maps.test.ts` – call the route's
registered handler with a Web `Request` (`tests/lib/server-route.ts`);
the MCP query-validation cases now run against the native route

**Removed:**
- `pages/api/**` (102 files), including the Next twins of the
already-native `routes/api/mcp/index.ts` and `functions/$slug/body.ts`
- unused `ProjectSettings` types and the `node-mocks-http` dev
dependency

Parity: every route registers the same methods its handler serves. The
exceptions are `check-cname`, `get-ip-address`, `get-utc-time`,
`get-s3-keys`, `get-deployment-commit`, `cli-release-version` and
`connect`: in Next they answered any method, and their routes register
`GET` only, as before this PR.

Addresses
[FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages).

## To test

- Load the table editor, SQL editor and Auth users on a self-hosted
build – `/api/platform/**` and `/api/v1/**` respond as before
- Use the Assistant and the docs search – `/api/ai/**` streams as before
- `GET /api/get-deployment-commit` – same JSON and `Cache-Control`

Ran typecheck, ESLint, lint ratchet, knip, Prettier, the TanStack build
and the full Studio vitest suite: all pass except
`lib/server/configcat.test.ts`, which also fails on `master` in an
environment with ConfigCat env vars set. Self-hosted E2E is CI-only.

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-11-11 22:24:43 +09:00
2f90228f04 feat(studio): port API handlers to TanStack server routes (stack 4/6, from #46424) (#47113)
**Stack 4/6** of the TanStack Start migration (#46424). Stacked on
**#47112** (S3).

> [!NOTE]
> Mechanical and homogeneous — every file is the same shape: a
`createFileRoute(...)` whose `server.handlers` delegate to the existing
`pages/api` handler via `toWebHandler` (the compat shim from S2). The
pages-router handlers are unchanged; Next still serves them directly and
ignores `routes/`.

## What's in this PR
- `routes/api/**` (~104 files): platform (`pg-meta`, auth, storage,
integrations, profile, telemetry, organizations, projects…), `ai/*`,
`v1/*`, `connect`, `content`/`mcp`, and standalone endpoints
(`deployment-mode`, `get-ip-address`, etc.).
- `routeTree.gen.ts` — **regenerated** for the routes present so far
(root + auth/app + api).

## Review tip
The route files are near-identical wrappers, so this is fast to skim.
The generated `routeTree.gen.ts` isn't meaningful review surface.

## Verification
On top of S1–S3: `studio` typecheck ✓, lint (0 errors) ✓.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **New Features**
* Added Model Context Protocol (MCP) API endpoint with configurable
feature support and read-only mode
* Added function artifact streaming capability for self-hosted functions

* **Chores**
  * Migrated API route infrastructure for improved system architecture

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2026-06-30 17:18:35 +08:00