Spaces:
Running
Running
Download node_modules/@supabase/supabase-js/src/lib/fetch.ts from Harry9233/Taste_Rider_Web: direct link, hf CLI and curl.
- Browser
- Download file 1.19 kB
-
https://huggingface.co/spaces/Harry9233/Taste_Rider_Web/resolve/main/node_modules/%40supabase/supabase-js/src/lib/fetch.ts
- Command line
-
hf download hf://spaces/Harry9233/Taste_Rider_Web/node_modules/@supabase/supabase-js/src/lib/fetch.ts
-
curl -L -o fetch.ts https://huggingface.co/spaces/Harry9233/Taste_Rider_Web/resolve/main/node_modules/%40supabase/supabase-js/src/lib/fetch.ts
1.19 kB
| // @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) => _fetch(...args) | |
| } | |
| export const resolveHeadersConstructor = () => { | |
| if (typeof Headers === 'undefined') { | |
| return NodeFetchHeaders | |
| } | |
| return Headers | |
| } | |
| export const fetchWithAuth = ( | |
| supabaseKey: string, | |
| getAccessToken: () => Promise<string | null>, | |
| customFetch?: Fetch | |
| ): Fetch => { | |
| const fetch = resolveFetch(customFetch) | |
| const HeadersConstructor = resolveHeadersConstructor() | |
| return async (input, init) => { | |
| const accessToken = (await getAccessToken()) ?? supabaseKey | |
| let headers = new HeadersConstructor(init?.headers) | |
| if (!headers.has('apikey')) { | |
| headers.set('apikey', supabaseKey) | |
| } | |
| if (!headers.has('Authorization')) { | |
| headers.set('Authorization', `Bearer ${accessToken}`) | |
| } | |
| return fetch(input, { ...init, headers }) | |
| } | |
| } | |