mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## Problem With all Studio API routes migrated to native TanStack Start handlers (or removed when unused) in parts 1–6, the Next Pages Router API adapter and legacy `NextApiRequest`/`NextApiResponse` wrappers are no longer used. Part 7 of 7 for [FE-5114](https://linear.app/supabase/issue/FE-5114/rewrite-api-routes-as-native-tanstack-start-handlers-and-remove-the) tears them down. ## Solution **Removed:** - `compat/next/api.ts` and `compat/next/api.test.ts` (`toWebHandler`) - Legacy `apiWrapper`, `apiAuthenticate`, and `fetchUserClaims` (`NextApiRequest`/`NextApiResponse`) functions and their legacy tests in `lib/api/apiWrapper.ts`, `lib/api/apiAuthenticate.ts`, `lib/api/apiWrappers.test.ts`, and `lib/api/apiAuthenticate.test.ts` - The now-unused `fromNodeHeaders` helper (and its `node:http` import) and its tests in `lib/api/apiHelpers.ts` / `lib/api/apiHelpers.test.ts` **Changed:** - Updated comment in `lib/server/configcat.ts` from `apiAuthenticate` to `authenticateRequest` ## Review instructions 1. Confirm `git grep -E "NextApiRequest|NextApiResponse|compat/next/api|toWebHandler|fromNodeHeaders|from 'next'" apps/studio/` returns no matches. 2. Run `pnpm --filter studio run typecheck`, `pnpm knip --workspace apps/studio`, and `pnpm --filter studio exec vitest run lib/api/ tests/routes/api/ scripts/__tests__/server-source-maps.test.ts`. ## 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>
21 lines
662 B
TypeScript
21 lines
662 B
TypeScript
import type { JwtPayload } from '@supabase/supabase-js'
|
|
|
|
import { getUserClaims } from '@/lib/gotrue'
|
|
|
|
/**
|
|
* Authenticate an incoming Web Request using its Authorization header.
|
|
* This method can only be used from the server side.
|
|
*/
|
|
export async function authenticateRequest(
|
|
request: Request
|
|
): Promise<JwtPayload | { error: Error }> {
|
|
const token = request.headers.get('authorization')?.replace(/bearer /i, '')
|
|
if (!token) return { error: new Error('missing access token') }
|
|
|
|
const { claims, error } = await getUserClaims(token)
|
|
if (error) return { error }
|
|
if (!claims) return { error: new Error('The user does not exist') }
|
|
|
|
return claims
|
|
}
|