Skip to content

Commit

Permalink
Fix FetchProvider in non-browser environment (#7634)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocavue committed Oct 23, 2023
1 parent bd073b2 commit f002ef3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/afraid-waves-remember.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/auth": patch
---

Fix FetchProvider in non-browser environments, by trying to get the `fetch` implementation from not only `self` but also standard `globalThis`.
18 changes: 18 additions & 0 deletions packages/auth/src/core/util/fetch_provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export class FetchProvider {
if (typeof self !== 'undefined' && 'fetch' in self) {
return self.fetch;
}
if (typeof globalThis !== 'undefined' && globalThis.fetch) {
return globalThis.fetch;
}
if (typeof fetch !== 'undefined') {
return fetch;
}
debugFail(
'Could not find fetch implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill'
);
Expand All @@ -55,6 +61,12 @@ export class FetchProvider {
if (typeof self !== 'undefined' && 'Headers' in self) {
return self.Headers;
}
if (typeof globalThis !== 'undefined' && globalThis.Headers) {
return globalThis.Headers;
}
if (typeof Headers !== 'undefined') {
return Headers;
}
debugFail(
'Could not find Headers implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill'
);
Expand All @@ -67,6 +79,12 @@ export class FetchProvider {
if (typeof self !== 'undefined' && 'Response' in self) {
return self.Response;
}
if (typeof globalThis !== 'undefined' && globalThis.Response) {
return globalThis.Response;
}
if (typeof Response !== 'undefined') {
return Response;
}
debugFail(
'Could not find Response implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill'
);
Expand Down

0 comments on commit f002ef3

Please sign in to comment.