react-query-firebase 1.0.2 → 1.0.4

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 (150) 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 +2 -0
  9. package/dist/src/auth/index.js +2 -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 +12 -0
  19. package/dist/src/auth/useIdToken.js +36 -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 +2 -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/firestore/useUpdateDocMutation copy.ts +0 -51
  146. package/src/useAnalytics.ts +0 -8
  147. package/src/useAuth.ts +0 -8
  148. package/src/useFirebase.ts +0 -8
  149. package/src/useFirestore.ts +0 -7
  150. package/src/useRemoteConfig.ts +0 -7
@@ -1,4 +1,18 @@
1
1
  import { DocumentData } from "firebase/firestore";
2
2
  import { GetDocSnapOptions } from "./getDocSnap";
3
3
  export type GetDocDataOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData> = GetDocSnapOptions<AppModelType, DbModelType>;
4
+ /**
5
+ * Asynchronously retrieves document data from a specified database and reference.
6
+ * Utilizes the helper function `getDocSnap` to fetch the document snapshot and
7
+ * checks if the document exists before returning its data.
8
+ *
9
+ * @param {Object} options - The options for fetching document data.
10
+ * @param {FirebaseFirestore} options.db - The Firestore database instance.
11
+ * @param {DocumentReference=} options.reference - The document reference. This is an optional parameter.
12
+ * @param {string=} options.path - The path to the document in the database. This is an optional parameter.
13
+ * @param {Array<string>=} options.pathSegments - The path segments for the document's path. This is an optional parameter.
14
+ *
15
+ * @returns {Promise<AppModelType | null>} Returns a promise that resolves to the document data if it exists,
16
+ * or null if the document does not exist.
17
+ */
4
18
  export declare const getDocData: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ db, reference, path, pathSegments }: GetDocDataOptions<AppModelType, DbModelType>) => Promise<AppModelType | null>;
@@ -1,4 +1,18 @@
1
1
  import { getDocSnap } from "./getDocSnap";
2
+ /**
3
+ * Asynchronously retrieves document data from a specified database and reference.
4
+ * Utilizes the helper function `getDocSnap` to fetch the document snapshot and
5
+ * checks if the document exists before returning its data.
6
+ *
7
+ * @param {Object} options - The options for fetching document data.
8
+ * @param {FirebaseFirestore} options.db - The Firestore database instance.
9
+ * @param {DocumentReference=} options.reference - The document reference. This is an optional parameter.
10
+ * @param {string=} options.path - The path to the document in the database. This is an optional parameter.
11
+ * @param {Array<string>=} options.pathSegments - The path segments for the document's path. This is an optional parameter.
12
+ *
13
+ * @returns {Promise<AppModelType | null>} Returns a promise that resolves to the document data if it exists,
14
+ * or null if the document does not exist.
15
+ */
2
16
  export const getDocData = async ({ db, reference, path, pathSegments }) => {
3
17
  const docSnap = await getDocSnap({ db, reference, path, pathSegments });
4
18
  if (docSnap && docSnap.exists()) {
@@ -5,4 +5,15 @@ export type GetDocRefOptions<AppModelType extends DocumentData = DocumentData, D
5
5
  path?: string;
6
6
  pathSegments?: string[];
7
7
  };
8
+ /**
9
+ * Retrieves a document reference based on provided database options.
10
+ * Either `reference` or `path` must be provided, not both.
11
+ *
12
+ * @param {Object} options - The options for getting a document reference.
13
+ * @param {Firestore} options.db - The Firestore database instance.
14
+ * @param {DocumentReference | CollectionReference | null} [options.reference] - Reference to a document or collection.
15
+ * @param {string | null} [options.path] - Path to the document.
16
+ * @param {string[] | null} [options.pathSegments] - Additional path segments if any.
17
+ * @returns {DocumentReference<AppModelType, DbModelType>} The document reference.
18
+ */
8
19
  export declare const getDocRef: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ db, reference, path, pathSegments }: GetDocRefOptions<AppModelType, DbModelType>) => Promise<DocumentReference<AppModelType, DbModelType>>;
