diff --git a/.changeset/afraid-waves-remember.md b/.changeset/afraid-waves-remember.md new file mode 100644 index 00000000000..8e0caf998d4 --- /dev/null +++ b/.changeset/afraid-waves-remember.md @@ -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`. diff --git a/packages/auth/src/core/util/fetch_provider.ts b/packages/auth/src/core/util/fetch_provider.ts index c7c3e0bd8bb..14433d6eacb 100644 --- a/packages/auth/src/core/util/fetch_provider.ts +++ b/packages/auth/src/core/util/fetch_provider.ts @@ -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' ); @@ -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' ); @@ -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' );