diff --git a/package-lock.json b/package-lock.json index b836b996..5d43a1d3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,6 @@ "dependencies": { "@supabase/auth-js": "2.64.2", "@supabase/functions-js": "2.4.1", - "@supabase/node-fetch": "2.6.15", "@supabase/postgrest-js": "1.15.7", "@supabase/realtime-js": "2.10.1", "@supabase/storage-js": "2.6.0" diff --git a/package.json b/package.json index 1a0f579a..8479fb96 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,6 @@ "dependencies": { "@supabase/auth-js": "2.64.2", "@supabase/functions-js": "2.4.1", - "@supabase/node-fetch": "2.6.15", "@supabase/postgrest-js": "1.15.7", "@supabase/realtime-js": "2.10.1", "@supabase/storage-js": "2.6.0" diff --git a/src/lib/fetch.ts b/src/lib/fetch.ts index c3ec5f42..b00564ae 100644 --- a/src/lib/fetch.ts +++ b/src/lib/fetch.ts @@ -1,39 +1,14 @@ -// @ts-ignore -import nodeFetch, { Headers as NodeFetchHeaders } from '@supabase/node-fetch' - type Fetch = typeof fetch -export const resolveFetch = (customFetch?: Fetch): Fetch => { - let _fetch: Fetch - if (customFetch) { - _fetch = customFetch - } else if (typeof fetch === 'undefined') { - _fetch = nodeFetch as unknown as Fetch - } else { - _fetch = fetch - } - return (...args: Parameters) => _fetch(...args) -} - -export const resolveHeadersConstructor = () => { - if (typeof Headers === 'undefined') { - return NodeFetchHeaders - } - - return Headers -} - export const fetchWithAuth = ( supabaseKey: string, getAccessToken: () => Promise, customFetch?: Fetch ): Fetch => { - const fetch = resolveFetch(customFetch) - const HeadersConstructor = resolveHeadersConstructor() - return async (input, init) => { + const fetch_ = customFetch ?? fetch const accessToken = (await getAccessToken()) ?? supabaseKey - let headers = new HeadersConstructor(init?.headers) + let headers = new Headers(init?.headers) if (!headers.has('apikey')) { headers.set('apikey', supabaseKey) @@ -43,6 +18,6 @@ export const fetchWithAuth = ( headers.set('Authorization', `Bearer ${accessToken}`) } - return fetch(input, { ...init, headers }) + return fetch_(input, { ...init, headers }) } }