Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix FetchProvider in non-browser environment #7634

Merged
merged 6 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading