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

supabase / supabase-js / 16261028777

14 Jul 2025 07:44AM UTC coverage: 72.889%. Remained the same
16261028777

Pull #1497

github

web-flow
Merge 7b175c40d into d78ce0eab
Pull Request #1497: feat: bump auth-js to 2.71.0

55 of 93 branches covered (59.14%)

Branch coverage included in aggregate %.

109 of 132 relevant lines covered (82.58%)

26.43 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'
6✔
3

4
type Fetch = typeof fetch
5

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

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

23
  return Headers
57✔
24
}
25

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

34
  return async (input, init) => {
57✔
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