react-query-firebase 1.0.3 → 1.0.5

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.
Files changed (149) hide show
  1. package/README.md +27 -3
  2. package/dist/src/analytics/index.d.ts +1 -0
  3. package/dist/src/analytics/index.js +1 -0
  4. package/dist/src/analytics/useAnalytics.d.ts +5 -0
  5. package/dist/src/analytics/useAnalytics.js +10 -0
  6. package/dist/src/analytics/useLogEvent.d.ts +7 -0
  7. package/dist/src/analytics/useLogEvent.js +8 -1
  8. package/dist/src/auth/index.d.ts +1 -0
  9. package/dist/src/auth/index.js +1 -0
  10. package/dist/src/auth/useAuth.d.ts +5 -0
  11. package/dist/src/auth/useAuth.js +10 -0
  12. package/dist/src/auth/useAuthStateReady.d.ts +5 -0
  13. package/dist/src/auth/useAuthStateReady.js +6 -1
  14. package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +7 -0
  15. package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.js +8 -1
  16. package/dist/src/auth/useCurrentUser.d.ts +5 -0
  17. package/dist/src/auth/useCurrentUser.js +6 -1
  18. package/dist/src/auth/useIdToken.d.ts +8 -0
  19. package/dist/src/auth/useIdToken.js +8 -0
  20. package/dist/src/auth/useReauthenticateWitCredentialMutation.d.ts +8 -0
  21. package/dist/src/auth/useReauthenticateWitCredentialMutation.js +8 -0
  22. package/dist/src/auth/useReauthenticateWitRedirectMutation.d.ts +8 -0
  23. package/dist/src/auth/useReauthenticateWitRedirectMutation.js +8 -0
  24. package/dist/src/auth/useSendEmailVerificationMutation.d.ts +6 -0
  25. package/dist/src/auth/useSendEmailVerificationMutation.js +6 -0
  26. package/dist/src/auth/useSignInWitEmailAndPasswordMutation.d.ts +7 -0
  27. package/dist/src/auth/useSignInWitEmailAndPasswordMutation.js +8 -1
  28. package/dist/src/auth/useSignInWitRedirectMutation.d.ts +6 -0
  29. package/dist/src/auth/useSignInWitRedirectMutation.js +7 -1
  30. package/dist/src/auth/useSignOutMutation.d.ts +7 -0
  31. package/dist/src/auth/useSignOutMutation.js +8 -1
  32. package/dist/src/auth/useUpdateProfileMutation.d.ts +7 -0
  33. package/dist/src/auth/useUpdateProfileMutation.js +7 -0
  34. package/dist/src/{FirebaseContext.d.ts → context/FirebaseContext.d.ts} +8 -2
  35. package/dist/src/context/FirebaseContext.js +8 -0
  36. package/dist/src/context/FirebaseContextProvider.d.ts +105 -0
  37. package/dist/src/{FirebaseContextProvider.js → context/FirebaseContextProvider.js} +24 -1
  38. package/dist/src/context/index.d.ts +1 -0
  39. package/dist/src/context/index.js +1 -0
  40. package/dist/src/firestore/index.d.ts +1 -0
  41. package/dist/src/firestore/index.js +1 -0
  42. package/dist/src/firestore/useAddDocMutation.d.ts +11 -0
  43. package/dist/src/firestore/useAddDocMutation.js +11 -0
  44. package/dist/src/firestore/useBatchWrite.d.ts +7 -0
  45. package/dist/src/firestore/useBatchWrite.js +8 -1
  46. package/dist/src/firestore/useCollectionReference.d.ts +11 -0
  47. package/dist/src/firestore/useCollectionReference.js +12 -1
  48. package/dist/src/firestore/useCompositeFilter.d.ts +10 -0
  49. package/dist/src/firestore/useCompositeFilter.js +17 -0
  50. package/dist/src/firestore/useCountQuery.d.ts +13 -0
  51. package/dist/src/firestore/useCountQuery.js +13 -0
  52. package/dist/src/firestore/useDeleteDocMutation.d.ts +7 -0
  53. package/dist/src/firestore/useDeleteDocMutation.js +7 -0
  54. package/dist/src/firestore/useDocReference.d.ts +12 -0
  55. package/dist/src/firestore/useDocReference.js +25 -1
  56. package/dist/src/firestore/useDocReferences.d.ts +16 -0
  57. package/dist/src/firestore/useDocReferences.js +17 -1
  58. package/dist/src/firestore/useFirestore.d.ts +7 -0
  59. package/dist/src/firestore/useFirestore.js +12 -0
  60. package/dist/src/firestore/useGetDocData.d.ts +8 -0
  61. package/dist/src/firestore/useGetDocData.js +9 -1
  62. package/dist/src/firestore/useInfiniteQuery.d.ts +7 -0
  63. package/dist/src/firestore/useInfiniteQuery.js +7 -0
  64. package/dist/src/firestore/useQuery.d.ts +14 -0
  65. package/dist/src/firestore/useQuery.js +14 -0
  66. package/dist/src/firestore/useRunTransaction.d.ts +7 -0
  67. package/dist/src/firestore/useRunTransaction.js +8 -1
  68. package/dist/src/firestore/useSetDocMutation.d.ts +9 -0
  69. package/dist/src/firestore/useSetDocMutation.js +9 -0
  70. package/dist/src/firestore/useUpdateDocMutation.d.ts +19 -0
  71. package/dist/src/firestore/useUpdateDocMutation.js +19 -0
  72. package/dist/src/firestore/utils/getDocData.d.ts +14 -0
  73. package/dist/src/firestore/utils/getDocData.js +14 -0
  74. package/dist/src/firestore/utils/getDocRef.d.ts +11 -0
  75. package/dist/src/firestore/utils/getDocRef.js +11 -0
  76. package/dist/src/firestore/utils/getDocSnap.d.ts +16 -0
  77. package/dist/src/firestore/utils/getDocSnap.js +16 -0
  78. package/dist/src/index.d.ts +1 -6
  79. package/dist/src/index.js +1 -6
  80. package/dist/src/remoteConfig/index.d.ts +1 -0
  81. package/dist/src/remoteConfig/index.js +1 -0
  82. package/dist/src/remoteConfig/useFetchAndActivate.d.ts +7 -0
  83. package/dist/src/remoteConfig/useFetchAndActivate.js +13 -4
  84. package/dist/src/remoteConfig/useGetValue.d.ts +6 -0
  85. package/dist/src/remoteConfig/useGetValue.js +7 -1
  86. package/dist/src/remoteConfig/useRemoteConfig.d.ts +5 -0
  87. package/dist/src/remoteConfig/useRemoteConfig.js +10 -0
  88. package/package.json +13 -5
  89. package/src/analytics/index.ts +1 -0
  90. package/src/analytics/useAnalytics.ts +12 -0
  91. package/src/analytics/useLogEvent.ts +8 -1
  92. package/src/auth/index.ts +1 -0
  93. package/src/auth/useAuth.ts +12 -0
  94. package/src/auth/useAuthStateReady.ts +6 -1
  95. package/src/auth/useCreateUserWitEmailAndPasswordMutation.ts +8 -1
  96. package/src/auth/useCurrentUser.ts +6 -1
  97. package/src/auth/useIdToken.ts +8 -0
  98. package/src/auth/useReauthenticateWitCredentialMutation.ts +8 -0
  99. package/src/auth/useReauthenticateWitRedirectMutation.ts +8 -0
  100. package/src/auth/useSendEmailVerificationMutation.ts +6 -0
  101. package/src/auth/useSignInWitEmailAndPasswordMutation.ts +8 -1
  102. package/src/auth/useSignInWitRedirectMutation.ts +7 -1
  103. package/src/auth/useSignOutMutation.ts +8 -1
  104. package/src/auth/useUpdateProfileMutation.ts +7 -0
  105. package/src/{FirebaseContext.ts → context/FirebaseContext.ts} +9 -2
  106. package/src/context/FirebaseContextProvider.tsx +173 -0
  107. package/src/context/index.ts +1 -0
  108. package/src/firestore/index.ts +1 -0
  109. package/src/firestore/useAddDocMutation.ts +11 -0
  110. package/src/firestore/useBatchWrite.ts +8 -1
  111. package/src/firestore/useCollectionReference.ts +12 -1
  112. package/src/firestore/useCompositeFilter.ts +18 -0
  113. package/src/firestore/useCountQuery.ts +14 -0
  114. package/src/firestore/useDeleteDocMutation.ts +7 -0
  115. package/src/firestore/useDocReference.ts +25 -1
  116. package/src/firestore/useDocReferences.ts +17 -1
  117. package/src/firestore/useFirestore.ts +13 -0
  118. package/src/firestore/useGetDocData.ts +9 -1
  119. package/src/firestore/useInfiniteQuery.ts +7 -0
  120. package/src/firestore/useQuery.ts +14 -0
  121. package/src/firestore/useRunTransaction.ts +8 -1
  122. package/src/firestore/useSetDocMutation.ts +9 -0
  123. package/src/firestore/useUpdateDocMutation.ts +19 -0
  124. package/src/firestore/utils/getDocData.ts +14 -0
  125. package/src/firestore/utils/getDocRef.ts +11 -0
  126. package/src/firestore/utils/getDocSnap.ts +16 -0
  127. package/src/index.ts +1 -6
  128. package/src/remoteConfig/index.ts +1 -0
  129. package/src/remoteConfig/useFetchAndActivate.ts +13 -4
  130. package/src/remoteConfig/useGetValue.ts +7 -1
  131. package/src/remoteConfig/useRemoteConfig.ts +11 -0
  132. package/dist/src/FirebaseContext.js +0 -3
  133. package/dist/src/FirebaseContextProvider.d.ts +0 -28
  134. package/dist/src/useAnalytics.d.ts +0 -1
  135. package/dist/src/useAnalytics.js +0 -6
  136. package/dist/src/useAuth.d.ts +0 -1
  137. package/dist/src/useAuth.js +0 -6
  138. package/dist/src/useFirebase.d.ts +0 -1
  139. package/dist/src/useFirebase.js +0 -6
  140. package/dist/src/useFirestore.d.ts +0 -1
  141. package/dist/src/useFirestore.js +0 -6
  142. package/dist/src/useRemoteConfig.d.ts +0 -1
  143. package/dist/src/useRemoteConfig.js +0 -6
  144. package/src/FirebaseContextProvider.tsx +0 -91
  145. package/src/useAnalytics.ts +0 -8
  146. package/src/useAuth.ts +0 -8
  147. package/src/useFirebase.ts +0 -8
  148. package/src/useFirestore.ts +0 -7
  149. package/src/useRemoteConfig.ts +0 -7
