react-query-firebase 2.0.0-rc6 → 2.0.0-rc8

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 (274) hide show
  1. package/package.json +16 -13
  2. package/web/analytics/index.d.ts +3 -0
  3. package/web/analytics/index.js +3 -0
  4. package/web/analytics/index.ts +3 -0
  5. package/web/analytics/useAnalytics.d.ts +5 -0
  6. package/web/analytics/useAnalytics.js +10 -0
  7. package/web/analytics/useAnalytics.ts +12 -0
  8. package/web/analytics/useLogEvent.d.ts +17 -0
  9. package/web/analytics/useLogEvent.js +21 -0
  10. package/web/analytics/useLogEvent.ts +34 -0
  11. package/web/analytics/useSetAnalyticsCollectionEnabled.d.ts +10 -0
  12. package/web/analytics/useSetAnalyticsCollectionEnabled.js +16 -0
  13. package/web/analytics/useSetAnalyticsCollectionEnabled.ts +22 -0
  14. package/web/auth/index.d.ts +13 -0
  15. package/web/auth/index.js +13 -0
  16. package/web/auth/index.ts +13 -0
  17. package/web/auth/mutation-keys.d.ts +7 -0
  18. package/web/auth/mutation-keys.js +19 -0
  19. package/web/auth/mutation-keys.ts +19 -0
  20. package/web/auth/useAuth.d.ts +5 -0
  21. package/web/auth/useAuth.js +10 -0
  22. package/web/auth/useAuth.ts +12 -0
  23. package/web/auth/useAuthStateReady.d.ts +6 -0
  24. package/web/auth/useAuthStateReady.js +19 -0
  25. package/web/auth/useAuthStateReady.ts +24 -0
  26. package/web/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +15 -0
  27. package/web/auth/useCreateUserWitEmailAndPasswordMutation.js +19 -0
  28. package/web/auth/useCreateUserWitEmailAndPasswordMutation.ts +33 -0
  29. package/web/auth/useCurrentUser.d.ts +6 -0
  30. package/web/auth/useCurrentUser.js +20 -0
  31. package/web/auth/useCurrentUser.ts +24 -0
  32. package/web/auth/useIdToken.d.ts +30 -0
  33. package/web/auth/useIdToken.js +66 -0
  34. package/web/auth/useIdToken.ts +83 -0
  35. package/web/auth/useReauthenticateWitCredentialMutation.d.ts +16 -0
  36. package/web/auth/useReauthenticateWitCredentialMutation.js +18 -0
  37. package/web/auth/useReauthenticateWitCredentialMutation.ts +31 -0
  38. package/web/auth/useReauthenticateWitRedirectMutation.d.ts +17 -0
  39. package/web/auth/useReauthenticateWitRedirectMutation.js +18 -0
  40. package/web/auth/useReauthenticateWitRedirectMutation.ts +37 -0
  41. package/web/auth/useSendEmailVerificationMutation.d.ts +13 -0
  42. package/web/auth/useSendEmailVerificationMutation.js +16 -0
  43. package/web/auth/useSendEmailVerificationMutation.ts +28 -0
  44. package/web/auth/useSignInWitEmailAndPasswordMutation.d.ts +15 -0
  45. package/web/auth/useSignInWitEmailAndPasswordMutation.js +19 -0
  46. package/web/auth/useSignInWitEmailAndPasswordMutation.ts +34 -0
  47. package/web/auth/useSignInWitRedirectMutation.d.ts +14 -0
  48. package/web/auth/useSignInWitRedirectMutation.js +18 -0
  49. package/web/auth/useSignInWitRedirectMutation.ts +33 -0
  50. package/web/auth/useSignOutMutation.d.ts +10 -0
  51. package/web/auth/useSignOutMutation.js +19 -0
  52. package/web/auth/useSignOutMutation.ts +25 -0
  53. package/web/auth/useUpdateProfileMutation.d.ts +15 -0
  54. package/web/auth/useUpdateProfileMutation.js +17 -0
  55. package/web/auth/useUpdateProfileMutation.ts +30 -0
  56. package/web/context/FirebaseContext.d.ts +19 -0
  57. package/web/context/FirebaseContext.js +8 -0
  58. package/web/context/FirebaseContext.ts +25 -0
  59. package/web/context/FirebaseContextProvider.d.ts +127 -0
  60. package/web/context/FirebaseContextProvider.js +100 -0
  61. package/web/context/FirebaseContextProvider.tsx +231 -0
  62. package/web/context/index.d.ts +1 -0
  63. package/web/context/index.js +1 -0
  64. package/web/context/index.ts +1 -0
  65. package/web/firestore/index.d.ts +16 -0
  66. package/web/firestore/index.js +16 -0
  67. package/web/firestore/index.ts +16 -0
  68. package/web/firestore/useAddDocMutation.d.ts +23 -0
  69. package/web/firestore/useAddDocMutation.js +26 -0
  70. package/web/firestore/useAddDocMutation.ts +62 -0
  71. package/web/firestore/useBatchWrite.d.ts +15 -0
  72. package/web/firestore/useBatchWrite.js +21 -0
  73. package/web/firestore/useBatchWrite.ts +31 -0
  74. package/web/firestore/useCollectionReference.d.ts +18 -0
  75. package/web/firestore/useCollectionReference.js +24 -0
  76. package/web/firestore/useCollectionReference.ts +37 -0
  77. package/web/firestore/useCompositeFilter.d.ts +31 -0
  78. package/web/firestore/useCompositeFilter.js +45 -0
  79. package/web/firestore/useCompositeFilter.ts +92 -0
  80. package/web/firestore/useCountQuery.d.ts +23 -0
  81. package/web/firestore/useCountQuery.js +30 -0
  82. package/web/firestore/useCountQuery.ts +65 -0
  83. package/web/firestore/useDeleteDocMutation.d.ts +18 -0
  84. package/web/firestore/useDeleteDocMutation.js +23 -0
  85. package/web/firestore/useDeleteDocMutation.ts +47 -0
  86. package/web/firestore/useDocReference.d.ts +19 -0
  87. package/web/firestore/useDocReference.js +45 -0
  88. package/web/firestore/useDocReference.ts +68 -0
  89. package/web/firestore/useDocReferences.d.ts +23 -0
  90. package/web/firestore/useDocReferences.js +31 -0
  91. package/web/firestore/useDocReferences.ts +44 -0
  92. package/web/firestore/useFirestore.d.ts +7 -0
  93. package/web/firestore/useFirestore.js +12 -0
  94. package/web/firestore/useFirestore.ts +13 -0
  95. package/web/firestore/useGetDocData.d.ts +18 -0
  96. package/web/firestore/useGetDocData.js +18 -0
  97. package/web/firestore/useGetDocData.ts +41 -0
  98. package/web/firestore/useGetRealtimeDocData.d.ts +57 -0
  99. package/web/firestore/useGetRealtimeDocData.js +56 -0
  100. package/web/firestore/useGetRealtimeDocData.ts +104 -0
  101. package/web/firestore/useInfiniteQuery.d.ts +18 -0
  102. package/web/firestore/useInfiniteQuery.js +28 -0
  103. package/web/firestore/useInfiniteQuery.ts +91 -0
  104. package/web/firestore/useQuery.d.ts +25 -0
  105. package/web/firestore/useQuery.js +34 -0
  106. package/web/firestore/useQuery.ts +72 -0
  107. package/web/firestore/useRunTransaction.d.ts +15 -0
  108. package/web/firestore/useRunTransaction.js +19 -0
  109. package/web/firestore/useRunTransaction.ts +31 -0
  110. package/web/firestore/useSetDocMutation.d.ts +20 -0
  111. package/web/firestore/useSetDocMutation.js +25 -0
  112. package/web/firestore/useSetDocMutation.ts +52 -0
  113. package/web/firestore/useUpdateDocMutation.d.ts +31 -0
  114. package/web/firestore/useUpdateDocMutation.js +37 -0
  115. package/web/firestore/useUpdateDocMutation.ts +74 -0
  116. package/web/firestore/utils/getDocData.d.ts +18 -0
  117. package/web/firestore/utils/getDocData.js +22 -0
  118. package/web/firestore/utils/getDocData.ts +39 -0
  119. package/web/firestore/utils/getDocRef.d.ts +19 -0
  120. package/web/firestore/utils/getDocRef.js +25 -0
  121. package/web/firestore/utils/getDocRef.ts +46 -0
  122. package/web/firestore/utils/getDocSnap.d.ts +20 -0
  123. package/web/firestore/utils/getDocSnap.js +25 -0
  124. package/web/firestore/utils/getDocSnap.ts +41 -0
  125. package/web/index.d.ts +5 -0
  126. package/web/index.js +5 -0
  127. package/web/index.ts +5 -0
  128. package/web/remoteConfig/index.d.ts +3 -0
  129. package/web/remoteConfig/index.js +3 -0
  130. package/web/remoteConfig/index.ts +3 -0
  131. package/web/remoteConfig/useFetchAndActivate.d.ts +11 -0
  132. package/web/remoteConfig/useFetchAndActivate.js +31 -0
  133. package/web/remoteConfig/useFetchAndActivate.ts +36 -0
  134. package/web/remoteConfig/useGetValue.d.ts +7 -0
  135. package/web/remoteConfig/useGetValue.js +15 -0
  136. package/web/remoteConfig/useGetValue.ts +16 -0
  137. package/web/remoteConfig/useRemoteConfig.d.ts +5 -0
  138. package/web/remoteConfig/useRemoteConfig.js +10 -0
  139. package/web/remoteConfig/useRemoteConfig.ts +11 -0
  140. /package/{dist/src → react-native}/analytics/index.d.ts +0 -0
  141. /package/{dist/src → react-native}/analytics/index.js +0 -0
  142. /package/{src → react-native}/analytics/index.ts +0 -0
  143. /package/{dist/src → react-native}/analytics/useAnalytics.d.ts +0 -0
  144. /package/{dist/src → react-native}/analytics/useAnalytics.js +0 -0
  145. /package/{src → react-native}/analytics/useAnalytics.ts +0 -0
  146. /package/{dist/src → react-native}/analytics/useLogEvent.d.ts +0 -0
  147. /package/{dist/src → react-native}/analytics/useLogEvent.js +0 -0
  148. /package/{src → react-native}/analytics/useLogEvent.ts +0 -0
  149. /package/{dist/src → react-native}/analytics/useSetAnalyticsCollectionEnabled.d.ts +0 -0
  150. /package/{dist/src → react-native}/analytics/useSetAnalyticsCollectionEnabled.js +0 -0
  151. /package/{src → react-native}/analytics/useSetAnalyticsCollectionEnabled.ts +0 -0
  152. /package/{dist/src → react-native}/auth/index.d.ts +0 -0
  153. /package/{dist/src → react-native}/auth/index.js +0 -0
  154. /package/{src → react-native}/auth/index.ts +0 -0
  155. /package/{dist/src → react-native}/auth/mutation-keys.d.ts +0 -0
  156. /package/{dist/src → react-native}/auth/mutation-keys.js +0 -0
  157. /package/{src → react-native}/auth/mutation-keys.ts +0 -0
  158. /package/{dist/src → react-native}/auth/useAuth.d.ts +0 -0
  159. /package/{dist/src → react-native}/auth/useAuth.js +0 -0
  160. /package/{src → react-native}/auth/useAuth.ts +0 -0
  161. /package/{dist/src → react-native}/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +0 -0
  162. /package/{dist/src → react-native}/auth/useCreateUserWitEmailAndPasswordMutation.js +0 -0
  163. /package/{src → react-native}/auth/useCreateUserWitEmailAndPasswordMutation.ts +0 -0
  164. /package/{dist/src → react-native}/auth/useCurrentUser.d.ts +0 -0
  165. /package/{dist/src → react-native}/auth/useCurrentUser.js +0 -0
  166. /package/{src → react-native}/auth/useCurrentUser.ts +0 -0
  167. /package/{dist/src → react-native}/auth/useIdToken.d.ts +0 -0
  168. /package/{dist/src → react-native}/auth/useIdToken.js +0 -0
  169. /package/{src → react-native}/auth/useIdToken.ts +0 -0
  170. /package/{dist/src → react-native}/auth/useReauthenticateWitCredentialMutation.d.ts +0 -0
  171. /package/{dist/src → react-native}/auth/useReauthenticateWitCredentialMutation.js +0 -0
  172. /package/{src → react-native}/auth/useReauthenticateWitCredentialMutation.ts +0 -0
  173. /package/{dist/src → react-native}/auth/useReauthenticateWitRedirectMutation.d.ts +0 -0
  174. /package/{dist/src → react-native}/auth/useReauthenticateWitRedirectMutation.js +0 -0
  175. /package/{src → react-native}/auth/useReauthenticateWitRedirectMutation.ts +0 -0
  176. /package/{dist/src → react-native}/auth/useSendEmailVerificationMutation.d.ts +0 -0
  177. /package/{dist/src → react-native}/auth/useSendEmailVerificationMutation.js +0 -0
  178. /package/{src → react-native}/auth/useSendEmailVerificationMutation.ts +0 -0
  179. /package/{dist/src → react-native}/auth/useSignInWitEmailAndPasswordMutation.d.ts +0 -0
  180. /package/{dist/src → react-native}/auth/useSignInWitEmailAndPasswordMutation.js +0 -0
  181. /package/{src → react-native}/auth/useSignInWitEmailAndPasswordMutation.ts +0 -0
  182. /package/{dist/src → react-native}/auth/useSignInWitRedirectMutation.d.ts +0 -0
  183. /package/{dist/src → react-native}/auth/useSignInWitRedirectMutation.js +0 -0
  184. /package/{src → react-native}/auth/useSignInWitRedirectMutation.ts +0 -0
  185. /package/{dist/src → react-native}/auth/useSignOutMutation.d.ts +0 -0
  186. /package/{dist/src → react-native}/auth/useSignOutMutation.js +0 -0
  187. /package/{src → react-native}/auth/useSignOutMutation.ts +0 -0
  188. /package/{dist/src → react-native}/auth/useUpdateProfileMutation.d.ts +0 -0
  189. /package/{dist/src → react-native}/auth/useUpdateProfileMutation.js +0 -0
  190. /package/{src → react-native}/auth/useUpdateProfileMutation.ts +0 -0
  191. /package/{dist/src → react-native}/context/FirebaseContext.d.ts +0 -0
  192. /package/{dist/src → react-native}/context/FirebaseContext.js +0 -0
  193. /package/{src → react-native}/context/FirebaseContext.ts +0 -0
  194. /package/{dist/src → react-native}/context/FirebaseContextProvider.d.ts +0 -0
  195. /package/{dist/src → react-native}/context/FirebaseContextProvider.js +0 -0
  196. /package/{src → react-native}/context/FirebaseContextProvider.tsx +0 -0
  197. /package/{dist/src → react-native}/context/index.d.ts +0 -0
  198. /package/{dist/src → react-native}/context/index.js +0 -0
  199. /package/{src → react-native}/context/index.ts +0 -0
  200. /package/{dist/src → react-native}/firestore/index.d.ts +0 -0
  201. /package/{dist/src → react-native}/firestore/index.js +0 -0
  202. /package/{src → react-native}/firestore/index.ts +0 -0
  203. /package/{dist/src → react-native}/firestore/useAddDocMutation.d.ts +0 -0
  204. /package/{dist/src → react-native}/firestore/useAddDocMutation.js +0 -0
  205. /package/{src → react-native}/firestore/useAddDocMutation.ts +0 -0
  206. /package/{dist/src → react-native}/firestore/useBatchWrite.d.ts +0 -0
  207. /package/{dist/src → react-native}/firestore/useBatchWrite.js +0 -0
  208. /package/{src → react-native}/firestore/useBatchWrite.ts +0 -0
  209. /package/{dist/src → react-native}/firestore/useCollectionReference.d.ts +0 -0
  210. /package/{dist/src → react-native}/firestore/useCollectionReference.js +0 -0
  211. /package/{src → react-native}/firestore/useCollectionReference.ts +0 -0
  212. /package/{dist/src → react-native}/firestore/useCompositeFilter.d.ts +0 -0
  213. /package/{dist/src → react-native}/firestore/useCompositeFilter.js +0 -0
  214. /package/{src → react-native}/firestore/useCompositeFilter.ts +0 -0
  215. /package/{dist/src → react-native}/firestore/useCountQuery.d.ts +0 -0
  216. /package/{dist/src → react-native}/firestore/useCountQuery.js +0 -0
  217. /package/{src → react-native}/firestore/useCountQuery.ts +0 -0
  218. /package/{dist/src → react-native}/firestore/useDeleteDocMutation.d.ts +0 -0
  219. /package/{dist/src → react-native}/firestore/useDeleteDocMutation.js +0 -0
  220. /package/{src → react-native}/firestore/useDeleteDocMutation.ts +0 -0
  221. /package/{dist/src → react-native}/firestore/useDocReference.d.ts +0 -0
  222. /package/{dist/src → react-native}/firestore/useDocReference.js +0 -0
  223. /package/{src → react-native}/firestore/useDocReference.ts +0 -0
  224. /package/{dist/src → react-native}/firestore/useDocReferences.d.ts +0 -0
  225. /package/{dist/src → react-native}/firestore/useDocReferences.js +0 -0
  226. /package/{src → react-native}/firestore/useDocReferences.ts +0 -0
  227. /package/{dist/src → react-native}/firestore/useFirestore.d.ts +0 -0
  228. /package/{dist/src → react-native}/firestore/useFirestore.js +0 -0
  229. /package/{src → react-native}/firestore/useFirestore.ts +0 -0
  230. /package/{dist/src → react-native}/firestore/useGetDocData.d.ts +0 -0
  231. /package/{dist/src → react-native}/firestore/useGetDocData.js +0 -0
  232. /package/{src → react-native}/firestore/useGetDocData.ts +0 -0
  233. /package/{dist/src → react-native}/firestore/useGetRealtimeDocData.d.ts +0 -0
  234. /package/{dist/src → react-native}/firestore/useGetRealtimeDocData.js +0 -0
  235. /package/{src → react-native}/firestore/useGetRealtimeDocData.ts +0 -0
  236. /package/{dist/src → react-native}/firestore/useInfiniteQuery.d.ts +0 -0
  237. /package/{dist/src → react-native}/firestore/useInfiniteQuery.js +0 -0
  238. /package/{src → react-native}/firestore/useInfiniteQuery.ts +0 -0
  239. /package/{dist/src → react-native}/firestore/useQuery.d.ts +0 -0
  240. /package/{dist/src → react-native}/firestore/useQuery.js +0 -0
  241. /package/{src → react-native}/firestore/useQuery.ts +0 -0
  242. /package/{dist/src → react-native}/firestore/useRunTransaction.d.ts +0 -0
  243. /package/{dist/src → react-native}/firestore/useRunTransaction.js +0 -0
  244. /package/{src → react-native}/firestore/useRunTransaction.ts +0 -0
  245. /package/{dist/src → react-native}/firestore/useSetDocMutation.d.ts +0 -0
  246. /package/{dist/src → react-native}/firestore/useSetDocMutation.js +0 -0
  247. /package/{src → react-native}/firestore/useSetDocMutation.ts +0 -0
  248. /package/{dist/src → react-native}/firestore/useUpdateDocMutation.d.ts +0 -0
  249. /package/{dist/src → react-native}/firestore/useUpdateDocMutation.js +0 -0
  250. /package/{src → react-native}/firestore/useUpdateDocMutation.ts +0 -0
  251. /package/{dist/src → react-native}/firestore/utils/getDocData.d.ts +0 -0
  252. /package/{dist/src → react-native}/firestore/utils/getDocData.js +0 -0
  253. /package/{src → react-native}/firestore/utils/getDocData.ts +0 -0
  254. /package/{dist/src → react-native}/firestore/utils/getDocRef.d.ts +0 -0
  255. /package/{dist/src → react-native}/firestore/utils/getDocRef.js +0 -0
  256. /package/{src → react-native}/firestore/utils/getDocRef.ts +0 -0
  257. /package/{dist/src → react-native}/firestore/utils/getDocSnap.d.ts +0 -0
  258. /package/{dist/src → react-native}/firestore/utils/getDocSnap.js +0 -0
  259. /package/{src → react-native}/firestore/utils/getDocSnap.ts +0 -0
  260. /package/{dist/src → react-native}/index.d.ts +0 -0
  261. /package/{dist/src → react-native}/index.js +0 -0
  262. /package/{src → react-native}/index.ts +0 -0
  263. /package/{dist/src → react-native}/remoteConfig/index.d.ts +0 -0
  264. /package/{dist/src → react-native}/remoteConfig/index.js +0 -0
  265. /package/{src → react-native}/remoteConfig/index.ts +0 -0
  266. /package/{dist/src → react-native}/remoteConfig/useFetchAndActivate.d.ts +0 -0
  267. /package/{dist/src → react-native}/remoteConfig/useFetchAndActivate.js +0 -0
  268. /package/{src → react-native}/remoteConfig/useFetchAndActivate.ts +0 -0
  269. /package/{dist/src → react-native}/remoteConfig/useGetValue.d.ts +0 -0
  270. /package/{dist/src → react-native}/remoteConfig/useGetValue.js +0 -0
  271. /package/{src → react-native}/remoteConfig/useGetValue.ts +0 -0
  272. /package/{dist/src → react-native}/remoteConfig/useRemoteConfig.d.ts +0 -0
  273. /package/{dist/src → react-native}/remoteConfig/useRemoteConfig.js +0 -0
  274. /package/{src → react-native}/remoteConfig/useRemoteConfig.ts +0 -0
