Skip to content

Commit 39b7656

Browse files
ocavueprameshj
authored andcommitted
Fix FetchProvider in non-browser environment (#7634)
1 parent 50668ec commit 39b7656

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

.changeset/afraid-waves-remember.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@firebase/auth": patch
3+
---
4+
5+
Fix FetchProvider in non-browser environments, by trying to get the `fetch` implementation from not only `self` but also standard `globalThis`.

packages/auth/src/core/util/fetch_provider.ts

+18
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ export class FetchProvider {
4343
if (typeof self !== 'undefined' && 'fetch' in self) {
4444
return self.fetch;
4545
}
46+
if (typeof globalThis !== 'undefined' && globalThis.fetch) {
47+
return globalThis.fetch;
48+
}
49+
if (typeof fetch !== 'undefined') {
50+
return fetch;
51+
}
4652
debugFail(
4753
'Could not find fetch implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill'
4854
);
@@ -55,6 +61,12 @@ export class FetchProvider {
5561
if (typeof self !== 'undefined' && 'Headers' in self) {
5662
return self.Headers;
5763
}
64+
if (typeof globalThis !== 'undefined' && globalThis.Headers) {
65+
return globalThis.Headers;
66+
}
67+
if (typeof Headers !== 'undefined') {
68+
return Headers;
69+
}
5870
debugFail(
5971
'Could not find Headers implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill'
6072
);
@@ -67,6 +79,12 @@ export class FetchProvider {
6779
if (typeof self !== 'undefined' && 'Response' in self) {
6880
return self.Response;
6981
}
82+
if (typeof globalThis !== 'undefined' && globalThis.Response) {
83+
return globalThis.Response;
84+
}
85+
if (typeof Response !== 'undefined') {
86+
return Response;
87+
}
7088
debugFail(
7189
'Could not find Response implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill'
7290
);

0 commit comments

Comments
 (0)