react-query-firebase 1.3.3 → 2.0.0-rc1
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.
- package/dist/src/analytics/useAnalytics.d.ts +1 -1
- package/dist/src/analytics/useLogEvent.js +1 -1
- package/dist/src/analytics/useSetAnalyticsCollectionEnabled.js +1 -1
- package/dist/src/auth/index.d.ts +0 -1
- package/dist/src/auth/index.js +0 -1
- package/dist/src/auth/useAuth.d.ts +1 -1
- package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.d.ts +5 -5
- package/dist/src/auth/useCreateUserWitEmailAndPasswordMutation.js +3 -3
- package/dist/src/auth/useCurrentUser.d.ts +1 -1
- package/dist/src/auth/useCurrentUser.js +4 -4
- package/dist/src/auth/useIdToken.js +1 -1
- package/dist/src/auth/useReauthenticateWitCredentialMutation.d.ts +7 -7
- package/dist/src/auth/useReauthenticateWitCredentialMutation.js +3 -3
- package/dist/src/auth/useReauthenticateWitRedirectMutation.d.ts +7 -7
- package/dist/src/auth/useReauthenticateWitRedirectMutation.js +3 -3
- package/dist/src/auth/useSendEmailVerificationMutation.d.ts +6 -6
- package/dist/src/auth/useSendEmailVerificationMutation.js +3 -3
- package/dist/src/auth/useSignInWitEmailAndPasswordMutation.d.ts +4 -4
- package/dist/src/auth/useSignInWitEmailAndPasswordMutation.js +2 -2
- package/dist/src/auth/useSignInWitRedirectMutation.d.ts +6 -6
- package/dist/src/auth/useSignInWitRedirectMutation.js +3 -3
- package/dist/src/auth/useSignOutMutation.d.ts +4 -4
- package/dist/src/auth/useSignOutMutation.js +3 -3
- package/dist/src/auth/useUpdateProfileMutation.d.ts +6 -6
- package/dist/src/auth/useUpdateProfileMutation.js +3 -3
- package/dist/src/context/FirebaseContext.d.ts +6 -10
- package/dist/src/context/FirebaseContextProvider.d.ts +25 -7
- package/dist/src/context/FirebaseContextProvider.js +41 -41
- package/dist/src/firestore/useAddDocMutation.d.ts +7 -9
- package/dist/src/firestore/useAddDocMutation.js +4 -5
- package/dist/src/firestore/useBatchWrite.d.ts +5 -5
- package/dist/src/firestore/useBatchWrite.js +1 -1
- package/dist/src/firestore/useCollectionReference.d.ts +5 -5
- package/dist/src/firestore/useCollectionReference.js +3 -5
- package/dist/src/firestore/useCompositeFilter.d.ts +6 -6
- package/dist/src/firestore/useCompositeFilter.js +12 -9
- package/dist/src/firestore/useCountQuery.d.ts +7 -7
- package/dist/src/firestore/useCountQuery.js +3 -3
- package/dist/src/firestore/useDeleteDocMutation.d.ts +6 -6
- package/dist/src/firestore/useDeleteDocMutation.js +1 -1
- package/dist/src/firestore/useDocReference.d.ts +6 -6
- package/dist/src/firestore/useDocReference.js +6 -10
- package/dist/src/firestore/useDocReferences.d.ts +6 -6
- package/dist/src/firestore/useDocReferences.js +4 -6
- package/dist/src/firestore/useFirestore.d.ts +1 -1
- package/dist/src/firestore/useGetDocData.d.ts +5 -5
- package/dist/src/firestore/useGetRealtimeDocData.d.ts +7 -7
- package/dist/src/firestore/useGetRealtimeDocData.js +1 -1
- package/dist/src/firestore/useInfiniteQuery.d.ts +5 -6
- package/dist/src/firestore/useInfiniteQuery.js +3 -3
- package/dist/src/firestore/useQuery.d.ts +7 -8
- package/dist/src/firestore/useQuery.js +5 -5
- package/dist/src/firestore/useRunTransaction.d.ts +5 -5
- package/dist/src/firestore/useRunTransaction.js +1 -1
- package/dist/src/firestore/useSetDocMutation.d.ts +7 -7
- package/dist/src/firestore/useSetDocMutation.js +2 -2
- package/dist/src/firestore/useUpdateDocMutation.d.ts +7 -8
- package/dist/src/firestore/useUpdateDocMutation.js +4 -4
- package/dist/src/firestore/utils/getDocData.d.ts +3 -3
- package/dist/src/firestore/utils/getDocData.js +1 -1
- package/dist/src/firestore/utils/getDocRef.d.ts +8 -8
- package/dist/src/firestore/utils/getDocRef.js +5 -9
- package/dist/src/firestore/utils/getDocSnap.d.ts +4 -4
- package/dist/src/firestore/utils/getDocSnap.js +2 -2
- package/dist/src/remoteConfig/useFetchAndActivate.js +1 -1
- package/dist/src/remoteConfig/useGetValue.d.ts +1 -1
- package/dist/src/remoteConfig/useGetValue.js +1 -1
- package/dist/src/remoteConfig/useRemoteConfig.d.ts +1 -1
- package/package.json +15 -5
- package/src/analytics/useLogEvent.ts +1 -1
- package/src/analytics/useSetAnalyticsCollectionEnabled.ts +1 -1
- package/src/auth/index.ts +0 -1
- package/src/auth/useCreateUserWitEmailAndPasswordMutation.ts +10 -5
- package/src/auth/useCurrentUser.ts +4 -4
- package/src/auth/useIdToken.ts +2 -2
- package/src/auth/useReauthenticateWitCredentialMutation.ts +12 -7
- package/src/auth/useReauthenticateWitRedirectMutation.ts +12 -7
- package/src/auth/useSendEmailVerificationMutation.ts +11 -6
- package/src/auth/useSignInWitEmailAndPasswordMutation.ts +9 -4
- package/src/auth/useSignInWitRedirectMutation.ts +11 -6
- package/src/auth/useSignOutMutation.ts +5 -5
- package/src/auth/useUpdateProfileMutation.ts +6 -6
- package/src/context/FirebaseContext.ts +6 -10
- package/src/context/FirebaseContextProvider.tsx +71 -44
- package/src/firestore/useAddDocMutation.ts +15 -22
- package/src/firestore/useBatchWrite.ts +7 -4
- package/src/firestore/useCollectionReference.ts +13 -9
- package/src/firestore/useCompositeFilter.ts +22 -27
- package/src/firestore/useCountQuery.ts +9 -13
- package/src/firestore/useDeleteDocMutation.ts +11 -10
- package/src/firestore/useDocReference.ts +23 -19
- package/src/firestore/useDocReferences.ts +15 -11
- package/src/firestore/useGetDocData.ts +14 -15
- package/src/firestore/useGetRealtimeDocData.ts +16 -10
- package/src/firestore/useInfiniteQuery.ts +9 -16
- package/src/firestore/useQuery.ts +11 -20
- package/src/firestore/useRunTransaction.ts +9 -4
- package/src/firestore/useSetDocMutation.ts +14 -11
- package/src/firestore/useUpdateDocMutation.ts +15 -21
- package/src/firestore/utils/getDocData.ts +7 -9
- package/src/firestore/utils/getDocRef.ts +13 -17
- package/src/firestore/utils/getDocSnap.ts +7 -9
- package/src/remoteConfig/useFetchAndActivate.ts +1 -1
- package/src/remoteConfig/useGetValue.ts +1 -1
- package/dist/src/auth/useAuthStateReady.d.ts +0 -6
- package/dist/src/auth/useAuthStateReady.js +0 -19
- package/src/auth/useAuthStateReady.ts +0 -24
package/src/auth/useIdToken.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from "react";
|
|
2
2
|
import { useCurrentUser } from "./useCurrentUser";
|
|
3
|
-
import { onIdTokenChanged } from "firebase/auth";
|
|
3
|
+
import { onIdTokenChanged, FirebaseAuthTypes } from "@react-native-firebase/auth";
|
|
4
4
|
import { useAuth } from "./useAuth";
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -63,7 +63,7 @@ export const useIdToken = (): UseIdTokenResult => {
|
|
|
63
63
|
}, [currentUser?.uid ?? ""]);
|
|
64
64
|
|
|
65
65
|
useEffect(() => {
|
|
66
|
-
const unsubscribe = onIdTokenChanged(auth, (user) => {
|
|
66
|
+
const unsubscribe = onIdTokenChanged(auth, (user: FirebaseAuthTypes.User) => {
|
|
67
67
|
if (user) {
|
|
68
68
|
user.getIdToken().then((idToken) => {
|
|
69
69
|
setIdToken(idToken);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { reauthenticateWithCredential,
|
|
2
|
+
import { reauthenticateWithCredential, FirebaseAuthTypes } from "@react-native-firebase/auth";
|
|
3
3
|
import { REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY } from "./mutation-keys";
|
|
4
|
-
import {
|
|
4
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
5
5
|
|
|
6
6
|
export type UseReauthenticateWitCredentialMutationVariables = {
|
|
7
|
-
credential: AuthCredential;
|
|
8
|
-
user: User;
|
|
7
|
+
credential: FirebaseAuthTypes.AuthCredential;
|
|
8
|
+
user: FirebaseAuthTypes.User;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -13,12 +13,17 @@ export type UseReauthenticateWitCredentialMutationVariables = {
|
|
|
13
13
|
* This hook utilizes useMutation from React Query to manage the asynchronous re-authentication
|
|
14
14
|
* process with Firebase credentials. It omits the default "mutationKey" and "mutationFn" options.
|
|
15
15
|
*
|
|
16
|
-
* @param {Omit<UseMutationOptions<UserCredential,
|
|
17
|
-
* @returns {UseMutationResult<UserCredential,
|
|
16
|
+
* @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional mutation options excluding "mutationKey" and "mutationFn".
|
|
17
|
+
* @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitCredentialMutationVariables, TContext>} A useMutation result object managing the loading, error, and result state of the re-authentication mutation.
|
|
18
18
|
*/
|
|
19
19
|
export const useReauthenticateWitCredentialMutation = <TContext = unknown>(
|
|
20
20
|
options: Omit<
|
|
21
|
-
UseMutationOptions<
|
|
21
|
+
UseMutationOptions<
|
|
22
|
+
FirebaseAuthTypes.UserCredential,
|
|
23
|
+
ReactNativeFirebase.NativeFirebaseError,
|
|
24
|
+
UseReauthenticateWitCredentialMutationVariables,
|
|
25
|
+
TContext
|
|
26
|
+
>,
|
|
22
27
|
"mutationKey" | "mutationFn"
|
|
23
28
|
> = {}
|
|
24
29
|
) => {
|
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { reauthenticateWithRedirect,
|
|
2
|
+
import { reauthenticateWithRedirect, FirebaseAuthTypes, PopupRedirectResolver } from "@react-native-firebase/auth";
|
|
3
3
|
|
|
4
4
|
import { REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
|
|
5
|
-
import {
|
|
5
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
6
6
|
|
|
7
7
|
export type UseReauthenticateWitRedirectMutationVariables = {
|
|
8
|
-
authProvider: AuthProvider;
|
|
8
|
+
authProvider: FirebaseAuthTypes.AuthProvider;
|
|
9
9
|
popupRedirectResolver?: PopupRedirectResolver;
|
|
10
|
-
user: User;
|
|
10
|
+
user: FirebaseAuthTypes.User;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Custom hook that provides a mutation to reauthenticate a user with a given authentication provider using redirection.
|
|
15
15
|
* This hook uses the `useMutation` hook from the React Query library to handle async mutation logic.
|
|
16
16
|
*
|
|
17
|
-
* @param {Omit<UseMutationOptions<void,
|
|
17
|
+
* @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, 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
18
|
* @template TContext - The type of any additional context you wish to pass to the mutation.
|
|
19
|
-
* @returns {UseMutationResult<void,
|
|
19
|
+
* @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseReauthenticateWitRedirectMutationVariables, TContext>} A mutation result object containing methods and state of the mutation.
|
|
20
20
|
*/
|
|
21
21
|
export const useReauthenticateWitRedirectMutation = <TContext = unknown>(
|
|
22
22
|
options: Omit<
|
|
23
|
-
UseMutationOptions<
|
|
23
|
+
UseMutationOptions<
|
|
24
|
+
void,
|
|
25
|
+
ReactNativeFirebase.NativeFirebaseError,
|
|
26
|
+
UseReauthenticateWitRedirectMutationVariables,
|
|
27
|
+
TContext
|
|
28
|
+
>,
|
|
24
29
|
"mutationKey" | "mutationFn"
|
|
25
30
|
> = {}
|
|
26
31
|
) => {
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { sendEmailVerification,
|
|
2
|
+
import { sendEmailVerification, FirebaseAuthTypes } from "@react-native-firebase/auth";
|
|
3
3
|
|
|
4
4
|
import { SEND_EMAIL_VERIFICATION_MUTATION_KEY } from "./mutation-keys";
|
|
5
|
-
import {
|
|
5
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
6
6
|
|
|
7
7
|
export type UseSendEmailVerificationMutationVariables = {
|
|
8
|
-
user: User;
|
|
8
|
+
user: FirebaseAuthTypes.User;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* A custom hook to create a mutation for sending an email verification to a user using Firebase.
|
|
13
13
|
* This uses the `useMutation` hook from a query library and wraps it with specific configuration options.
|
|
14
|
-
* @param {Omit<UseMutationOptions<void,
|
|
15
|
-
* @returns {UseMutationResult<void,
|
|
14
|
+
* @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeReactNativeFirebase.NativeFirebaseError, UseSendEmailVerificationMutationVariables, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding `queryKey` and `queryFn`.
|
|
15
|
+
* @returns {UseMutationResult<void, NativeReactNativeFirebase.NativeFirebaseError, UseSendEmailVerificationMutationVariables, TContext>} An object containing mutation state and functions for managing the mutation lifecycle.
|
|
16
16
|
*/
|
|
17
17
|
export const useSendEmailVerificationMutation = <TContext = unknown>(
|
|
18
18
|
options: Omit<
|
|
19
|
-
UseMutationOptions<
|
|
19
|
+
UseMutationOptions<
|
|
20
|
+
void,
|
|
21
|
+
ReactNativeFirebase.NativeFirebaseError,
|
|
22
|
+
UseSendEmailVerificationMutationVariables,
|
|
23
|
+
TContext
|
|
24
|
+
>,
|
|
20
25
|
"queryKey" | "queryFn"
|
|
21
26
|
> = {}
|
|
22
27
|
) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { signInWithEmailAndPassword,
|
|
2
|
+
import { signInWithEmailAndPassword, FirebaseAuthTypes } from "@react-native-firebase/auth";
|
|
3
3
|
|
|
4
4
|
import { useAuth } from "./useAuth";
|
|
5
5
|
import { SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
|
|
6
|
-
import {
|
|
6
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
7
7
|
|
|
8
8
|
export type UseSignInWitEmailAndPasswordMutationVariables = {
|
|
9
9
|
email: string;
|
|
@@ -14,12 +14,17 @@ export type UseSignInWitEmailAndPasswordMutationVariables = {
|
|
|
14
14
|
* Custom hook to perform a sign-in operation using email and password with Firebase Authentication.
|
|
15
15
|
* It utilizes the `useMutation` hook to manage the asynchronous operation and its state.
|
|
16
16
|
*
|
|
17
|
-
* @param {Omit<UseMutationOptions<UserCredential,
|
|
17
|
+
* @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseSignInWitEmailAndPasswordMutationVariables, TContext>, 'mutationKey' | 'mutationFn'>} options - Options to configure the mutation, excluding 'mutationKey' and 'mutationFn'.
|
|
18
18
|
* @returns {MutationResult} A mutation object containing the result of the sign-in process and helper functions.
|
|
19
19
|
*/
|
|
20
20
|
export const useSignInWitEmailAndPasswordMutation = <TContext = unknown>(
|
|
21
21
|
options: Omit<
|
|
22
|
-
UseMutationOptions<
|
|
22
|
+
UseMutationOptions<
|
|
23
|
+
FirebaseAuthTypes.UserCredential,
|
|
24
|
+
ReactNativeFirebase.NativeFirebaseError,
|
|
25
|
+
UseSignInWitEmailAndPasswordMutationVariables,
|
|
26
|
+
TContext
|
|
27
|
+
>,
|
|
23
28
|
"mutationKey" | "mutationFn"
|
|
24
29
|
> = {}
|
|
25
30
|
) => {
|
|
@@ -1,24 +1,29 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { signInWithRedirect,
|
|
2
|
+
import { signInWithRedirect, FirebaseAuthTypes, PopupRedirectResolver } from "@react-native-firebase/auth";
|
|
3
3
|
|
|
4
4
|
import { useAuth } from "./useAuth";
|
|
5
5
|
import { SIGN_IN_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
|
|
6
|
-
import {
|
|
6
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
7
7
|
|
|
8
8
|
export type UseSignInWitRedirectMutationVariables = {
|
|
9
|
-
authProvider: AuthProvider;
|
|
9
|
+
authProvider: FirebaseAuthTypes.AuthProvider;
|
|
10
10
|
popupRedirectResolver?: PopupRedirectResolver;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Custom hook for handling Firebase authentication using sign-in with redirect functionality.
|
|
15
15
|
* This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
|
|
16
|
-
* @param {Omit<UseMutationOptions<void,
|
|
17
|
-
* @returns {UseMutationResult<void,
|
|
16
|
+
* @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseSignInWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
|
|
17
|
+
* @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseSignInWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
|
|
18
18
|
*/
|
|
19
19
|
export const useSignInWitRedirectMutation = <TContext = unknown>(
|
|
20
20
|
options: Omit<
|
|
21
|
-
UseMutationOptions<
|
|
21
|
+
UseMutationOptions<
|
|
22
|
+
void,
|
|
23
|
+
ReactNativeFirebase.NativeFirebaseError,
|
|
24
|
+
UseSignInWitRedirectMutationVariables,
|
|
25
|
+
TContext
|
|
26
|
+
>,
|
|
22
27
|
"mutationKey" | "mutationFn"
|
|
23
28
|
> = {}
|
|
24
29
|
) => {
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { signOut } from "firebase/auth";
|
|
2
|
+
import { signOut } from "@react-native-firebase/auth";
|
|
3
3
|
|
|
4
4
|
import { SIGN_OUT_MUTATION_KEY } from "./mutation-keys";
|
|
5
|
-
import {
|
|
5
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
6
6
|
import { useAuth } from "./useAuth";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Custom hook for handling the sign-out mutation using Firebase authentication.
|
|
10
10
|
* It wraps the useMutation hook to provide a sign-out function with Firebase.
|
|
11
11
|
*
|
|
12
|
-
* @param {Omit<UseMutationOptions<void,
|
|
13
|
-
* @returns {UseMutationResult<void,
|
|
12
|
+
* @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>, "queryKey" | "queryFn">} options - Configuration options for the mutation, excluding "queryKey" and "queryFn".
|
|
13
|
+
* @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>} A mutation object for handling the sign-out process, including methods for mutating and state tracking.
|
|
14
14
|
*/
|
|
15
15
|
export const useSignOutMutation = <TContext = unknown>(
|
|
16
|
-
options: Omit<UseMutationOptions<void,
|
|
16
|
+
options: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, void, TContext>, "queryKey" | "queryFn"> = {}
|
|
17
17
|
) => {
|
|
18
18
|
const firebaseAuth = useAuth();
|
|
19
19
|
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { updateProfile,
|
|
3
|
-
import {
|
|
2
|
+
import { updateProfile, FirebaseAuthTypes } from "@react-native-firebase/auth";
|
|
3
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
4
4
|
import { CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY } from "./mutation-keys";
|
|
5
5
|
|
|
6
6
|
export type UseUpdateProfileMutationVariables = {
|
|
7
7
|
displayName?: string;
|
|
8
|
-
user: User;
|
|
8
|
+
user: FirebaseAuthTypes.User;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Custom hook to manage the mutation for updating a user's profile.
|
|
13
13
|
* Utilizes Firebase for updating the user's display name.
|
|
14
14
|
*
|
|
15
|
-
* @param {Omit<UseMutationOptions<void,
|
|
16
|
-
* @returns {UseMutationResult<void,
|
|
15
|
+
* @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseUpdateProfileMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Configuration options for the mutation, excluding mutationKey and mutationFn.
|
|
16
|
+
* @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseUpdateProfileMutationVariables, TContext>} The result of the mutation operation including statuses, data, and error information.
|
|
17
17
|
*/
|
|
18
18
|
export const useUpdateProfileMutation = <TContext = unknown>(
|
|
19
19
|
options: Omit<
|
|
20
|
-
UseMutationOptions<void,
|
|
20
|
+
UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseUpdateProfileMutationVariables, TContext>,
|
|
21
21
|
"mutationKey" | "mutationFn"
|
|
22
22
|
> = {}
|
|
23
23
|
) => {
|
|
@@ -2,18 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
import { createContext } from "react";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import { Analytics } from "firebase/analytics";
|
|
7
|
-
import { Firestore } from "firebase/firestore";
|
|
8
|
-
import { FirebaseApp } from "firebase/app";
|
|
9
|
-
import { RemoteConfig } from "firebase/remote-config";
|
|
5
|
+
import { firebase } from "@react-native-firebase/auth";
|
|
10
6
|
|
|
11
7
|
type FirebaseContextValue = {
|
|
12
|
-
auth:
|
|
13
|
-
analytics:
|
|
14
|
-
firebase:
|
|
15
|
-
remoteConfig:
|
|
16
|
-
firestore:
|
|
8
|
+
auth: ReturnType<typeof firebase.auth>;
|
|
9
|
+
analytics: ReturnType<typeof firebase.analytics>;
|
|
10
|
+
firebase: ReturnType<typeof firebase.app>;
|
|
11
|
+
remoteConfig: ReturnType<typeof firebase.remoteConfig>;
|
|
12
|
+
firestore: ReturnType<typeof firebase.firestore>;
|
|
17
13
|
};
|
|
18
14
|
|
|
19
15
|
/**
|
|
@@ -1,10 +1,29 @@
|
|
|
1
1
|
import React, { PropsWithChildren, useEffect, useMemo } from "react";
|
|
2
2
|
import { FirebaseContext } from "./FirebaseContext";
|
|
3
|
-
import { connectAuthEmulator
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { connectFirestoreEmulator
|
|
7
|
-
import {
|
|
3
|
+
import { connectAuthEmulator } from "@react-native-firebase/auth";
|
|
4
|
+
import { FirebaseAnalyticsTypes, setAnalyticsCollectionEnabled, setConsent } from "@react-native-firebase/analytics";
|
|
5
|
+
import { FirebaseRemoteConfigTypes } from "@react-native-firebase/remote-config";
|
|
6
|
+
import { connectFirestoreEmulator } from "@react-native-firebase/firestore";
|
|
7
|
+
import firebase, { ReactNativeFirebase, initializeApp } from "@react-native-firebase/app";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @inline
|
|
11
|
+
* @see https://firebase.google.com/docs/reference/js/firestore_.firestoresettings
|
|
12
|
+
*/
|
|
13
|
+
export type FirestoreSettings = {
|
|
14
|
+
cacheSizeBytes?: number;
|
|
15
|
+
experimentalAutoDetectLongPolling?: boolean;
|
|
16
|
+
experimentalForceLongPolling?: boolean;
|
|
17
|
+
experimentalLongPollingOptions?: {
|
|
18
|
+
timeoutSeconds: number;
|
|
19
|
+
};
|
|
20
|
+
host?: string;
|
|
21
|
+
ignoreUndefinedProperties?: boolean;
|
|
22
|
+
localCache?: {
|
|
23
|
+
kind: "memory" | "persistent";
|
|
24
|
+
};
|
|
25
|
+
ssl?: boolean;
|
|
26
|
+
};
|
|
8
27
|
|
|
9
28
|
/**
|
|
10
29
|
* @inline
|
|
@@ -48,6 +67,7 @@ export type FirebaseContextProviderEmulators = {
|
|
|
48
67
|
* @inline
|
|
49
68
|
*/
|
|
50
69
|
export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
70
|
+
platform: "Web" | "ReactNative";
|
|
51
71
|
/**
|
|
52
72
|
* Defines configuration for firebase emulators
|
|
53
73
|
*/
|
|
@@ -55,7 +75,7 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
55
75
|
/**
|
|
56
76
|
* Configuration options for Firebase initialization. {@link https://firebase.google.com/docs/web/setup#config-object | Learn about the Firebase config object}
|
|
57
77
|
*/
|
|
58
|
-
options:
|
|
78
|
+
options: ReactNativeFirebase.FirebaseAppOptions;
|
|
59
79
|
/**
|
|
60
80
|
* Flag indicating whether Firebase Auth should be enabled.
|
|
61
81
|
*/
|
|
@@ -77,7 +97,7 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
77
97
|
* security_storage: "denied"
|
|
78
98
|
* }
|
|
79
99
|
*/
|
|
80
|
-
consentSettings?: ConsentSettings;
|
|
100
|
+
consentSettings?: FirebaseAnalyticsTypes.ConsentSettings;
|
|
81
101
|
/**
|
|
82
102
|
* Specifies custom configurations for your Cloud Firestore instance.
|
|
83
103
|
* You must set these before invoking any other methods.
|
|
@@ -94,7 +114,7 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
94
114
|
* 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}
|
|
95
115
|
* @defaultValue `true`
|
|
96
116
|
*/
|
|
97
|
-
remoteConfigSettings?:
|
|
117
|
+
remoteConfigSettings?: FirebaseRemoteConfigTypes.ConfigSettings;
|
|
98
118
|
/**
|
|
99
119
|
* Configuration options for Firebase Remote Config Defaults.
|
|
100
120
|
*/
|
|
@@ -130,6 +150,7 @@ export type FirebaseContextProviderProps = PropsWithChildren & {
|
|
|
130
150
|
* ```
|
|
131
151
|
*/
|
|
132
152
|
export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = ({
|
|
153
|
+
platform,
|
|
133
154
|
emulators,
|
|
134
155
|
options,
|
|
135
156
|
children,
|
|
@@ -142,40 +163,42 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
142
163
|
remoteConfigDefaults = {},
|
|
143
164
|
firestoreSettings
|
|
144
165
|
}) => {
|
|
145
|
-
const
|
|
146
|
-
return initializeApp(options);
|
|
166
|
+
const internalFirebase = useMemo(() => {
|
|
167
|
+
return platform === "Web" ? initializeApp(options) : firebase;
|
|
147
168
|
}, [options]);
|
|
148
169
|
|
|
149
170
|
useEffect(() => {
|
|
150
|
-
setConsent({
|
|
151
|
-
ad_personalization:
|
|
152
|
-
ad_storage:
|
|
153
|
-
ad_user_data:
|
|
154
|
-
analytics_storage:
|
|
155
|
-
functionality_storage:
|
|
156
|
-
personalization_storage:
|
|
157
|
-
security_storage:
|
|
171
|
+
setConsent(firebase.analytics(), {
|
|
172
|
+
ad_personalization: false,
|
|
173
|
+
ad_storage: false,
|
|
174
|
+
ad_user_data: false,
|
|
175
|
+
analytics_storage: false,
|
|
176
|
+
functionality_storage: false,
|
|
177
|
+
personalization_storage: false,
|
|
178
|
+
security_storage: false,
|
|
158
179
|
...consentSettings
|
|
159
180
|
});
|
|
160
|
-
}, [consentSettings]);
|
|
181
|
+
}, [consentSettings, firebase]);
|
|
161
182
|
|
|
162
|
-
const
|
|
183
|
+
const internalFirestore = useMemo(() => {
|
|
163
184
|
if (firestoreEnabled) {
|
|
164
|
-
const localFirestore = initializeFirestore(firebase, firestoreSettings || {});
|
|
165
|
-
|
|
166
185
|
if (emulators?.firestore?.host && emulators?.firestore?.port) {
|
|
167
|
-
connectFirestoreEmulator(
|
|
186
|
+
connectFirestoreEmulator(
|
|
187
|
+
internalFirebase.firestore(),
|
|
188
|
+
emulators.firestore.host,
|
|
189
|
+
emulators.firestore.port
|
|
190
|
+
);
|
|
168
191
|
}
|
|
169
192
|
|
|
170
|
-
return
|
|
193
|
+
return internalFirebase.firestore();
|
|
171
194
|
}
|
|
172
195
|
|
|
173
196
|
return null;
|
|
174
|
-
}, [firestoreSettings, emulators?.firestore, firestoreEnabled]);
|
|
197
|
+
}, [firestoreSettings, emulators?.firestore, firestoreEnabled, internalFirebase]);
|
|
175
198
|
|
|
176
|
-
const
|
|
199
|
+
const internalAuth = useMemo(() => {
|
|
177
200
|
if (authEnabled) {
|
|
178
|
-
const localAuth =
|
|
201
|
+
const localAuth = internalFirebase.auth();
|
|
179
202
|
if (emulators?.auth?.host) {
|
|
180
203
|
connectAuthEmulator(localAuth, emulators?.auth?.host, {
|
|
181
204
|
disableWarnings: true
|
|
@@ -184,42 +207,46 @@ export const FirebaseContextProvider: React.FC<FirebaseContextProviderProps> = (
|
|
|
184
207
|
return localAuth;
|
|
185
208
|
}
|
|
186
209
|
return null;
|
|
187
|
-
}, [emulators?.auth, authEnabled]);
|
|
210
|
+
}, [emulators?.auth, authEnabled, internalFirebase]);
|
|
188
211
|
|
|
189
|
-
const
|
|
190
|
-
if (
|
|
191
|
-
|
|
212
|
+
const internalAnalytics = useMemo(() => {
|
|
213
|
+
if (
|
|
214
|
+
analyticsEnabled &&
|
|
215
|
+
options.measurementId &&
|
|
216
|
+
(typeof window !== "undefined" || platform === "ReactNative")
|
|
217
|
+
) {
|
|
218
|
+
return internalFirebase.analytics();
|
|
192
219
|
}
|
|
193
220
|
return null;
|
|
194
|
-
}, [analyticsEnabled, options.measurementId]);
|
|
221
|
+
}, [analyticsEnabled, options.measurementId, internalFirebase]);
|
|
195
222
|
|
|
196
|
-
const
|
|
197
|
-
if (remoteConfigEnabled && typeof window !== "undefined") {
|
|
198
|
-
const localRemoteConfig =
|
|
223
|
+
const internalRemoteConfig = useMemo(() => {
|
|
224
|
+
if (remoteConfigEnabled && (typeof window !== "undefined" || platform === "ReactNative")) {
|
|
225
|
+
const localRemoteConfig = internalFirebase.remoteConfig();
|
|
199
226
|
if (remoteConfigSettings) {
|
|
200
|
-
localRemoteConfig.settings.
|
|
227
|
+
localRemoteConfig.settings.fetchTimeMillis = remoteConfigSettings.fetchTimeMillis;
|
|
201
228
|
localRemoteConfig.settings.minimumFetchIntervalMillis = remoteConfigSettings.minimumFetchIntervalMillis;
|
|
202
229
|
localRemoteConfig.defaultConfig = remoteConfigDefaults;
|
|
203
230
|
}
|
|
204
231
|
return localRemoteConfig;
|
|
205
232
|
}
|
|
206
233
|
return null;
|
|
207
|
-
}, [remoteConfigEnabled]);
|
|
234
|
+
}, [remoteConfigEnabled, remoteConfigSettings, internalFirebase]);
|
|
208
235
|
|
|
209
236
|
const contextValue = useMemo(
|
|
210
237
|
() => ({
|
|
211
|
-
firebase,
|
|
212
|
-
auth,
|
|
213
|
-
analytics,
|
|
214
|
-
firestore,
|
|
215
|
-
remoteConfig
|
|
238
|
+
firebase: internalFirebase,
|
|
239
|
+
auth: internalAuth,
|
|
240
|
+
analytics: internalAnalytics,
|
|
241
|
+
firestore: internalFirestore,
|
|
242
|
+
remoteConfig: internalRemoteConfig
|
|
216
243
|
}),
|
|
217
|
-
[
|
|
244
|
+
[internalFirebase, internalAuth, internalAnalytics, internalFirestore, internalRemoteConfig]
|
|
218
245
|
);
|
|
219
246
|
|
|
220
247
|
useEffect(() => {
|
|
221
248
|
if (contextValue.analytics) {
|
|
222
|
-
setAnalyticsCollectionEnabled(contextValue.analytics, consentSettings?.analytics_storage
|
|
249
|
+
setAnalyticsCollectionEnabled(contextValue.analytics, !!consentSettings?.analytics_storage);
|
|
223
250
|
}
|
|
224
251
|
}, [consentSettings]);
|
|
225
252
|
|
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import {
|
|
3
|
-
DocumentData,
|
|
4
|
-
addDoc,
|
|
5
|
-
WithFieldValue,
|
|
6
|
-
CollectionReference,
|
|
7
|
-
getDoc,
|
|
8
|
-
FirestoreDataConverter
|
|
9
|
-
} from "firebase/firestore";
|
|
2
|
+
import { FirebaseFirestoreTypes, addDoc, WithFieldValue, getDoc } from "@react-native-firebase/firestore";
|
|
10
3
|
|
|
11
|
-
import {
|
|
4
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
12
5
|
import { useMemo } from "react";
|
|
13
6
|
|
|
14
7
|
export type UseAddDocMutationValues<AppModelType> = {
|
|
@@ -16,14 +9,17 @@ export type UseAddDocMutationValues<AppModelType> = {
|
|
|
16
9
|
};
|
|
17
10
|
|
|
18
11
|
export type UseAddDocMutationOptions<
|
|
19
|
-
AppModelType extends DocumentData = DocumentData,
|
|
20
|
-
DbModelType extends DocumentData = DocumentData,
|
|
12
|
+
AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData,
|
|
21
13
|
TContext = unknown
|
|
22
14
|
> = {
|
|
23
|
-
reference: CollectionReference<AppModelType
|
|
24
|
-
converter?: FirestoreDataConverter<AppModelType, DbModelType>;
|
|
15
|
+
reference: FirebaseFirestoreTypes.CollectionReference<AppModelType>;
|
|
25
16
|
options?: Omit<
|
|
26
|
-
UseMutationOptions<
|
|
17
|
+
UseMutationOptions<
|
|
18
|
+
AppModelType,
|
|
19
|
+
ReactNativeFirebase.NativeFirebaseError,
|
|
20
|
+
UseAddDocMutationValues<AppModelType>,
|
|
21
|
+
TContext
|
|
22
|
+
>,
|
|
27
23
|
"mutationFn" | "mutationKey"
|
|
28
24
|
>;
|
|
29
25
|
};
|
|
@@ -33,28 +29,25 @@ export type UseAddDocMutationOptions<
|
|
|
33
29
|
* It handles addition and optional conversion of the document data in Firestore.
|
|
34
30
|
*
|
|
35
31
|
* @param {Object} options - Options for the mutation hook
|
|
36
|
-
* @param {FirebaseFirestore.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
|
|
37
|
-
* @param {FirebaseFirestore.FirestoreDataConverter<DbModelType>} [options.converter] - Optional data converter for reading and writing Firestore documents.
|
|
32
|
+
* @param {FirebaseFirestore.FirebaseFirestoreTypes.CollectionReference<AppModelType>} options.reference - Firestore collection reference where the document should be added.
|
|
38
33
|
* @param {UseMutationOptions<AppModelType, Error, { data: DbModelType }, TContext>} [options.options={}] - Optional configuration for the mutation.
|
|
39
34
|
*
|
|
40
35
|
* @returns {UseMutationResult<AppModelType, Error, { data: DbModelType }, TContext>} The mutation hook result containing status, error, and data of the mutation process.
|
|
41
36
|
*/
|
|
42
37
|
export const useAddDocMutation = <
|
|
43
|
-
AppModelType extends DocumentData = DocumentData,
|
|
44
|
-
DbModelType extends DocumentData = DocumentData,
|
|
38
|
+
AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData,
|
|
45
39
|
TContext = unknown
|
|
46
40
|
>({
|
|
47
41
|
reference,
|
|
48
|
-
converter,
|
|
49
42
|
options = {}
|
|
50
|
-
}: UseAddDocMutationOptions<AppModelType,
|
|
43
|
+
}: UseAddDocMutationOptions<AppModelType, TContext>) => {
|
|
51
44
|
const mutationKey = useMemo(() => [reference.path], [reference.path]);
|
|
52
45
|
|
|
53
46
|
return useMutation({
|
|
54
47
|
...options,
|
|
55
48
|
mutationFn: async ({ data }) => {
|
|
56
|
-
const docRef = await addDoc<AppModelType
|
|
57
|
-
const docSnap = await getDoc(
|
|
49
|
+
const docRef = await addDoc<AppModelType>(reference, data);
|
|
50
|
+
const docSnap = await getDoc(docRef);
|
|
58
51
|
return docSnap.data() as AppModelType;
|
|
59
52
|
},
|
|
60
53
|
mutationKey
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { useMutation, UseMutationOptions } from "@tanstack/react-query";
|
|
2
|
-
import { writeBatch,
|
|
2
|
+
import { writeBatch, FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { ReactNativeFirebase } from "@react-native-firebase/app";
|
|
5
5
|
import { useFirestore } from "./useFirestore";
|
|
6
6
|
|
|
7
|
-
export type UseBatchWriteVariables = (batch: WriteBatch) => Promise<void> | void;
|
|
7
|
+
export type UseBatchWriteVariables = (batch: FirebaseFirestoreTypes.WriteBatch) => Promise<void> | void;
|
|
8
8
|
|
|
9
9
|
export type UseBatchWriteOptions<TContext = unknown> = {
|
|
10
|
-
options?: Omit<
|
|
10
|
+
options?: Omit<
|
|
11
|
+
UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseBatchWriteVariables, TContext>,
|
|
12
|
+
"mutationFn"
|
|
13
|
+
>;
|
|
11
14
|
};
|
|
12
15
|
|
|
13
16
|
/**
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import { collection,
|
|
1
|
+
import { collection, FirebaseFirestoreTypes } from "@react-native-firebase/firestore";
|
|
2
2
|
|
|
3
3
|
import { useMemo } from "react";
|
|
4
4
|
import { useFirestore } from "./useFirestore";
|
|
5
5
|
|
|
6
|
-
export type UseCollectionReferenceOptions<
|
|
7
|
-
|
|
6
|
+
export type UseCollectionReferenceOptions<
|
|
7
|
+
AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData
|
|
8
|
+
> = {
|
|
9
|
+
reference?:
|
|
10
|
+
| FirebaseFirestoreTypes.CollectionReference<AppModelType>
|
|
11
|
+
| FirebaseFirestoreTypes.DocumentReference<AppModelType>;
|
|
8
12
|
path: string;
|
|
9
13
|
pathSegments?: string[];
|
|
10
14
|
};
|
|
@@ -14,24 +18,24 @@ export type UseCollectionReferenceOptions<AppModelType, DbModelType extends Docu
|
|
|
14
18
|
*
|
|
15
19
|
* This hook utilizes useMemo for optimization, ensuring the collection reference is recalculated only when its dependencies change.
|
|
16
20
|
*
|
|
17
|
-
* @param {UseCollectionReferenceOptions<AppModelType
|
|
21
|
+
* @param {UseCollectionReferenceOptions<AppModelType>} options - The options including path, reference, and pathSegments to construct the Firestore collection reference.
|
|
18
22
|
* @param {string} options.path - The base path for the collection.
|
|
19
23
|
* @param {FirestoreReference} options.reference - An optional Firestore reference object that should be of type "collection".
|
|
20
24
|
* @param {string[]} options.pathSegments - Additional path segments to append to the base path.
|
|
21
25
|
* @returns {CollectionReference} A Firestore collection reference constructed using the specified path, reference, and path segments.
|
|
22
26
|
*/
|
|
23
|
-
export const useCollectionReference = <
|
|
27
|
+
export const useCollectionReference = <
|
|
28
|
+
AppModelType extends FirebaseFirestoreTypes.DocumentData = FirebaseFirestoreTypes.DocumentData
|
|
29
|
+
>({
|
|
24
30
|
path,
|
|
25
31
|
reference,
|
|
26
32
|
pathSegments
|
|
27
|
-
}: UseCollectionReferenceOptions<AppModelType
|
|
33
|
+
}: UseCollectionReferenceOptions<AppModelType>) => {
|
|
28
34
|
const db = useFirestore();
|
|
29
35
|
|
|
30
36
|
return useMemo(() => {
|
|
31
37
|
return !reference
|
|
32
38
|
? collection(db, path || "", ...(pathSegments || []))
|
|
33
|
-
: reference
|
|
34
|
-
? collection(reference, path, ...(pathSegments || []))
|
|
35
|
-
: collection(reference, path, ...(pathSegments || []));
|
|
39
|
+
: collection(reference, path, ...(pathSegments || []));
|
|
36
40
|
}, [path, reference?.path, pathSegments]);
|
|
37
41
|
};
|