package/package.json CHANGED
@@ -13,19 +13,22 @@
13
13
  "@react-native-firebase/installations": "^21.0.0",
14
14
  "@react-native-firebase/remote-config": "^21.0.0",
15
15
  "@tanstack/react-query": "^5.0.0",
16
+ "firebase": "^11.0.0",
16
17
  "react": "^18.0.0 || ^19.0.0"
17
18
  },
18
19
  "publishConfig": {
19
20
  "access": "public"
20
21
  },
21
- "description": "This module offers react hooks to work with Firebase",
22
+ "description": "This module offers react hooks to work with Firebase on react-native and web platforms",
22
23
  "devDependencies": {
23
24
  "@laverve/eslint-utils": "^5.1.1",
24
- "@react-native-firebase/analytics": "^21.12.2",
25
- "@react-native-firebase/app": "^21.12.2",
26
- "@react-native-firebase/auth": "^21.12.2",
27
- "@react-native-firebase/firestore": "^21.12.2",
28
- "@react-native-firebase/remote-config": "^21.12.2",
25
+ "@react-native-firebase/analytics": "^21.0.0",
26
+ "@react-native-firebase/app": "^21.0.0",
27
+ "@react-native-firebase/auth": "^21.0.0",
28
+ "@react-native-firebase/crashlytics": "^21.0.0",
29
+ "@react-native-firebase/firestore": "^21.0.0",
30
+ "@react-native-firebase/installations": "^21.0.0",
31
+ "@react-native-firebase/remote-config": "^21.0.0",
29
32
  "@types/react": "^19.0.2",
30
33
  "husky": "^9.1.1",
31
34
  "lint-staged": "^15.1.0",
@@ -35,25 +38,25 @@
35
38
  "typedoc-plugin-markdown": "^4.4.1",
36
39
  "typedoc-vitepress-theme": "^1.1.2",
37
40
  "typescript": "^5.2.2",
38
- "vitepress": "^1.5.0"
41
+ "vitepress": "^1.5.0",
42
+ "firebase": "^11.0.1"
39
43
  },
