react-query-firebase 1.2.1 → 1.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -70,7 +70,7 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
70
70
|
* security_storage: "denied"
|
|
71
71
|
* }
|
|
72
72
|
*/
|
|
73
|
-
|
|
73
|
+
consentSettings?: ConsentSettings;
|
|
74
74
|
/**
|
|
75
75
|
* Flag indicating whether Firebase Firestore should be enabled.
|
|
76
76
|
* @defaultValue `true`
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useMemo } from "react";
|
|
1
|
+
import React, { useEffect, useMemo } from "react";
|
|
2
2
|
import { FirebaseContext } from "./FirebaseContext";
|
|
3
3
|
import { connectAuthEmulator, getAuth } from "firebase/auth";
|
|
4
4
|
import { getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
|
|
@@ -28,10 +28,22 @@ import { initializeApp } from "firebase/app";
|
|
|
28
28
|
* };
|
|
29
29
|
* ```
|
|
30
30
|
*/
|
|
31
|
-
export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true,
|
|
31
|
+
export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, consentSettings = {}, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {} }) => {
|
|
32
32
|
const firebase = useMemo(() => {
|
|
33
33
|
return initializeApp(options);
|
|
34
34
|
}, [options]);
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
setConsent({
|
|
37
|
+
ad_personalization: "denied",
|
|
38
|
+
ad_storage: "denied",
|
|
39
|
+
ad_user_data: "denied",
|
|
40
|
+
analytics_storage: "denied",
|
|
41
|
+
functionality_storage: "denied",
|
|
42
|
+
personalization_storage: "denied",
|
|
43
|
+
security_storage: "denied",
|
|
44
|
+
...consentSettings
|
|
45
|
+
});
|
|
46
|
+
}, [consentSettings]);
|
|
35
47
|
const contextValue = useMemo(() => {
|
|
36
48
|
const value = {};
|
|
37
49
|
if (firestoreEnabled) {
|
|
@@ -50,20 +62,9 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
50
62
|
}
|
|
51
63
|
value.auth = auth;
|
|
52
64
|
}
|
|
53
|
-
setConsent({
|
|
54
|
-
ad_personalization: "denied",
|
|
55
|
-
ad_storage: "denied",
|
|
56
|
-
ad_user_data: "denied",
|
|
57
|
-
analytics_storage: "denied",
|
|
58
|
-
functionality_storage: "denied",
|
|
59
|
-
personalization_storage: "denied",
|
|
60
|
-
security_storage: "denied",
|
|
61
|
-
...defaultConsent
|
|
62
|
-
});
|
|
63
65
|
if (analyticsEnabled && options.measurementId && typeof window !== "undefined") {
|
|
64
66
|
const analytics = getAnalytics(firebase);
|
|
65
67
|
value.analytics = analytics;
|
|
66
|
-
setAnalyticsCollectionEnabled(analytics, defaultConsent?.analytics_storage === "granted");
|
|
67
68
|
}
|
|
68
69
|
if (remoteConfigEnabled && typeof window !== "undefined") {
|
|
69
70
|
const remoteConfig = getRemoteConfig(firebase);
|
|
@@ -76,5 +77,10 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
|
|
|
76
77
|
}
|
|
77
78
|
return { firebase, ...value };
|
|
78
79
|
}, [firebase]);
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (contextValue.analytics) {
|
|
82
|
+
setAnalyticsCollectionEnabled(contextValue.analytics, consentSettings?.analytics_storage === "granted");
|
|
83
|
+
}
|
|
84
|
+
}, [consentSettings]);
|
|
79
85
|
return (React.createElement(FirebaseContext.Provider, { value: contextValue }, children));
|
|
80
86
|
};
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { PropsWithChildren, useMemo } from "react";
|
|
1
|
+
import React, { PropsWithChildren, useEffect, useMemo } from "react";
|
|
2
2
|
import { FirebaseContext } from "./FirebaseContext";
|
|
3
3
|
import { connectAuthEmulator, getAuth } from "firebase/auth";
|
|
4
4
|
import { ConsentSettings, getAnalytics, setAnalyticsCollectionEnabled, setConsent } from "firebase/analytics";
|
|
@@ -77,7 +77,7 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
77
77
|
* security_storage: "denied"
|
|
78
78
|
* }
|
|
79
79
|
*/
|
|
80
|
-
|
|
80
|
+
consentSettings?: ConsentSettings;
|
|
81
81
|
/**
|
|
82
82
|
* Flag indicating whether Firebase Firestore should be enabled.
|
|
83
83
|
* @defaultValue `true`
|
|
@@ -129,7 +129,7 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
129
129
|
authEnabled = true,
|
|
130
130
|
firestoreEnabled = true,
|
|
131
131
|
analyticsEnabled = true,
|
|
132
|
-
|
|
132
|
+
consentSettings = {},
|
|
133
133
|
remoteConfigEnabled = true,
|
|
134
134
|
remoteConfigSettings,
|
|
135
135
|
remoteConfigDefaults = {}
|
|
@@ -138,6 +138,19 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
138
138
|
return initializeApp(options);
|
|
139
139
|
}, [options]);
|
|
140
140
|
|
|
141
|
+
useEffect(() => {
|
|
142
|
+
setConsent({
|
|
143
|
+
ad_personalization: "denied",
|
|
144
|
+
ad_storage: "denied",
|
|
145
|
+
ad_user_data: "denied",
|
|
146
|
+
analytics_storage: "denied",
|
|
147
|
+
functionality_storage: "denied",
|
|
148
|
+
personalization_storage: "denied",
|
|
149
|
+
security_storage: "denied",
|
|
150
|
+
...consentSettings
|
|
151
|
+
});
|
|
152
|
+
}, [consentSettings]);
|
|
153
|
+
|
|
141
154
|
const contextValue = useMemo(() => {
|
|
142
155
|
const value: Partial<React.ContextType<typeof FirebaseContext>> = {};
|
|
143
156
|
|
|
@@ -161,22 +174,9 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
161
174
|
value.auth = auth;
|
|
162
175
|
}
|
|
163
176
|
|
|
164
|
-
setConsent({
|
|
165
|
-
ad_personalization: "denied",
|
|
166
|
-
ad_storage: "denied",
|
|
167
|
-
ad_user_data: "denied",
|
|
168
|
-
analytics_storage: "denied",
|
|
169
|
-
functionality_storage: "denied",
|
|
170
|
-
personalization_storage: "denied",
|
|
171
|
-
security_storage: "denied",
|
|
172
|
-
...defaultConsent
|
|
173
|
-
});
|
|
174
|
-
|
|
175
177
|
if (analyticsEnabled && options.measurementId && typeof window !== "undefined") {
|
|
176
178
|
const analytics = getAnalytics(firebase);
|
|
177
179
|
value.analytics = analytics;
|
|
178
|
-
|
|
179
|
-
setAnalyticsCollectionEnabled(analytics, defaultConsent?.analytics_storage === "granted");
|
|
180
180
|
}
|
|
181
181
|
|
|
182
182
|
if (remoteConfigEnabled && typeof window !== "undefined") {
|
|
@@ -192,6 +192,12 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
192
192
|
return { firebase, ...value };
|
|
193
193
|
}, [firebase]);
|
|
194
194
|
|
|
195
|
+
useEffect(() => {
|
|
196
|
+
if (contextValue.analytics) {
|
|
197
|
+
setAnalyticsCollectionEnabled(contextValue.analytics, consentSettings?.analytics_storage === "granted");
|
|
198
|
+
}
|
|
199
|
+
}, [consentSettings]);
|
|
200
|
+
|
|
195
201
|
return (
|
|
196
202
|
<FirebaseContext.Provider value={contextValue as React.ContextType<typeof FirebaseContext>}>
|
|
197
203
|
{children}
|