package/README.md CHANGED
@@ -9,13 +9,37 @@ This module offers a set of hooks to work with [Firebase](https://firebase.googl
9
9
  Run the following command to install:
10
10
 
11
11
  ```
12
- npm i react-query-firebase
12
+ npm i react-query-firebase @tanstack/react-query --save
13
13
  ```
14
14
 
15
- ## Usage
15
+ ## Basic Example
16
16
 
17
- TODO:
17
+ ```jsx
18
+ import { useQuery, FirebaseContextProvider } from "react-query-firebase";
18
19
 
20
+ const firebaseConfig = {};
21
+ export const App = () => {
22
+ const [queryClient] = useState(() => new QueryClient({ defaultOptions: { queries: { throwOnError: true } } }));
23
+
24
+ return (
25
+ <QueryClientProvider client={queryClient}>
26
+ <FirebaseContextProvider options={firebaseConfig}>
27
+ <ChildComponent />
28
+ </FirebaseContextProvider>
29
+ </QueryClientProvider>
30
+ );
31
+ };
32
+
33
+ export const ChildComponent = () => {
34
+ const { data, isFetching } = useQuery({});
35
+
36
+ return <div>{JSON.stringify(data)}</div>;
37
+ };
38
+ ```
39
+
40
+ ## Documentation
41
+
42
+ 1. [All docs](https://vpishuk.github.io/react-query-firebase).
19
43
 
20
44
  ## Contribution guidelines
21
45
 
@@ -1 +1,2 @@
1
1
  export * from "./useLogEvent";
2
+ export * from "./useAnalytics";
@@ -1 +1,2 @@
1
1
  export * from "./useLogEvent";
2
+ export * from "./useAnalytics";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Hook to access Firebase analytics from the Firebase context.
3
+ * @returns {any} The analytics object from the Firebase context.
4
+ */
5
+ export declare const useAnalytics: () => import("@firebase/analytics").Analytics;
@@ -0,0 +1,10 @@
1
+ import { useContext } from "react";
2
+ import { FirebaseContext } from "../context/FirebaseContext";
3
+ /**
4
+ * Hook to access Firebase analytics from the Firebase context.
5
+ * @returns {any} The analytics object from the Firebase context.
6
+ */
7
+ export const useAnalytics = () => {
8
+ const { analytics } = useContext(FirebaseContext);
9
+ return analytics;
10
+ };
@@ -4,6 +4,13 @@ type UseLogEventOptions = {
4
4
  [key: string]: unknown;
5
5
  };
6
6
  };
7
+ /**
8
+ * Custom hook to create a log event function that logs an analytics event with specified parameters.
9
+ * @param {Object} options - The options for the log event.
10
+ * @param {string} options.eventName - The name of the event to be logged.
11
+ * @param {Object} options.eventParams - The parameters to be sent along with the event.
12
+ * @returns {Object} An object containing a `logEvent` function that, when called, logs the event.
13
+ */
7
14
  export declare const useLogEvent: ({ eventName, eventParams }: UseLogEventOptions) => {
8
15
  logEvent: () => void;
9
16
  };
@@ -1,6 +1,13 @@
1
1
  import { logEvent } from "firebase/analytics";
2
- import { useAnalytics } from "../useAnalytics";
2
+ import { useAnalytics } from "./useAnalytics";
3
3
  import { useCallback, useMemo } from "react";
4
+ /**
5
+ * Custom hook to create a log event function that logs an analytics event with specified parameters.
6
+ * @param {Object} options - The options for the log event.
7
+ * @param {string} options.eventName - The name of the event to be logged.
8
+ * @param {Object} options.eventParams - The parameters to be sent along with the event.
9
+ * @returns {Object} An object containing a `logEvent` function that, when called, logs the event.
10
+ */
4
11
  export const useLogEvent = ({ eventName, eventParams }) => {
5
12
  const analytics = useAnalytics();
6
13
  const logEventCallback = useCallback(() => {
@@ -1,4 +1,5 @@
1
1
  export * from "./mutation-keys";
2
+ export * from "./useAuth";
2
3
  export * from "./useCreateUserWitEmailAndPasswordMutation";
3
4
  export * from "./useSendEmailVerificationMutation";
4
5
  export * from "./useSignInWitEmailAndPasswordMutation";
@@ -1,4 +1,5 @@
1
1
  export * from "./mutation-keys";
2
+ export * from "./useAuth";
2
3
  export * from "./useCreateUserWitEmailAndPasswordMutation";
3
4
  export * from "./useSendEmailVerificationMutation";
4
5
  export * from "./useSignInWitEmailAndPasswordMutation";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Custom hook to retrieve the authentication object from the Firebase context.
3
+ * @returns {Auth} The authentication object from the Firebase context.
4
+ */
5
+ export declare const useAuth: () => import("firebase/auth").Auth;
@@ -0,0 +1,10 @@
1
+ import { useContext } from "react";
2
+ import { FirebaseContext } from "../context/FirebaseContext";
3
+ /**
4
+ * Custom hook to retrieve the authentication object from the Firebase context.
5
+ * @returns {Auth} The authentication object from the Firebase context.
6
+ */
7
+ export const useAuth = () => {
8
+ const { auth } = useContext(FirebaseContext);
9
+ return auth;
10
+ };
@@ -1 +1,6 @@
1
+ /**
2
+ * A custom hook that determines if the Firebase authentication state is ready.
3
+ * It uses Firebase authentication to check if the auth state is ready and updates the state accordingly.
4
+ * @returns {boolean} Indicates whether the authentication state is ready.
5
+ */
1
6
  export declare const useAuthStateReady: () => boolean;
@@ -1,5 +1,10 @@
1
- import { useAuth } from "../useAuth";
1
+ import { useAuth } from "./useAuth";
2
2
  import { useCallback, useEffect, useState } from "react";
3
+ /**
4
+ * A custom hook that determines if the Firebase authentication state is ready.
5
+ * It uses Firebase authentication to check if the auth state is ready and updates the state accordingly.
6
+ * @returns {boolean} Indicates whether the authentication state is ready.
7
+ */
3
8
  export const useAuthStateReady = () => {
4
9
  const firebaseAuth = useAuth();
5
10
  const [isAuthStateReady, setIsAuthStateReady] = useState(false);
@@ -5,4 +5,11 @@ export type UseCreateUserWitEmailAndPasswordMutationVariables = {
5
5
  email: string;
6
6
  password: string;
7
7
  };
8
+ /**
9
+ * Custom hook to initiate a user creation process using email and password with Firebase authentication.
10
+ * This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
11
+ *
12
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
13
+ * @returns {UseMutationResult<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
14
+ */
8
15
  export declare const useCreateUserWitEmailAndPasswordMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>;
@@ -1,7 +1,14 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { createUserWithEmailAndPassword } from "firebase/auth";
3
- import { useAuth } from "../useAuth";
3
+ import { useAuth } from "./useAuth";
4
4
  import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
5
+ /**
6
+ * Custom hook to initiate a user creation process using email and password with Firebase authentication.
7
+ * This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
8
+ *
9
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
10
+ * @returns {UseMutationResult<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
11
+ */
5
12
  export const useCreateUserWitEmailAndPasswordMutation = (options = {}) => {
6
13
  const firebaseAuth = useAuth();
7
14
  return useMutation({
@@ -1 +1,6 @@
1
+ /**
2
+ * Hook that provides the current authenticated user from Firebase Auth.
3
+ * It listens for changes in the authentication state and updates the user accordingly.
4
+ * @returns {Object|null} The current authenticated user object or null if no user is authenticated.
5
+ */
1
6
  export declare const useCurrentUser: () => import("firebase/auth").User | null;
@@ -1,5 +1,10 @@
1
- import { useAuth } from "../useAuth";
1
+ import { useAuth } from "./useAuth";
2
2
  import { useEffect, useState } from "react";
3
+ /**
4
+ * Hook that provides the current authenticated user from Firebase Auth.
5
+ * It listens for changes in the authentication state and updates the user accordingly.
6
+ * @returns {Object|null} The current authenticated user object or null if no user is authenticated.
7
+ */
3
8
  export const useCurrentUser = () => {
4
9
  const firebaseAuth = useAuth();
5
10
  const [currentUser, setCurrentUser] = useState(firebaseAuth.currentUser);
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Custom hook to manage an ID token for the current user.
3
+ * This hook provides an `idToken` value and a `refresh` function to manually refresh the token.
4
+ *
5
+ * @returns {Object} An object containing:
6
+ * @returns {string} idToken - The current ID token for the user.
7
+ * @returns {Function} refresh - A function to refresh the ID token.
8
+ */
1
9
  export declare const useIdToken: () => {
2
10
  idToken: string;
3
11
  refresh: () => Promise<void>;
@@ -1,5 +1,13 @@
1
1
  import { useCallback, useEffect, useState } from "react";
2
2
  import { useCurrentUser } from "./useCurrentUser";
3
+ /**
4
+ * Custom hook to manage an ID token for the current user.
5
+ * This hook provides an `idToken` value and a `refresh` function to manually refresh the token.
6
+ *
7
+ * @returns {Object} An object containing:
8
+ * @returns {string} idToken - The current ID token for the user.
9
+ * @returns {Function} refresh - A function to refresh the ID token.
10
+ */
3
11
  export const useIdToken = () => {
4
12
  const currentUser = useCurrentUser();
5
13
  const [idToken, setIdToken] = useState("");
@@ -5,4 +5,12 @@ export type UseReauthenticateWitCredentialMutationVariables = {
5
5
  credential: AuthCredential;
6
6
  user: User;
7
7
  };
8
+ /**
9
+ * Custom hook to create a mutation for re-authenticating a user with a given credential.
10
+ * This hook utilizes useMutation from React Query to manage the asynchronous re-authentication
11
+ * process with Firebase credentials. It omits the default "mutationKey" and "mutationFn" options.
12
+ *
13
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional mutation options excluding "mutationKey" and "mutationFn".
14
+ * @returns {UseMutationResult<UserCredential, FirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>} A useMutation result object managing the loading, error, and result state of the re-authentication mutation.
15
+ */
8
16
  export declare const useReauthenticateWitCredentialMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<UserCredential, FirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<UserCredential, FirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>;
@@ -1,6 +1,14 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { reauthenticateWithCredential } from "firebase/auth";
3
3
  import { REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY } from "./mutation-keys";
4
+ /**
5
+ * Custom hook to create a mutation for re-authenticating a user with a given credential.
6
+ * This hook utilizes useMutation from React Query to manage the asynchronous re-authentication
7
+ * process with Firebase credentials. It omits the default "mutationKey" and "mutationFn" options.
8
+ *
9
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional mutation options excluding "mutationKey" and "mutationFn".
10
+ * @returns {UseMutationResult<UserCredential, FirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>} A useMutation result object managing the loading, error, and result state of the re-authentication mutation.
11
+ */
4
12
  export const useReauthenticateWitCredentialMutation = (options = {}) => {
5
13
  return useMutation({
6
14
  ...options,
@@ -6,4 +6,12 @@ export type UseReauthenticateWitRedirectMutationVariables = {
6
6
  popupRedirectResolver?: PopupRedirectResolver;
7
7
  user: User;
8
8
  };
9
+ /**
10
+ * Custom hook that provides a mutation to reauthenticate a user with a given authentication provider using redirection.
11
+ * This hook uses the `useMutation` hook from the React Query library to handle async mutation logic.
12
+ *
13
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configuration object for the mutation. It provides the ability to pass options to customize the behavior of the mutation.
14
+ * @template TContext - The type of any additional context you wish to pass to the mutation.
15
+ * @returns {UseMutationResult<void, FirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>} A mutation result object containing methods and state of the mutation.
16
+ */
9
17
  export declare const useReauthenticateWitRedirectMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, FirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>;
@@ -1,6 +1,14 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { reauthenticateWithRedirect } from "firebase/auth";
3
3
  import { REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
4
+ /**
5
+ * Custom hook that provides a mutation to reauthenticate a user with a given authentication provider using redirection.
6
+ * This hook uses the `useMutation` hook from the React Query library to handle async mutation logic.
7
+ *
8
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configuration object for the mutation. It provides the ability to pass options to customize the behavior of the mutation.
9
+ * @template TContext - The type of any additional context you wish to pass to the mutation.
10
+ * @returns {UseMutationResult<void, FirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>} A mutation result object containing methods and state of the mutation.
11
+ */
4
12
  export const useReauthenticateWitRedirectMutation = (options = {}) => {
5
13
  return useMutation({
6
14
  ...options,
@@ -4,4 +4,10 @@ import { FirebaseError } from "firebase/app";
4
4
  export type UseSendEmailVerificationMutationVariables = {
5
5
  user: User;
6
6
  };
7
+ /**
8
+ * A custom hook to create a mutation for sending an email verification to a user using Firebase.
9
+ * This uses the `useMutation` hook from a query library and wraps it with specific configuration options.
10
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding `queryKey` and `queryFn`.
11
+ * @returns {UseMutationResult<void, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>} An object containing mutation state and functions for managing the mutation lifecycle.
12
+ */
7
13
  export declare const useSendEmailVerificationMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>, "queryKey" | "queryFn">) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>;
@@ -1,6 +1,12 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { sendEmailVerification } from "firebase/auth";
3
3
  import { SEND_EMAIL_VERIFICATION_MUTATION_KEY } from "./mutation-keys";
4
+ /**
5
+ * A custom hook to create a mutation for sending an email verification to a user using Firebase.
6
+ * This uses the `useMutation` hook from a query library and wraps it with specific configuration options.
7
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding `queryKey` and `queryFn`.
8
+ * @returns {UseMutationResult<void, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>} An object containing mutation state and functions for managing the mutation lifecycle.
9
+ */
4
10
  export const useSendEmailVerificationMutation = (options = {}) => {
5
11
  return useMutation({
6
12
  ...options,
@@ -5,4 +5,11 @@ export type UseSignInWitEmailAndPasswordMutationVariables = {
5
5
  email: string;
6
6
  password: string;
7
7
  };
8
+ /**
9
+ * Custom hook to perform a sign-in operation using email and password with Firebase Authentication.
10
+ * It utilizes the `useMutation` hook to manage the asynchronous operation and its state.
11
+ *
12
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>, 'mutationKey' | 'mutationFn'>} options - Options to configure the mutation, excluding 'mutationKey' and 'mutationFn'.
13
+ * @returns {MutationResult} A mutation object containing the result of the sign-in process and helper functions.
14
+ */
8
15
  export declare const useSignInWitEmailAndPasswordMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<UserCredential, FirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<UserCredential, FirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>;
@@ -1,7 +1,14 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { signInWithEmailAndPassword } from "firebase/auth";
3
- import { useAuth } from "../useAuth";
3
+ import { useAuth } from "./useAuth";
4
4
  import { SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
5
+ /**
6
+ * Custom hook to perform a sign-in operation using email and password with Firebase Authentication.
7
+ * It utilizes the `useMutation` hook to manage the asynchronous operation and its state.
8
+ *
9
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>, 'mutationKey' | 'mutationFn'>} options - Options to configure the mutation, excluding 'mutationKey' and 'mutationFn'.
10
+ * @returns {MutationResult} A mutation object containing the result of the sign-in process and helper functions.
11
+ */
5
12
  export const useSignInWitEmailAndPasswordMutation = (options = {}) => {
6
13
  const firebaseAuth = useAuth();
7
14
  return useMutation({
@@ -5,4 +5,10 @@ export type UseSignInWitRedirectMutationVariables = {
5
5
  authProvider: AuthProvider;
6
6
  popupRedirectResolver?: PopupRedirectResolver;
7
7
  };
8
+ /**
9
+ * Custom hook for handling Firebase authentication using sign-in with redirect functionality.
10
+ * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
11
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
12
+ * @returns {UseMutationResult<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
13
+ */
8
14
  export declare const useSignInWitRedirectMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>;
@@ -1,7 +1,13 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { signInWithRedirect } from "firebase/auth";
3
- import { useAuth } from "../useAuth";
3
+ import { useAuth } from "./useAuth";
4
4
  import { SIGN_IN_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
5
+ /**
6
+ * Custom hook for handling Firebase authentication using sign-in with redirect functionality.
7
+ * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
8
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
9
+ * @returns {UseMutationResult<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
10
+ */
5
11
  export const useSignInWitRedirectMutation = (options = {}) => {
6
12
  const firebaseAuth = useAuth();
7
13
  return useMutation({
@@ -1,3 +1,10 @@
1
1
  import { UseMutationOptions } from "@tanstack/react-query";
2
2
  import { FirebaseError } from "firebase/app";
3
+ /**
4
+ * Custom hook for handling the sign-out mutation using Firebase authentication.
5
+ * It wraps the useMutation hook to provide a sign-out function with Firebase.
6
+ *
7
+ * @param {Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding "queryKey" and "queryFn".
8
+ * @returns {UseMutationResult<void, FirebaseError, void, TContext>} A mutation object for handling the sign-out process, including methods for mutating and state tracking.
9
+ */
3
10
  export declare const useSignOutMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "queryKey" | "queryFn">) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, void, TContext>;
@@ -1,7 +1,14 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { signOut } from "firebase/auth";
3
3
  import { SIGN_OUT_MUTATION_KEY } from "./mutation-keys";
4
- import { useAuth } from "../useAuth";
4
+ import { useAuth } from "./useAuth";
5
+ /**
6
+ * Custom hook for handling the sign-out mutation using Firebase authentication.
7
+ * It wraps the useMutation hook to provide a sign-out function with Firebase.
8
+ *
9
+ * @param {Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding "queryKey" and "queryFn".
10
+ * @returns {UseMutationResult<void, FirebaseError, void, TContext>} A mutation object for handling the sign-out process, including methods for mutating and state tracking.
11
+ */
5
12
  export const useSignOutMutation = (options = {}) => {
6
13
  const firebaseAuth = useAuth();
7
14
  return useMutation({
@@ -5,4 +5,11 @@ export type UseUpdateProfileMutationVariables = {
5
5
  displayName?: string;
6
6
  user: User;
7
7
  };
8
+ /**
9
+ * Custom hook to manage the mutation for updating a user's profile.
10
+ * Utilizes Firebase for updating the user's display name.
11
+ *
12
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
13
+ * @returns {UseMutationResult<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>} The result of the mutation operation including statuses, data, and error information.
14
+ */
8
15
  export declare const useUpdateProfileMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>;
@@ -1,6 +1,13 @@
1
1
  import { useMutation } from "@tanstack/react-query";
2
2
  import { updateProfile } from "firebase/auth";
3
3
  import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
4
+ /**
5
+ * Custom hook to manage the mutation for updating a user's profile.
6
+ * Utilizes Firebase for updating the user's display name.
7
+ *
8
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
9
+ * @returns {UseMutationResult<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>} The result of the mutation operation including statuses, data, and error information.
10
+ */
4
11
  export const useUpdateProfileMutation = (options = {}) => {
5
12
  return useMutation({
6
13
  ...options,
@@ -3,11 +3,17 @@ import { Analytics } from "firebase/analytics";
3
3
  import { Firestore } from "firebase/firestore";
4
4
  import { FirebaseApp } from "firebase/app";
5
5
  import { RemoteConfig } from "firebase/remote-config";
6
- export type FirebaseContextValue = {
6
+ type FirebaseContextValue = {
7
7
  auth: Auth;
8
8
  analytics: Analytics;
9
9
  firebase: FirebaseApp;
10
10
  remoteConfig: RemoteConfig;
11
11
  firestore: Firestore;
12
12
  };
13
- export declare const FirebaseContext: import("react").Context<Partial<FirebaseContextValue>>;
13
+ /**
14
+ * FirebaseContext is a shared context across children that provides access to firebase features
15
+ *
16
+ * @internal
17
+ */
18
+ export declare const FirebaseContext: import("react").Context<FirebaseContextValue>;
19
+ export {};
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import { createContext } from "react";
3
+ /**
4
+ * FirebaseContext is a shared context across children that provides access to firebase features
5
+ *
6
+ * @internal
7
+ */
8
+ export const FirebaseContext = createContext({});
@@ -0,0 +1,105 @@
1
+ import React, { PropsWithChildren } from "react";
2
+ import { RemoteConfigSettings } from "firebase/remote-config";
3
+ import { FirebaseOptions } from "firebase/app";
4
+ /**
5
+ * @inline
6
+ */
7
+ export type FirebaseContextProviderFirestoreEmulatorConfig = {
8
+ /**
9
+ * Host to connect to Firebase Firestore Emulator
10
+ */
11
+ host: string;
12
+ /**
13
+ * Port to connect to Firebase Firestore Emulator
14
+ */
15
+ port: number;
16
+ };
17
+ /**
18
+ * @inline
19
+ */
20
+ export type FirebaseContextProviderAuthEmulatorConfig = {
21
+ /**
22
+ * Host to connect to Firebase Auth Emulator
23
+ */
24
+ host: string;
25
+ };
26
+ /**
27
+ * @inline
28
+ */
29
+ export type FirebaseContextProviderEmulators = {
30
+ /**
31
+ * Defines configuration for Firebase Firestore emulator. Optional.
32
+ */
33
+ firestore?: FirebaseContextProviderFirestoreEmulatorConfig;
34
+ /**
35
+ * Defines configuration for Firebase Auth emulator. Optional
36
+ */
37
+ auth?: FirebaseContextProviderAuthEmulatorConfig;
38
+ };
39
+ /**
40
+ * @inline
41
+ */
42
+ export type FirebaseContextProviderProps = PropsWithChildren & {
43
+ /**
44
+ * Defines configuration for firebase emulators
45
+ */
46
+ emulators?: FirebaseContextProviderEmulators;
47
+ /**
48
+ * Configuration options for Firebase initialization. {@link https://firebase.google.com/docs/web/setup#config-object | Learn about the Firebase config object}
49
+ */
50
+ options: FirebaseOptions;
51
+ /**
52
+ * Flag indicating whether Firebase Auth should be enabled.
53
+ */
54
+ authEnabled?: boolean;
55
+ /**
56
+ * Flag indicating whether Firebase Analytics should be enabled.
57
+ * @defaultValue `true`
58
+ */
59
+ analyticsEnabled?: boolean;
60
+ /**
61
+ * Flag indicating whether Firebase Firestore should be enabled.
62
+ * @defaultValue `true`
63
+ */
64
+ firestoreEnabled?: boolean;
65
+ /**
66
+ * Configuration options for Firebase Remote Config Settings. {@link https://firebase.google.com/docs/reference/js/remote-config.remoteconfigsettings | Learn about the Firebase Remote COnfig Settings object}
67
+ * @defaultValue `true`
68
+ */
69
+ remoteConfigSettings?: RemoteConfigSettings;
70
+ /**
71
+ * Configuration options for Firebase Remote Config Defaults.
72
+ */
73
+ remoteConfigDefaults?: {
74
+ [key: string]: string | number | boolean;
75
+ };
76
+ /**
77
+ * Flag indicating whether Firebase Remote Config should be enabled.
78
+ * @defaultValue `true`
79
+ */
80
+ remoteConfigEnabled?: boolean;
81
+ };
82
+ /**
83
+ * FirebaseContextProvider component configures and provides Firebase services to its children.
84
+ * Initializes Firebase app and enables optional Firebase services such as Firestore, Auth, Analytics,
85
+ * and Remote Config based on the provided configuration and parameters.
86
+ *
87
+ * @group Component
88
+ *
89
+ * @param {FirebaseContextProviderProps} props
90
+ *
91
+ * @returns {FirebaseContextProvider<FirebaseContextProviderProps>}
92
+ *
93
+ * @example
94
+ * ```jsx
95
+ * const firebaseConfig = {};
96
+ * export const App = () => {
97
+ * return (
98
+ * <FirebaseContextProvider options={firebaseConfig}>
99
+ * <ChildComponent />
100
+ * </FirebaseContextProvider>
101
+ * );
102
+ * };
103
+ * ```
104
+ */
105
+ export declare const FirebaseContextProvider: React.FC<FirebaseContextProviderProps>;
@@ -5,6 +5,29 @@ import { getAnalytics } from "firebase/analytics";
5
5
  import { getRemoteConfig } from "firebase/remote-config";
6
6
  import { connectFirestoreEmulator, getFirestore } from "firebase/firestore";
7
7
  import { initializeApp } from "firebase/app";
8
+ /**
9
+ * FirebaseContextProvider component configures and provides Firebase services to its children.
10
+ * Initializes Firebase app and enables optional Firebase services such as Firestore, Auth, Analytics,
11
+ * and Remote Config based on the provided configuration and parameters.
12
+ *
13
+ * @group Component
14
+ *
15
+ * @param {FirebaseContextProviderProps} props
16
+ *
17
+ * @returns {FirebaseContextProvider<FirebaseContextProviderProps>}
18
+ *
19
+ * @example
20
+ * ```jsx
21
+ * const firebaseConfig = {};
22
+ * export const App = () => {
23
+ * return (
24
+ * <FirebaseContextProvider options={firebaseConfig}>
25
+ * <ChildComponent />
26
+ * </FirebaseContextProvider>
27
+ * );
28
+ * };
29
+ * ```
30
+ */
8
31
  export const FirebaseContextProvider = ({ emulators, options, children, authEnabled = true, firestoreEnabled = true, analyticsEnabled = true, remoteConfigEnabled = true, remoteConfigSettings, remoteConfigDefaults = {} }) => {
9
32
  const firebase = useMemo(() => {
10
33
  return initializeApp(options);
@@ -42,5 +65,5 @@ export const FirebaseContextProvider = ({ emulators, options, children, authEnab
42
65
  }
43
66
  return { firebase, ...value };
44
67
  }, [firebase]);
45
- return React.createElement(FirebaseContext.Provider, { value: contextValue }, children);
68
+ return (React.createElement(FirebaseContext.Provider, { value: contextValue }, children));
46
69
  };
@@ -0,0 +1 @@
1
+ export * from "./FirebaseContextProvider";
@@ -0,0 +1 @@
1
+ export * from "./FirebaseContextProvider";
@@ -1,3 +1,4 @@
1
+ export * from "./useFirestore";
1
2
  export * from "./useAddDocMutation";
2
3
  export * from "./useBatchWrite";
3
4
  export * from "./useCollectionReference";
@@ -1,3 +1,4 @@
1
+ export * from "./useFirestore";
1
2
  export * from "./useAddDocMutation";
2
3
  export * from "./useBatchWrite";
3
4
  export * from "./useCollectionReference";