40
44
  "homepage": "https://github.com/vpishuk/react-query-firebase",
41
45
  "keywords": [
42
46
  "firebase",
43
47
  "react",
44
- "hooks"
48
+ "hooks",
49
+ "react-native"
45
50
  ],
46
51
  "license": "MIT",
47
- "main": "./dist/src/index.js",
48
- "types": "./dist/src/index.d.ts",
49
52
  "name": "react-query-firebase",
50
53
  "repository": {
51
54
  "type": "git",
52
55
  "url": "https://github.com/vpishuk/react-query-firebase.git"
53
56
  },
54
57
  "files": [
55
- "./dist/src/",
56
- "./src/",
58
+ "./web/",
59
+ "./react-native/",
57
60
  "package.json",
58
61
  "package-lock.json",
59
62
  "README.md",
@@ -70,5 +73,5 @@
70
73
  "docs:build": "vitepress build docs",
71
74
  "docs:preview": "vitepress preview docs"
72
75
  },
73
- "version": "2.0.0-rc6"
76
+ "version": "2.0.0-rc8"
74
77
  }
@@ -0,0 +1,3 @@
1
+ export * from "./useLogEvent";
2
+ export * from "./useAnalytics";
3
+ export * from "./useSetAnalyticsCollectionEnabled";
@@ -0,0 +1,3 @@
1
+ export * from "./useLogEvent";
2
+ export * from "./useAnalytics";
3
+ export * from "./useSetAnalyticsCollectionEnabled";
@@ -0,0 +1,3 @@
1
+ export * from "./useLogEvent";
2
+ export * from "./useAnalytics";
3
+ export * from "./useSetAnalyticsCollectionEnabled";
@@ -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
+ };
@@ -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
+ };
@@ -0,0 +1,17 @@
1
+ type UseLogEventOptions = {
2
+ eventName: string;
3
+ eventParams?: {
4
+ [key: string]: unknown;
5
+ };
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
+ */
14
+ export declare const useLogEvent: ({ eventName, eventParams }: UseLogEventOptions) => {
15
+ logEvent: () => void;
16
+ };
17
+ export {};
@@ -0,0 +1,21 @@
1
+ import { logEvent } from "firebase/analytics";
2
+ import { useAnalytics } from "./useAnalytics";
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
+ */
11
+ export const useLogEvent = ({ eventName, eventParams }) => {
12
+ const analytics = useAnalytics();
13
+ const logEventCallback = useCallback(() => {
14
+ if (analytics) {
15
+ logEvent(analytics, eventName, eventParams);
16
+ }
17
+ }, [eventName, eventParams]);
18
+ return useMemo(() => ({
19
+ logEvent: logEventCallback
20
+ }), [logEventCallback]);
21
+ };
@@ -0,0 +1,34 @@
1
+ import { logEvent } from "firebase/analytics";
2
+ import { useAnalytics } from "./useAnalytics";
3
+ import { useCallback, useMemo } from "react";
4
+
5
+ type UseLogEventOptions = {
6
+ eventName: string;
7
+ eventParams?: {
8
+ [key: string]: unknown;
9
+ };
10
+ };
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
+ */
19
+ export const useLogEvent = ({ eventName, eventParams }: UseLogEventOptions) => {
20
+ const analytics = useAnalytics();
21
+
22
+ const logEventCallback = useCallback(() => {
23
+ if (analytics) {
24
+ logEvent(analytics, eventName, eventParams);
25
+ }
26
+ }, [eventName, eventParams]);
27
+
28
+ return useMemo(
29
+ () => ({
30
+ logEvent: logEventCallback
31
+ }),
32
+ [logEventCallback]
33
+ );
34
+ };
@@ -0,0 +1,10 @@
1
+ type UseSetAnalyticsCollectionEnabledOptions = {
2
+ enabled?: boolean;
3
+ };
4
+ /**
5
+ * Custom hook to enable or disable analytics collection
6
+ * @param {Object} options - The options for hook.
7
+ * @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
8
+ */
9
+ export declare const useSetAnalyticsCollectionEnabled: ({ enabled }: UseSetAnalyticsCollectionEnabledOptions) => void;
10
+ export {};
@@ -0,0 +1,16 @@
1
+ import { setAnalyticsCollectionEnabled } from "firebase/analytics";
2
+ import { useAnalytics } from "./useAnalytics";
3
+ import { useEffect } from "react";
4
+ /**
5
+ * Custom hook to enable or disable analytics collection
6
+ * @param {Object} options - The options for hook.
7
+ * @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
8
+ */
9
+ export const useSetAnalyticsCollectionEnabled = ({ enabled = false }) => {
10
+ const analytics = useAnalytics();
11
+ useEffect(() => {
12
+ if (analytics) {
13
+ setAnalyticsCollectionEnabled(analytics, enabled);
14
+ }
15
+ }, [analytics]);
16
+ };
@@ -0,0 +1,22 @@
1
+ import { setAnalyticsCollectionEnabled } from "firebase/analytics";
2
+ import { useAnalytics } from "./useAnalytics";
3
+ import { useEffect } from "react";
4
+
5
+ type UseSetAnalyticsCollectionEnabledOptions = {
6
+ enabled?: boolean;
7
+ };
8
+
9
+ /**
10
+ * Custom hook to enable or disable analytics collection
11
+ * @param {Object} options - The options for hook.
12
+ * @param {string} options.enabled - Flag that identifies if analytics collection is enabled.
13
+ */
14
+ export const useSetAnalyticsCollectionEnabled = ({ enabled = false }: UseSetAnalyticsCollectionEnabledOptions) => {
15
+ const analytics = useAnalytics();
16
+
17
+ useEffect(() => {
18
+ if (analytics) {
19
+ setAnalyticsCollectionEnabled(analytics, enabled);
20
+ }
21
+ }, [analytics]);
22
+ };
@@ -0,0 +1,13 @@
1
+ export * from "./mutation-keys";
2
+ export * from "./useAuth";
3
+ export * from "./useCreateUserWitEmailAndPasswordMutation";
4
+ export * from "./useSendEmailVerificationMutation";
5
+ export * from "./useSignInWitEmailAndPasswordMutation";
6
+ export * from "./useCurrentUser";
7
+ export * from "./useAuthStateReady";
8
+ export * from "./useSignInWitRedirectMutation";
9
+ export * from "./useUpdateProfileMutation";
10
+ export * from "./useSignOutMutation";
11
+ export * from "./useIdToken";
12
+ export * from "./useReauthenticateWitCredentialMutation";
13
+ export * from "./useReauthenticateWitRedirectMutation";
@@ -0,0 +1,13 @@
1
+ export * from "./mutation-keys";
2
+ export * from "./useAuth";
3
+ export * from "./useCreateUserWitEmailAndPasswordMutation";
4
+ export * from "./useSendEmailVerificationMutation";
5
+ export * from "./useSignInWitEmailAndPasswordMutation";
6
+ export * from "./useCurrentUser";
7
+ export * from "./useAuthStateReady";
8
+ export * from "./useSignInWitRedirectMutation";
9
+ export * from "./useUpdateProfileMutation";
10
+ export * from "./useSignOutMutation";
11
+ export * from "./useIdToken";
12
+ export * from "./useReauthenticateWitCredentialMutation";
13
+ export * from "./useReauthenticateWitRedirectMutation";
@@ -0,0 +1,13 @@
1
+ export * from "./mutation-keys";
2
+ export * from "./useAuth";
3
+ export * from "./useCreateUserWitEmailAndPasswordMutation";
4
+ export * from "./useSendEmailVerificationMutation";
5
+ export * from "./useSignInWitEmailAndPasswordMutation";
6
+ export * from "./useCurrentUser";
7
+ export * from "./useAuthStateReady";
8
+ export * from "./useSignInWitRedirectMutation";
9
+ export * from "./useUpdateProfileMutation";
10
+ export * from "./useSignOutMutation";
11
+ export * from "./useIdToken";
12
+ export * from "./useReauthenticateWitCredentialMutation";
13
+ export * from "./useReauthenticateWitRedirectMutation";
@@ -0,0 +1,7 @@
1
+ export declare const CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION"];
2
+ export declare const SEND_EMAIL_VERIFICATION_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"];
3
+ export declare const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"];
4
+ export declare const SIGN_IN_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
5
+ export declare const SIGN_OUT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_OUT"];
6
+ export declare const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
7
+ export declare const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_CREDENTIAL"];
@@ -0,0 +1,19 @@
1
+ export const CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
2
+ "FIREBASE",
3
+ "AUTH",
4
+ "CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION"
5
+ ];
6
+ export const SEND_EMAIL_VERIFICATION_MUTATION_KEY = ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"];
7
+ export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
8
+ "FIREBASE",
9
+ "AUTH",
10
+ "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"
11
+ ];
12
+ export const SIGN_IN_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
13
+ export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"];
14
+ export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
15
+ export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
16
+ "FIREBASE",
17
+ "AUTH",
18
+ "REAUTHENTICATE_WITH_CREDENTIAL"
19
+ ];
@@ -0,0 +1,19 @@
1
+ export const CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
2
+ "FIREBASE",
3
+ "AUTH",
4
+ "CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION"
5
+ ] as const;
6
+ export const SEND_EMAIL_VERIFICATION_MUTATION_KEY = ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"] as const;
7
+ export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
8
+ "FIREBASE",
9
+ "AUTH",
10
+ "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"
11
+ ] as const;
12
+ export const SIGN_IN_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"] as const;
13
+ export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"] as const;
14
+ export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"] as const;
15
+ export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
16
+ "FIREBASE",
17
+ "AUTH",
18
+ "REAUTHENTICATE_WITH_CREDENTIAL"
19
+ ] as const;
@@ -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
+ };
@@ -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
+ };
@@ -0,0 +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
+ */
6
+ export declare const useAuthStateReady: () => boolean;
@@ -0,0 +1,19 @@
1
+ import { useAuth } from "./useAuth";
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
+ */
8
+ export const useAuthStateReady = () => {
9
+ const firebaseAuth = useAuth();
10
+ const [isAuthStateReady, setIsAuthStateReady] = useState(false);
11
+ const callback = useCallback(async () => {
12
+ await firebaseAuth.authStateReady();
13
+ setIsAuthStateReady(true);
14
+ }, [isAuthStateReady]);
15
+ useEffect(() => {
16
+ callback();
17
+ }, [callback]);
18
+ return isAuthStateReady;
19
+ };
@@ -0,0 +1,24 @@
1
+ import { useAuth } from "./useAuth";
2
+ import { useCallback, useEffect, useState } from "react";
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
+ */
9
+ export const useAuthStateReady = () => {
10
+ const firebaseAuth = useAuth();
11
+
12
+ const [isAuthStateReady, setIsAuthStateReady] = useState(false);
13
+
14
+ const callback = useCallback(async () => {
15
+ await firebaseAuth.authStateReady();
16
+ setIsAuthStateReady(true);
17
+ }, [isAuthStateReady]);
18
+
19
+ useEffect(() => {
20
+ callback();
21
+ }, [callback]);
22
+
23
+ return isAuthStateReady;
24
+ };
@@ -0,0 +1,15 @@
1
+ import { UseMutationOptions } from "@tanstack/react-query";
2
+ import { UserCredential } from "firebase/auth";
3
+ import { FirebaseError } from "firebase/app";
4
+ export type UseCreateUserWitEmailAndPasswordMutationVariables = {
5
+ email: string;
6
+ password: string;
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
+ */
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>;
@@ -0,0 +1,19 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+ import { createUserWithEmailAndPassword } from "firebase/auth";
3
+ import { useAuth } from "./useAuth";
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
+ */
12
+ export const useCreateUserWitEmailAndPasswordMutation = (options = {}) => {
13
+ const firebaseAuth = useAuth();
14
+ return useMutation({
15
+ ...options,
16
+ mutationFn: async ({ email, password }) => await createUserWithEmailAndPassword(firebaseAuth, email, password),
17
+ mutationKey: CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY
18
+ });
19
+ };
@@ -0,0 +1,33 @@
1
+ import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
+ import { createUserWithEmailAndPassword, UserCredential } from "firebase/auth";
3
+ import { useAuth } from "./useAuth";
4
+ import { FirebaseError } from "firebase/app";
5
+ import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
6
+
7
+ export type UseCreateUserWitEmailAndPasswordMutationVariables = {
8
+ email: string;
9
+ password: string;
10
+ };
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
+ */
19
+ export const useCreateUserWitEmailAndPasswordMutation = <TContext = unknown>(
20
+ options: Omit<
21
+ UseMutationOptions<UserCredential, FirebaseError, UseCreateUserWitEmailAndPasswordMutationVariables, TContext>,
22
+ "mutationKey" | "mutationFn"
23
+ > = {}
24
+ ) => {
25
+ const firebaseAuth = useAuth();
26
+
27
+ return useMutation({
28
+ ...options,
29
+ mutationFn: async ({ email, password }: UseCreateUserWitEmailAndPasswordMutationVariables) =>
30
+ await createUserWithEmailAndPassword(firebaseAuth, email, password),
31
+ mutationKey: CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY
32
+ });
33
+ };
@@ -0,0 +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
+ */
6
+ export declare const useCurrentUser: () => import("@firebase/auth").User | null;
@@ -0,0 +1,20 @@
1
+ import { useAuth } from "./useAuth";
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
+ */
8
+ export const useCurrentUser = () => {
9
+ const firebaseAuth = useAuth();
10
+ const [currentUser, setCurrentUser] = useState(firebaseAuth.currentUser);
11
+ useEffect(() => {
12
+ const unsubscribe = firebaseAuth.onAuthStateChanged((user) => {
13
+ setCurrentUser(user);
14
+ });
15
+ return () => {
16
+ unsubscribe();
17
+ };
18
+ }, [currentUser?.uid ?? ""]);
19
+ return currentUser;
20
+ };
@@ -0,0 +1,24 @@
1
+ import { useAuth } from "./useAuth";
2
+ import { useEffect, useState } from "react";
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
+ */
9
+ export const useCurrentUser = () => {
10
+ const firebaseAuth = useAuth();
11
+
12
+ const [currentUser, setCurrentUser] = useState(firebaseAuth.currentUser);
13
+
14
+ useEffect(() => {
15
+ const unsubscribe = firebaseAuth.onAuthStateChanged((user) => {
16
+ setCurrentUser(user);
17
+ });
18
+ return () => {
19
+ unsubscribe();
20
+ };
21
+ }, [currentUser?.uid ?? ""]);
22
+
23
+ return currentUser;
24
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @inline
3
+ */
4
+ export type UseIdTokenResult = {
5
+ idToken: string;
6
+ refresh: () => Promise<string | undefined>;
7
+ };
8
+ /**
9
+ * A hook to manage the ID token.
10
+ * It monitors changes to the ID token and provides the token itself along with a refresh method to update the token when needed.
11
+ *
12
+ * @group Hook
13
+ *
14
+ * @returns {UseIdTokenResult}
15
+ *
16
+ * @example
17
+ * ```jsx
18
+ * export const MyComponent = () => {
19
+ * const result = useIdToken();
20
+ * useEffect(() => {
21
+ * const timeout = setTimeout(() => {
22
+ * result.refresh();
23
+ * }, 5000);
24
+ * return () => clearTimeout();
25
+ * }, [])
26
+ * console.log(resilt.idToken);
27
+ * };
28
+ * ```
29
+ */
30
+ export declare const useIdToken: () => UseIdTokenResult;
@@ -0,0 +1,66 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { useCurrentUser } from "./useCurrentUser";
3
+ import { onIdTokenChanged } from "firebase/auth";
4
+ import { useAuth } from "./useAuth";
5
+ /**
6
+ * A hook to manage the ID token.
7
+ * It monitors changes to the ID token and provides the token itself along with a refresh method to update the token when needed.
8
+ *
9
+ * @group Hook
10
+ *
11
+ * @returns {UseIdTokenResult}
12
+ *
13
+ * @example
14
+ * ```jsx
15
+ * export const MyComponent = () => {
16
+ * const result = useIdToken();
17
+ * useEffect(() => {
18
+ * const timeout = setTimeout(() => {
19
+ * result.refresh();
20
+ * }, 5000);
21
+ * return () => clearTimeout();
22
+ * }, [])
23
+ * console.log(resilt.idToken);
24
+ * };
25
+ * ```
26
+ */
27
+ export const useIdToken = () => {
28
+ const auth = useAuth();
29
+ const currentUser = useCurrentUser();
30
+ const [idToken, setIdToken] = useState("");
31
+ const callback = useCallback(async () => {
32
+ if (!currentUser) {
33
+ setIdToken("");
34
+ return;
35
+ }
36
+ const idToken = await currentUser.getIdToken();
37
+ setIdToken(idToken);
38
+ }, [currentUser, idToken]);
39
+ const refresh = useCallback(async () => {
40
+ if (!currentUser) {
41
+ return;
42
+ }
43
+ const idToken = await currentUser.getIdToken(true);
44
+ return idToken;
45
+ }, [currentUser, idToken]);
46
+ useEffect(() => {
47
+ callback();
48
+ }, [currentUser?.uid ?? ""]);
49
+ useEffect(() => {
50
+ const unsubscribe = onIdTokenChanged(auth, (user) => {
51
+ if (user) {
52
+ user.getIdToken().then((idToken) => {
53
+ setIdToken(idToken);
54
+ });
55
+ }
56
+ else {
57
+ setIdToken("");
58
+ }
59
+ });
60
+ return () => unsubscribe();
61
+ }, [idToken]);
62
+ return {
63
+ idToken,
64
+ refresh
65
+ };
66
+ };