• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / supabase-js / 7896106712

14 Feb 2024 03:31AM UTC coverage: 65.877% (+0.5%) from 65.385%
7896106712

Pull #976

github

web-flow
Merge 28f9621ed into b9cb9e1be
Pull Request #976: fix: revert from/schema/rpc changes

47 of 92 branches covered (51.09%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 1 file covered. (100.0%)

92 of 119 relevant lines covered (77.31%)

4.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.47
/src/lib/fetch.ts
1
// @ts-ignore
2
import nodeFetch, { Headers as NodeFetchHeaders } from '@supabase/node-fetch'
2✔
3

4
type Fetch = typeof fetch
5

6
export const resolveFetch = (customFetch?: Fetch): Fetch => {
2✔
7
  let _fetch: Fetch
8
  if (customFetch) {
7!
9
    _fetch = customFetch
×
10
  } else if (typeof fetch === 'undefined') {
7!
11
    _fetch = nodeFetch as unknown as Fetch
×
12
  } else {
13
    _fetch = fetch
7✔
14
  }
15
  return (...args) => _fetch(...args)
7✔
16
}
17

18
export const resolveHeadersConstructor = () => {
2✔
19
  if (typeof Headers === 'undefined') {
7!
20
    return NodeFetchHeaders
×
21
  }
22

23
  return Headers
7✔
24
}
25

26
export const fetchWithAuth = (
2✔
27
  supabaseKey: string,
28
  getAccessToken: () => Promise<string | null>,
29
  customFetch?: Fetch
30
): Fetch => {
31
  const fetch = resolveFetch(customFetch)
7✔
32
  const HeadersConstructor = resolveHeadersConstructor()
7✔
33

34
  return async (input, init) => {
7✔
35
    const accessToken = (await getAccessToken()) ?? supabaseKey
×
36
    let headers = new HeadersConstructor(init?.headers)
×
37

38
    if (!headers.has('apikey')) {
×
39
      headers.set('apikey', supabaseKey)
×
40
    }
41

42
    if (!headers.has('Authorization')) {
×
43
      headers.set('Authorization', `Bearer ${accessToken}`)
×
44
    }
45

46
    return fetch(input, { ...init, headers })
×
47
  }
48
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc