From 804f9ec35d1788401d230f34f13a52595daf8446 Mon Sep 17 00:00:00 2001 From: ocavue Date: Sat, 16 Sep 2023 00:31:17 +0800 Subject: [PATCH 1/5] Fix FetchProvider in non-browser environment --- packages/auth/src/core/util/fetch_provider.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/auth/src/core/util/fetch_provider.ts b/packages/auth/src/core/util/fetch_provider.ts index c7c3e0bd8bb..efe0f6f76c8 100644 --- a/packages/auth/src/core/util/fetch_provider.ts +++ b/packages/auth/src/core/util/fetch_provider.ts @@ -43,6 +43,9 @@ export class FetchProvider { if (typeof self !== 'undefined' && 'fetch' in self) { return self.fetch; } + if (typeof globalThis !== 'undefined' && 'fetch' in globalThis) { + return globalThis.fetch; + } debugFail( 'Could not find fetch implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill' ); @@ -55,6 +58,9 @@ export class FetchProvider { if (typeof self !== 'undefined' && 'Headers' in self) { return self.Headers; } + if (typeof globalThis !== 'undefined' && 'Headers' in globalThis) { + return globalThis.Headers; + } debugFail( 'Could not find Headers implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill' ); @@ -67,6 +73,9 @@ export class FetchProvider { if (typeof self !== 'undefined' && 'Response' in self) { return self.Response; } + if (typeof globalThis !== 'undefined' && 'Response' in globalThis) { + return globalThis.Response; + } debugFail( 'Could not find Response implementation, make sure you call FetchProvider.initialize() with an appropriate polyfill' ); From 1ac0e0edc999fdf45e4248db3ade4e381132bbe9 Mon Sep 17 00:00:00 2001 From: ocavue Date: Sat, 16 Sep 2023 05:51:32 +0800 Subject: [PATCH 2/5] Try to get fetch directly --- packages/auth/src/core/util/fetch_provider.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/auth/src/core/util/fetch_provider.ts b/packages/auth/src/core/util/fetch_provider.ts index efe0f6f76c8..14433d6eacb 100644 --- a/packages/auth/src/core/util/fetch_provider.ts +++ b/packages/auth/src/core/util/fetch_provider.ts @@ -43,9 +43,12 @@ export class FetchProvider { if (typeof self !== 'undefined' && 'fetch' in self) { return self.fetch; } - if (typeof globalThis !== 'undefined' && 'fetch' in globalThis) { + 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' ); @@ -58,9 +61,12 @@ export class FetchProvider { if (typeof self !== 'undefined' && 'Headers' in self) { return self.Headers; } - if (typeof globalThis !== 'undefined' && 'Headers' in globalThis) { + 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' ); @@ -73,9 +79,12 @@ export class FetchProvider { if (typeof self !== 'undefined' && 'Response' in self) { return self.Response; } - if (typeof globalThis !== 'undefined' && 'Response' in globalThis) { + 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' ); From c34e6bd090b13baef839cd742469cb9e1fc334f2 Mon Sep 17 00:00:00 2001 From: ocavue Date: Wed, 20 Sep 2023 11:21:55 +0800 Subject: [PATCH 3/5] Create afraid-waves-remember.md --- .changeset/afraid-waves-remember.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/afraid-waves-remember.md 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`. From 50b16f49f0aff9b23024cf0c0def2752562bcd04 Mon Sep 17 00:00:00 2001 From: ocavue Date: Wed, 18 Oct 2023 18:06:02 +0800 Subject: [PATCH 4/5] chore: trigger ci From 9dda1e5baa65c1f9ebc76e92be715ebbdc15977c Mon Sep 17 00:00:00 2001 From: ocavue Date: Thu, 19 Oct 2023 15:55:23 +0800 Subject: [PATCH 5/5] chore: trigger ci