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

supabase / supabase-js / 5637173022

23 Jul 2023 03:10PM UTC coverage: 65.969% (-0.5%) from 66.492%
5637173022

Pull #814

github

web-flow
Merge de342cbda into ce46e6967
Pull Request #814: feat: bump node version to 18

43 of 84 branches covered (51.19%)

Branch coverage included in aggregate %.

83 of 107 relevant lines covered (77.57%)

4.12 hits per line

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

39.47
/src/lib/fetch.ts
1
import crossFetch, { Headers as CrossFetchHeaders } from 'cross-fetch'
2✔
2

3
type Fetch = typeof fetch
4

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

17
export const resolveHeadersConstructor = () => {
2✔
18
  if (typeof Headers === 'undefined') {
6!
19
    return CrossFetchHeaders
×
20
  }
21

22
  return Headers
6✔
23
}
24

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

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

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

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

45
    return fetch(input, { ...init, headers })
×
46
  }
47
}
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