@@ -1,4 +1,15 @@
1
1
  import { doc } from "firebase/firestore";
2
+ /**
3
+ * Retrieves a document reference based on provided database options.
4
+ * Either `reference` or `path` must be provided, not both.
5
+ *
6
+ * @param {Object} options - The options for getting a document reference.
7
+ * @param {Firestore} options.db - The Firestore database instance.
8
+ * @param {DocumentReference | CollectionReference | null} [options.reference] - Reference to a document or collection.
9
+ * @param {string | null} [options.path] - Path to the document.
10
+ * @param {string[] | null} [options.pathSegments] - Additional path segments if any.
11
+ * @returns {DocumentReference<AppModelType, DbModelType>} The document reference.
12
+ */
2
13
  export const getDocRef = async ({ db, reference, path, pathSegments }) => {
3
14
  if (!reference && !path) {
4
15
  throw new Error("One of the options must be provided: path or reference.");
@@ -1,4 +1,20 @@
1
1
  import { DocumentData } from "firebase/firestore";
2
2
  import { GetDocRefOptions } from "./getDocRef";
3
3
  export type GetDocSnapOptions<AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData> = GetDocRefOptions<AppModelType, DbModelType>;
4
+ /**
5
+ * Asynchronously retrieves a document snapshot from Firestore using a specified document reference
6
+ * or path information. This function handles getting the appropriate document reference based on
7
+ * the parameters provided, and then fetches the document data from Firestore.
8
+ *
9
+ * @param {GetDocSnapOptions<AppModelType, DbModelType>} options - An object containing options
10
+ * for retrieving the document
11
+ * snapshot.
12
+ * @param {DocumentData} options.db - The Firestore database instance to perform the operation on.
13
+ * @param {string} options.reference - A string representing a direct Firestore document reference.
14
+ * @param {string} options.path - A Firestore path string leading to the document.
15
+ * @param {string[]} options.pathSegments - An array of path segments to build the Firestore path.
16
+ * @returns {Promise<DocumentData | null>} A promise that resolves to the document data if the
17
+ * document exists, or `null` if the document does not exist
18
+ * or if the reference could not be obtained.
19
+ */
4
20
  export declare const getDocSnap: <AppModelType extends DocumentData = DocumentData, DbModelType extends DocumentData = DocumentData>({ db, reference, path, pathSegments }: GetDocSnapOptions<AppModelType, DbModelType>) => Promise<import("@firebase/firestore").DocumentSnapshot<AppModelType, DbModelType> | null>;
@@ -1,5 +1,21 @@
1
1
  import { getDoc as firestoreGetDoc } from "firebase/firestore";
2
2
  import { getDocRef } from "./getDocRef";
3
+ /**
4
+ * Asynchronously retrieves a document snapshot from Firestore using a specified document reference
5
+ * or path information. This function handles getting the appropriate document reference based on
6
+ * the parameters provided, and then fetches the document data from Firestore.
7
+ *
8
+ * @param {GetDocSnapOptions<AppModelType, DbModelType>} options - An object containing options
9
+ * for retrieving the document
10
+ * snapshot.
11
+ * @param {DocumentData} options.db - The Firestore database instance to perform the operation on.
12
+ * @param {string} options.reference - A string representing a direct Firestore document reference.
13
+ * @param {string} options.path - A Firestore path string leading to the document.
14
+ * @param {string[]} options.pathSegments - An array of path segments to build the Firestore path.
15
+ * @returns {Promise<DocumentData | null>} A promise that resolves to the document data if the
16
+ * document exists, or `null` if the document does not exist
17
+ * or if the reference could not be obtained.
18
+ */
3
19
  export const getDocSnap = async ({ db, reference, path, pathSegments }) => {
4
20
  const docRef = await getDocRef({ db, reference, path, pathSegments });
5
21
  if (docRef) {
@@ -1,10 +1,5 @@
1
- export * from "./useAuth";
2
- export * from "./useFirebase";
3
- export * from "./useFirestore";
4
- export * from "./FirebaseContextProvider";
5
- export * from "./useAnalytics";
6
- export * from "./useRemoteConfig";
7
1
  export * from "./analytics";
8
2
  export * from "./auth";
3
+ export * from "./context";
9
4
  export * from "./firestore";
10
5
  export * from "./remoteConfig";
package/dist/src/index.js CHANGED
@@ -1,10 +1,5 @@
1
- export * from "./useAuth";
2
- export * from "./useFirebase";
3
- export * from "./useFirestore";
4
- export * from "./FirebaseContextProvider";
5
- export * from "./useAnalytics";
6
- export * from "./useRemoteConfig";
7
1
  export * from "./analytics";
8
2
  export * from "./auth";
3
+ export * from "./context";
9
4
  export * from "./firestore";
10
5
  export * from "./remoteConfig";
@@ -1,2 +1,3 @@
1
1
  export * from "./useFetchAndActivate";
2
2
  export * from "./useGetValue";
3
+ export * from "./useRemoteConfig";
@@ -1,2 +1,3 @@
1
1
  export * from "./useFetchAndActivate";
2
2
  export * from "./useGetValue";
3
+ export * from "./useRemoteConfig";
@@ -1,3 +1,10 @@
1
+ /**
2
+ * Custom hook to fetch and activate remote configuration settings.
3
+ * Initializes remote configuration, fetches, activates it, and tracks the fetch status.
4
+ * @returns {Object} An object containing:
5
+ * - {Function} fetchAndActivate - Callback function to fetch and activate remote configuration.
6
+ * - {Boolean} isFetched - Boolean representing whether the fetch-and-activate process completed.
7
+ */
1
8
  export declare const useFetchAndActivate: () => {
2
9
  fetchAndActivate: () => Promise<void>;
3
10
  isFetched: boolean;
@@ -1,14 +1,23 @@
1
- import { useRemoteConfig } from "../useRemoteConfig";
1
+ import { useRemoteConfig } from "./useRemoteConfig";
2
2
  import { ensureInitialized, fetchAndActivate } from "firebase/remote-config";
3
3
  import { useCallback, useMemo, useState } from "react";
4
+ /**
5
+ * Custom hook to fetch and activate remote configuration settings.
6
+ * Initializes remote configuration, fetches, activates it, and tracks the fetch status.
7
+ * @returns {Object} An object containing:
8
+ * - {Function} fetchAndActivate - Callback function to fetch and activate remote configuration.
9
+ * - {Boolean} isFetched - Boolean representing whether the fetch-and-activate process completed.
10
+ */
4
11
  export const useFetchAndActivate = () => {
5
12
  const remoteConfig = useRemoteConfig();
6
13
  const [isFetched, setIsFetched] = useState(false);
7
14
  const fetchAndActivateCallback = useCallback(async () => {
8
15
  try {
9
- await ensureInitialized(remoteConfig);
10
- await fetchAndActivate(remoteConfig);
11
- setIsFetched(true);
16
+ if (remoteConfig) {
17
+ await ensureInitialized(remoteConfig);
18
+ await fetchAndActivate(remoteConfig);
19
+ setIsFetched(true);
20
+ }
12
21
  }
13
22
  catch (e) {
14
23
  setIsFetched(true);
@@ -1 +1,7 @@
1
+ /**
2
+ * Custom hook to retrieve a value associated with a specified key from remote configuration.
3
+ * Utilizes memoization to optimize performance by recalculating the result only if dependencies change.
4
+ * @param {string} key - The key for which the corresponding value is to be fetched from the remote configuration.
5
+ * @returns {any | null} The value associated with the specified key if available, otherwise null.
6
+ */
1
7
  export declare const useGetValue: (key: string) => import("@firebase/remote-config").Value | null;
@@ -1,6 +1,12 @@
1
1
  import { getValue } from "firebase/remote-config";
2
- import { useRemoteConfig } from "../useRemoteConfig";
2
+ import { useRemoteConfig } from "./useRemoteConfig";
3
3
  import { useMemo } from "react";
4
+ /**
5
+ * Custom hook to retrieve a value associated with a specified key from remote configuration.
6
+ * Utilizes memoization to optimize performance by recalculating the result only if dependencies change.
7
+ * @param {string} key - The key for which the corresponding value is to be fetched from the remote configuration.
8
+ * @returns {any | null} The value associated with the specified key if available, otherwise null.
9
+ */
4
10
  export const useGetValue = (key) => {
5
11
  const remoteConfig = useRemoteConfig();
6
12
  return useMemo(() => {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Hook to access the Firebase Remote Config instance from the context.
3
+ * @returns {RemoteConfig} The remoteConfig object from the Firebase context.
4
+ */
5
+ export declare const useRemoteConfig: () => import("@firebase/remote-config").RemoteConfig;
@@ -0,0 +1,10 @@
1
+ import { useContext } from "react";
2
+ import { FirebaseContext } from "../context/FirebaseContext";
3
+ /**
4
+ * Hook to access the Firebase Remote Config instance from the context.
5
+ * @returns {RemoteConfig} The remoteConfig object from the Firebase context.
6
+ */
7
+ export const useRemoteConfig = () => {
8
+ const { remoteConfig } = useContext(FirebaseContext);
9
+ return remoteConfig;
10
+ };
package/package.json CHANGED
@@ -8,8 +8,8 @@
8
8
  "firebase": "^11.0.1"
9
9
  },
10
10
  "peerDependencies": {
11
- "react": "^19.0.0",
12
- "@tanstack/react-query": "^5.62.15"
11
+ "@tanstack/react-query": "^5.62.15",
12
+ "react": "^19.0.0"
13
13
  },
14
14
  "publishConfig": {
15
15
  "access": "public"
@@ -22,7 +22,11 @@
22
22
  "lint-staged": "^15.1.0",
23
23
  "prettier": "^3.0.3",
24
24
  "react": "^19.0.0",
25
- "typescript": "^5.2.2"
25
+ "typedoc": "^0.27.6",
26
+ "typedoc-plugin-markdown": "^4.4.1",
27
+ "typedoc-vitepress-theme": "^1.1.2",
28
+ "typescript": "^5.2.2",
29
+ "vitepress": "^1.5.0"
26
30
  },
27
31
  "homepage": "https://github.com/vpishuk/react-query-firebase",
28
32
  "keywords": [
@@ -51,7 +55,11 @@
51
55
  "lint": "eslint",
52
56
  "lint:fix": "eslint --fix",
53
57
  "lint:staged": "lint-staged",
54
- "prepare": "husky"
58
+ "prepare": "husky",
59
+ "docs:generate": "rm -rf docs/ && typedoc --plugin typedoc-plugin-markdown --plugin typedoc-vitepress-theme",
60
+ "docs:dev": "vitepress dev",
61
+ "docs:build": "vitepress build",
62
+ "docs:preview": "vitepress preview"
55
63
  },
56
- "version": "1.0.2"
64
+ "version": "1.0.4"
57
65
  }
@@ -1 +1,2 @@
1
1
  export * from "./useLogEvent";
2
+ export * from "./useAnalytics";
@@ -0,0 +1,12 @@
1
+ import { useContext } from "react";
2
+
3
+ import { FirebaseContext } from "../context/FirebaseContext";
4
+
5
+ /**
6
+ * Hook to access Firebase analytics from the Firebase context.
7
+ * @returns {any} The analytics object from the Firebase context.
8
+ */
9
+ export const useAnalytics = () => {
10
+ const { analytics } = useContext(FirebaseContext);
11
+ return analytics;
12
+ };
@@ -1,5 +1,5 @@
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
4
 
5
5
  type UseLogEventOptions = {
@@ -9,6 +9,13 @@ type UseLogEventOptions = {
9
9
  };
10
10
  };
11
11
 
12
+ /**
13
+ * Custom hook to create a log event function that logs an analytics event with specified parameters.
14
+ * @param {Object} options - The options for the log event.
15
+ * @param {string} options.eventName - The name of the event to be logged.
16
+ * @param {Object} options.eventParams - The parameters to be sent along with the event.
17
+ * @returns {Object} An object containing a `logEvent` function that, when called, logs the event.
18
+ */
12
19
  export const useLogEvent = ({ eventName, eventParams }: UseLogEventOptions) => {
13
20
  const analytics = useAnalytics();
14
21
 
package/src/auth/index.ts CHANGED
@@ -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";
@@ -7,5 +8,6 @@ export * from "./useAuthStateReady";
7
8
  export * from "./useSignInWitRedirectMutation";
8
9
  export * from "./useUpdateProfileMutation";
9
10
  export * from "./useSignOutMutation";
11
+ export * from "./useIdToken";
10
12
  export * from "./useReauthenticateWitCredentialMutation";
11
13
  export * from "./useReauthenticateWitRedirectMutation";
@@ -0,0 +1,12 @@
1
+ import { useContext } from "react";
2
+
3
+ import { FirebaseContext } from "../context/FirebaseContext";
4
+
5
+ /**
6
+ * Custom hook to retrieve the authentication object from the Firebase context.
7
+ * @returns {Auth} The authentication object from the Firebase context.
8
+ */
9
+ export const useAuth = () => {
10
+ const { auth } = useContext(FirebaseContext);
11
+ return auth;
12
+ };
@@ -1,6 +1,11 @@
1
- import { useAuth } from "../useAuth";
1
+ import { useAuth } from "./useAuth";
2
2
  import { useCallback, useEffect, useState } from "react";
3
3
 
4
+ /**
5
+ * A custom hook that determines if the Firebase authentication state is ready.
6
+ * It uses Firebase authentication to check if the auth state is ready and updates the state accordingly.
7
+ * @returns {boolean} Indicates whether the authentication state is ready.
8
+ */
4
9
  export const useAuthStateReady = () => {
5
10
  const firebaseAuth = useAuth();
6
11
 
@@ -1,6 +1,6 @@
1
1
  import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
2
  import { createUserWithEmailAndPassword, UserCredential } from "firebase/auth";
3
- import { useAuth } from "../useAuth";
3
+ import { useAuth } from "./useAuth";
4
4
  import { FirebaseError } from "firebase/app";
5
5
  import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
6
6
 
@@ -9,6 +9,13 @@ export type UseCreateUserWitEmailAndPasswordMutationVariables = {
9
9
  password: string;
10
10
  };
11
11
 
12
+ /**
13
+ * Custom hook to initiate a user creation process using email and password with Firebase authentication.
14
+ * This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
15
+ *
16
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
17
+ * @returns {UseMutationResult<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
18
+ */
12
19
  export const useCreateUserWitEmailAndPasswordMutation = <TContext = unknown>(
13
20
  options: Omit<
14
21
  UseMutationOptions<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>,
@@ -1,6 +1,11 @@
1
- import { useAuth } from "../useAuth";
1
+ import { useAuth } from "./useAuth";
2
2
  import { useEffect, useState } from "react";
3
3
 
4
+ /**
5
+ * Hook that provides the current authenticated user from Firebase Auth.
6
+ * It listens for changes in the authentication state and updates the user accordingly.
7
+ * @returns {Object|null} The current authenticated user object or null if no user is authenticated.
8
+ */
4
9
  export const useCurrentUser = () => {
5
10
  const firebaseAuth = useAuth();
6
11
 
@@ -1,6 +1,14 @@
1
1
  import { useCallback, useEffect, useState } from "react";
2
2
  import { useCurrentUser } from "./useCurrentUser";
3
3
 
4
+ /**
5
+ * Custom hook to manage an ID token for the current user.
6
+ * This hook provides an `idToken` value and a `refresh` function to manually refresh the token.
7
+ *
8
+ * @returns {Object} An object containing:
9
+ * @returns {string} idToken - The current ID token for the user.
10
+ * @returns {Function} refresh - A function to refresh the ID token.
11
+ */
4
12
  export const useIdToken = () => {
5
13
  const currentUser = useCurrentUser();
6
14
  const [idToken, setIdToken] = useState("");
@@ -8,6 +8,14 @@ export type UseReauthenticateWitCredentialMutationVariables = {
8
8
  user: User;
9
9
  };
10
10
 
11
+ /**
12
+ * Custom hook to create a mutation for re-authenticating a user with a given credential.
13
+ * This hook utilizes useMutation from React Query to manage the asynchronous re-authentication
14
+ * process with Firebase credentials. It omits the default "mutationKey" and "mutationFn" options.
15
+ *
16
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional mutation options excluding "mutationKey" and "mutationFn".
17
+ * @returns {UseMutationResult<UserCredential, FirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>} A useMutation result object managing the loading, error, and result state of the re-authentication mutation.
18
+ */
11
19
  export const useReauthenticateWitCredentialMutation = <TContext = unknown>(
12
20
  options: Omit<
13
21
  UseMutationOptions<UserCredential, FirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>,
@@ -10,6 +10,14 @@ export type UseReauthenticateWitRedirectMutationVariables = {
10
10
  user: User;
11
11
  };
12
12
 
13
+ /**
14
+ * Custom hook that provides a mutation to reauthenticate a user with a given authentication provider using redirection.
15
+ * This hook uses the `useMutation` hook from the React Query library to handle async mutation logic.
16
+ *
17
+ * @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.
18
+ * @template TContext - The type of any additional context you wish to pass to the mutation.
19
+ * @returns {UseMutationResult<void, FirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>} A mutation result object containing methods and state of the mutation.
20
+ */
13
21
  export const useReauthenticateWitRedirectMutation = <TContext = unknown>(
14
22
  options: Omit<
15
23
  UseMutationOptions<void, FirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>,
@@ -8,6 +8,12 @@ export type UseSendEmailVerificationMutationVariables = {
8
8
  user: User;
9
9
  };
10
10
 
11
+ /**
12
+ * A custom hook to create a mutation for sending an email verification to a user using Firebase.
13
+ * This uses the `useMutation` hook from a query library and wraps it with specific configuration options.
14
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding `queryKey` and `queryFn`.
15
+ * @returns {UseMutationResult<void, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>} An object containing mutation state and functions for managing the mutation lifecycle.
16
+ */
11
17
  export const useSendEmailVerificationMutation = <TContext = unknown>(
12
18
  options: Omit<
13
19
  UseMutationOptions<void, FirebaseError, UseSendEmailVerificationMutationVariables, TContext>,
@@ -1,7 +1,7 @@
1
1
  import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
2
  import { signInWithEmailAndPassword, UserCredential } from "firebase/auth";
3
3
 
4
- import { useAuth } from "../useAuth";
4
+ import { useAuth } from "./useAuth";
5
5
  import { SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
6
6
  import { FirebaseError } from "firebase/app";
7
7
 
@@ -10,6 +10,13 @@ export type UseSignInWitEmailAndPasswordMutationVariables = {
10
10
  password: string;
11
11
  };
12
12
 
13
+ /**
14
+ * Custom hook to perform a sign-in operation using email and password with Firebase Authentication.
15
+ * It utilizes the `useMutation` hook to manage the asynchronous operation and its state.
16
+ *
17
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>, 'mutationKey' | 'mutationFn'>} options - Options to configure the mutation, excluding 'mutationKey' and 'mutationFn'.
18
+ * @returns {MutationResult} A mutation object containing the result of the sign-in process and helper functions.
19
+ */
13
20
  export const useSignInWitEmailAndPasswordMutation = <TContext = unknown>(
14
21
  options: Omit<
15
22
  UseMutationOptions<UserCredential, FirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>,
@@ -1,7 +1,7 @@
1
1
  import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
2
  import { signInWithRedirect, AuthProvider, PopupRedirectResolver } from "firebase/auth";
3
3
 
4
- import { useAuth } from "../useAuth";
4
+ import { useAuth } from "./useAuth";
5
5
  import { SIGN_IN_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
6
6
  import { FirebaseError } from "firebase/app";
7
7
 
@@ -10,6 +10,12 @@ export type UseSignInWitRedirectMutationVariables = {
10
10
  popupRedirectResolver?: PopupRedirectResolver;
11
11
  };
12
12
 
13
+ /**
14
+ * Custom hook for handling Firebase authentication using sign-in with redirect functionality.
15
+ * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
16
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
17
+ * @returns {UseMutationResult<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
18
+ */
13
19
  export const useSignInWitRedirectMutation = <TContext = unknown>(
14
20
  options: Omit<
15
21
  UseMutationOptions<void, FirebaseError, UseSignInWitRedirectMutationVariables, TContext>,
@@ -3,8 +3,15 @@ import { signOut } from "firebase/auth";
3
3
 
4
4
  import { SIGN_OUT_MUTATION_KEY } from "./mutation-keys";
5
5
  import { FirebaseError } from "firebase/app";
6
- import { useAuth } from "../useAuth";
6
+ import { useAuth } from "./useAuth";
7
7
 
8
+ /**
9
+ * Custom hook for handling the sign-out mutation using Firebase authentication.
10
+ * It wraps the useMutation hook to provide a sign-out function with Firebase.
11
+ *
12
+ * @param {Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding "queryKey" and "queryFn".
13
+ * @returns {UseMutationResult<void, FirebaseError, void, TContext>} A mutation object for handling the sign-out process, including methods for mutating and state tracking.
14
+ */
8
15
  export const useSignOutMutation = <TContext = unknown>(
9
16
  options: Omit<UseMutationOptions<void, FirebaseError, void, TContext>, "queryKey" | "queryFn"> = {}
10
17
  ) => {
@@ -8,6 +8,13 @@ export type UseUpdateProfileMutationVariables = {
8
8
  user: User;
9
9
  };
10
10
 
11
+ /**
12
+ * Custom hook to manage the mutation for updating a user's profile.
13
+ * Utilizes Firebase for updating the user's display name.
14
+ *
15
+ * @param {Omit<UseMutationOptions<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
16
+ * @returns {UseMutationResult<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>} The result of the mutation operation including statuses, data, and error information.
17
+ */
11
18
  export const useUpdateProfileMutation = <TContext = unknown>(
12
19
  options: Omit<
13
20
  UseMutationOptions<void, FirebaseError, UseUpdateProfileMutationVariables, TContext>,
@@ -1,4 +1,5 @@
1
1
  "use client";
2
+
2
3
  import { createContext } from "react";
3
4
 
4
5
  import { Auth } from "firebase/auth";
@@ -7,7 +8,7 @@ import { Firestore } from "firebase/firestore";
7
8
  import { FirebaseApp } from "firebase/app";
8
9
  import { RemoteConfig } from "firebase/remote-config";
9
10
 
10
- export type FirebaseContextValue = {
11
+ type FirebaseContextValue = {
11
12
  auth: Auth;
12
13
  analytics: Analytics;
13
14
  firebase: FirebaseApp;
@@ -15,4 +16,10 @@ export type FirebaseContextValue = {
15
16
  firestore: Firestore;
16
17
  };
17
18
 
18
- export const FirebaseContext = createContext<Partial<FirebaseContextValue>>({});
19
+ /**
20
+ * FirebaseContext is a shared context across children that provides access to firebase features
21
+ *
22
+ * @internal
23
+ */
24
+
25
+ export const FirebaseContext = createContext<FirebaseContextValue>({} as FirebaseContextValue);