Files
supabase/apps/docs/lib/fetch/fetchWrappers.ts
Alaister Young 9d534c9f5a fix: response error codes (#30581)
* fix: response error codes

* upgrade docs

* remove request url modification middleware

* move api routes for self-hosted to platform folder

* remove some lib/common/fetch usage

* docs: use middleware for openapi-fetch (#30600)

Get rid of the unauthedAllowedPost function (I don't think there's any harm in letting any requests that require authentication to just 403, they should be disabled at the React Query level and if not they will fail gracefully enough...)

* fix local count query

* add default values for clone mutation

* fix ts and codegen

* add missing lodash dep to playwright tests

* Fix the playwright tests to match the new folder structure for selfhosted variant.

* remove unused import

* Remove unused state

* remove unused sql debug mutation

* remove unused export

* fix notifications query

* fix jwt updating status

* fix typescript

* save sql snippet after renaming

* update codegen & fix ts error

* override array querySerializer

---------

Co-authored-by: Charis <26616127+charislam@users.noreply.github.com>
Co-authored-by: Joshen Lim <joshenlimek@gmail.com>
Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com>
2025-01-20 11:27:38 +08:00

47 lines
1.1 KiB
TypeScript

import type { paths } from 'api-types'
import createClient from 'openapi-fetch'
import { v4 as uuidv4 } from 'uuid'
import { API_URL } from '../constants'
import { getAccessToken } from '../userAuth'
const DEFAULT_HEADERS = {
'Content-Type': 'application/json',
Accept: 'application/json',
}
const client = createClient<paths>({
baseUrl: API_URL,
referrerPolicy: 'no-referrer-when-downgrade',
headers: DEFAULT_HEADERS,
})
async function constructHeaders(headersInit?: HeadersInit | undefined) {
const requestId = uuidv4()
const headers = new Headers(headersInit)
headers.set('X-Request-Id', requestId)
if (!headers.has('Authorization')) {
const accessToken = await getAccessToken()
if (accessToken) {
headers.set('Authorization', `Bearer ${accessToken}`)
}
}
return headers
}
client.use({
async onRequest({ request }) {
const headers = await constructHeaders(request.headers)
headers.forEach((value, key) => {
request.headers.set(key, value)
})
return request
},
})
export const { GET: get, POST: post } = client