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

supabase / supabase-js / 5094229097

26 May 2023 07:15PM UTC coverage: 66.492% (-1.0%) from 67.513%
5094229097

Pull #778

github

GitHub
Merge abdf36db1 into 3c552377f
Pull Request #778: feat: edge functions support for custom domains and vanity domains

44 of 84 branches covered (52.38%)

Branch coverage included in aggregate %.

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

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

42.11
/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
6✔
11
  } else {
12
    _fetch = fetch
×
13
  }
14
  return (...args) => _fetch(...args)
6✔
15
}
16

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

22
  return Headers
×
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