react-query-firebase 2.7.1 → 2.9.0

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 (53) hide show
  1. package/package.json +14 -14
  2. package/react-native/auth/index.d.ts +4 -2
  3. package/react-native/auth/index.js +4 -2
  4. package/react-native/auth/index.ts +4 -2
  5. package/react-native/auth/mutation-keys.d.ts +1 -1
  6. package/react-native/auth/mutation-keys.js +1 -1
  7. package/react-native/auth/mutation-keys.ts +1 -1
  8. package/react-native/auth/useAppleAuthProviderCredential.d.ts +24 -0
  9. package/react-native/auth/useAppleAuthProviderCredential.js +24 -0
  10. package/react-native/auth/useAppleAuthProviderCredential.ts +31 -0
  11. package/react-native/auth/useEmailAuthProviderCredential.d.ts +25 -0
  12. package/react-native/auth/useEmailAuthProviderCredential.js +30 -0
  13. package/react-native/auth/useEmailAuthProviderCredential.ts +38 -0
  14. package/react-native/auth/useFacebookAuthProviderCredential.d.ts +24 -0
  15. package/react-native/auth/useFacebookAuthProviderCredential.js +24 -0
  16. package/react-native/auth/useFacebookAuthProviderCredential.ts +31 -0
  17. package/react-native/auth/useLinkWithCredentialMutation.d.ts +14 -0
  18. package/react-native/auth/useLinkWithCredentialMutation.js +16 -0
  19. package/react-native/auth/useLinkWithCredentialMutation.ts +35 -0
  20. package/react-native/firestore/useAddDocMutation.ts +2 -2
  21. package/react-native/firestore/useCountQuery.ts +1 -1
  22. package/react-native/firestore/useInfiniteQuery.ts +5 -2
  23. package/react-native/firestore/useQuery.ts +2 -2
  24. package/web/auth/index.d.ts +4 -2
  25. package/web/auth/index.js +4 -2
  26. package/web/auth/index.ts +4 -2
  27. package/web/auth/mutation-keys.d.ts +1 -1
  28. package/web/auth/mutation-keys.js +1 -1
  29. package/web/auth/mutation-keys.ts +1 -1
  30. package/web/auth/useAppleAuthProviderCredential.d.ts +24 -0
  31. package/web/auth/useAppleAuthProviderCredential.js +25 -0
  32. package/web/auth/useAppleAuthProviderCredential.ts +32 -0
  33. package/web/auth/useEmailAuthProviderCredential.d.ts +25 -0
  34. package/web/auth/useEmailAuthProviderCredential.js +30 -0
  35. package/web/auth/useEmailAuthProviderCredential.ts +38 -0
  36. package/web/auth/useFacebookAuthProviderCredential.d.ts +24 -0
  37. package/web/auth/useFacebookAuthProviderCredential.js +24 -0
  38. package/web/auth/useFacebookAuthProviderCredential.ts +31 -0
  39. package/web/auth/useLinkWithCredentialMutation.d.ts +14 -0
  40. package/web/auth/useLinkWithCredentialMutation.js +16 -0
  41. package/web/auth/useLinkWithCredentialMutation.ts +30 -0
  42. package/react-native/auth/useAuthProvider.d.ts +0 -18
  43. package/react-native/auth/useAuthProvider.js +0 -35
  44. package/react-native/auth/useAuthProvider.ts +0 -45
  45. package/react-native/auth/useLinkWithRedirect.d.ts +0 -15
  46. package/react-native/auth/useLinkWithRedirect.js +0 -16
  47. package/react-native/auth/useLinkWithRedirect.ts +0 -36
  48. package/web/auth/useAuthProvider.d.ts +0 -19
  49. package/web/auth/useAuthProvider.js +0 -35
  50. package/web/auth/useAuthProvider.ts +0 -45
  51. package/web/auth/useLinkWithRedirect.d.ts +0 -15
  52. package/web/auth/useLinkWithRedirect.js +0 -16
  53. package/web/auth/useLinkWithRedirect.ts +0 -31
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "@react-native-firebase/firestore": "^22.x.x",
13
13
  "@react-native-firebase/installations": "^22.x.x",
14
14
  "@react-native-firebase/remote-config": "^22.x.x",
15
- "@tanstack/react-query": "^5.x.x",
15
+ "@tanstack/react-query": "^5.83.0",
16
16
  "firebase": "^11.x.x",
17
17
  "react": "^18.x.x || ^19.x.x"
18
18
  },
@@ -24,22 +24,22 @@
24
24
  "@laverve/eslint-utils": "^5.3.1",
25
25
  "@react-native-firebase/analytics": "^22.2.1",
26
26
  "@react-native-firebase/app": "^22.2.1",
27
- "@react-native-firebase/auth": "^22.2.1",
28
- "@react-native-firebase/crashlytics": "^22.2.1",
29
- "@react-native-firebase/firestore": "^22.2.1",
30
- "@react-native-firebase/installations": "^22.2.1",
31
- "@react-native-firebase/remote-config": "^22.2.1",
32
- "@types/react": "^19.1.7",
27
+ "@react-native-firebase/auth": "^22.4.0",
28
+ "@react-native-firebase/crashlytics": "^22.4.0",
29
+ "@react-native-firebase/firestore": "^22.4.0",
30
+ "@react-native-firebase/installations": "^22.4.0",
31
+ "@react-native-firebase/remote-config": "^22.4.0",
32
+ "@types/react": "^19.1.8",
33
+ "firebase": "^11.9.0",
33
34
  "husky": "^9.1.7",
34
- "lint-staged": "^16.1.0",
35
- "prettier": "^3.5.3",
35
+ "lint-staged": "^16.1.2",
36
+ "prettier": "^3.6.2",
36
37
  "react": "^19.1.0",
37
- "typedoc": "^0.28.5",
38
- "typedoc-plugin-markdown": "^4.6.4",
38
+ "typedoc": "^0.28.7",
39
+ "typedoc-plugin-markdown": "^4.7.1",
39
40
  "typedoc-vitepress-theme": "^1.1.2",
40
41
  "typescript": "^5.8.3",
41
- "vitepress": "^1.6.3",
42
- "firebase": "^11.9.0"
42
+ "vitepress": "^1.6.3"
43
43
  },
44
44
  "homepage": "https://github.com/vpishuk/react-query-firebase",
45
45
  "keywords": [
@@ -74,5 +74,5 @@
74
74
  "docs:build": "vitepress build docs",
75
75
  "docs:preview": "vitepress preview docs"
76
76
  },
77
- "version": "2.7.1"
77
+ "version": "2.9.0"
78
78
  }
@@ -12,5 +12,7 @@ export * from "./useReauthenticateWitCredentialMutation";
12
12
  export * from "./useReauthenticateWitRedirectMutation";
13
13
  export * from "./useAuthStateReady";
14
14
  export * from "./useSignInAnonymouslyMutation";
15
- export * from "./useAuthProvider";
16
- export * from "./useLinkWithRedirect";
15
+ export * from "./useEmailAuthProviderCredential";
16
+ export * from "./useFacebookAuthProviderCredential";
17
+ export * from "./useAppleAuthProviderCredential";
18
+ export * from "./useLinkWithCredentialMutation";
@@ -12,5 +12,7 @@ export * from "./useReauthenticateWitCredentialMutation";
12
12
  export * from "./useReauthenticateWitRedirectMutation";
13
13
  export * from "./useAuthStateReady";
14
14
  export * from "./useSignInAnonymouslyMutation";
15
- export * from "./useAuthProvider";
16
- export * from "./useLinkWithRedirect";
15
+ export * from "./useEmailAuthProviderCredential";
16
+ export * from "./useFacebookAuthProviderCredential";
17
+ export * from "./useAppleAuthProviderCredential";
18
+ export * from "./useLinkWithCredentialMutation";
@@ -12,5 +12,7 @@ export * from "./useReauthenticateWitCredentialMutation";
12
12
  export * from "./useReauthenticateWitRedirectMutation";
13
13
  export * from "./useAuthStateReady";
14
14
  export * from "./useSignInAnonymouslyMutation";
15
- export * from "./useAuthProvider";
16
- export * from "./useLinkWithRedirect";
15
+ export * from "./useEmailAuthProviderCredential";
16
+ export * from "./useFacebookAuthProviderCredential";
17
+ export * from "./useAppleAuthProviderCredential";
18
+ export * from "./useLinkWithCredentialMutation";
@@ -3,7 +3,7 @@ export declare const SEND_EMAIL_VERIFICATION_MUTATION_KEY: readonly ["FIREBASE",
3
3
  export declare const SIGN_IN_ANONYMOUSLY_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_ANONYMOUSLY_MUTATION"];
4
4
  export declare const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"];
5
5
  export declare const SIGN_IN_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
6
- export declare const LINK_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "LINK_WITH_REDIRECT_MUTATION"];
6
+ export declare const LINK_WITH_CREDENTIAL_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "LINK_WITH_CREDENTIAL_MUTATION"];
7
7
  export declare const SIGN_OUT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_OUT"];
8
8
  export declare const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
9
9
  export declare const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_CREDENTIAL"];
@@ -11,7 +11,7 @@ export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
11
11
  "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"
12
12
  ];
13
13
  export const SIGN_IN_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
14
- export const LINK_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "LINK_WITH_REDIRECT_MUTATION"];
14
+ export const LINK_WITH_CREDENTIAL_MUTATION_KEY = ["FIREBASE", "AUTH", "LINK_WITH_CREDENTIAL_MUTATION"];
15
15
  export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"];
16
16
  export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
17
17
  export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
@@ -11,7 +11,7 @@ export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
11
11
  "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"
12
12
  ] as const;
13
13
  export const SIGN_IN_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"] as const;
14
- export const LINK_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "LINK_WITH_REDIRECT_MUTATION"] as const;
14
+ export const LINK_WITH_CREDENTIAL_MUTATION_KEY = ["FIREBASE", "AUTH", "LINK_WITH_CREDENTIAL_MUTATION"] as const;
15
15
  export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"] as const;
16
16
  export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"] as const;
17
17
  export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
@@ -0,0 +1,24 @@
1
+ import { FirebaseAuthTypes } from "@react-native-firebase/auth";
2
+ type Credential = {
3
+ token: string;
4
+ nonce: string;
5
+ };
6
+ /**
7
+ * A custom hook that returns an auth credential for facebook.
8
+ *
9
+ * @group Hook
10
+ * @param {AuthProvider} provider alas of a provider
11
+ *
12
+ * @returns {AuthCredential}
13
+ *
14
+ * @example
15
+ * ```jsx
16
+ * export const MyComponent = () => {
17
+ * const getCredential = useAppleAuthProviderCredential();
18
+ * // ...
19
+ * getCredential({token, nonce: ''})
20
+ * };
21
+ * ```
22
+ */
23
+ export declare const useAppleAuthProviderCredential: () => (credential: Credential) => FirebaseAuthTypes.AuthCredential;
24
+ export {};
@@ -0,0 +1,24 @@
1
+ import { AppleAuthProvider } from "@react-native-firebase/auth";
2
+ import { useCallback } from "react";
3
+ /**
4
+ * A custom hook that returns an auth credential for facebook.
5
+ *
6
+ * @group Hook
7
+ * @param {AuthProvider} provider alas of a provider
8
+ *
9
+ * @returns {AuthCredential}
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * export const MyComponent = () => {
14
+ * const getCredential = useAppleAuthProviderCredential();
15
+ * // ...
16
+ * getCredential({token, nonce: ''})
17
+ * };
18
+ * ```
19
+ */
20
+ export const useAppleAuthProviderCredential = () => {
21
+ return useCallback((credential) => {
22
+ return AppleAuthProvider.credential(credential.token, credential.nonce);
23
+ }, []);
24
+ };
@@ -0,0 +1,31 @@
1
+ import { AppleAuthProvider, FirebaseAuthTypes } from "@react-native-firebase/auth";
2
+ import { useCallback } from "react";
3
+
4
+ type Credential = {
5
+ token: string;
6
+ nonce: string;
7
+ };
8
+
9
+ /**
10
+ * A custom hook that returns an auth credential for facebook.
11
+ *
12
+ * @group Hook
13
+ * @param {AuthProvider} provider alas of a provider
14
+ *
15
+ * @returns {AuthCredential}
16
+ *
17
+ * @example
18
+ * ```jsx
19
+ * export const MyComponent = () => {
20
+ * const getCredential = useAppleAuthProviderCredential();
21
+ * // ...
22
+ * getCredential({token, nonce: ''})
23
+ * };
24
+ * ```
25
+ */
26
+
27
+ export const useAppleAuthProviderCredential = () => {
28
+ return useCallback((credential: Credential): FirebaseAuthTypes.AuthCredential => {
29
+ return AppleAuthProvider.credential(credential.token, credential.nonce);
30
+ }, []);
31
+ };
@@ -0,0 +1,25 @@
1
+ import { FirebaseAuthTypes } from "@react-native-firebase/auth";
2
+ type Credential = {
3
+ email: string;
4
+ password?: string;
5
+ emailLink?: string;
6
+ };
7
+ /**
8
+ * A custom hook that returns an auth credential for email.
9
+ *
10
+ * @group Hook
11
+ * @param {AuthProvider} provider alas of a provider
12
+ *
13
+ * @returns {AuthCredential}
14
+ *
15
+ * @example
16
+ * ```jsx
17
+ * export const MyComponent = () => {
18
+ * const getCredential = useEmailAuthProviderCredential();
19
+ * // ...
20
+ * getCredential({email, password})
21
+ * };
22
+ * ```
23
+ */
24
+ export declare const useEmailAuthProviderCredential: () => (credential: Credential) => FirebaseAuthTypes.AuthCredential;
25
+ export {};
@@ -0,0 +1,30 @@
1
+ import { EmailAuthProvider } from "@react-native-firebase/auth";
2
+ import { useCallback } from "react";
3
+ /**
4
+ * A custom hook that returns an auth credential for email.
5
+ *
6
+ * @group Hook
7
+ * @param {AuthProvider} provider alas of a provider
8
+ *
9
+ * @returns {AuthCredential}
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * export const MyComponent = () => {
14
+ * const getCredential = useEmailAuthProviderCredential();
15
+ * // ...
16
+ * getCredential({email, password})
17
+ * };
18
+ * ```
19
+ */
20
+ export const useEmailAuthProviderCredential = () => {
21
+ return useCallback((credential) => {
22
+ if (credential.password) {
23
+ return EmailAuthProvider.credential(credential.email, credential.password);
24
+ }
25
+ if (credential.emailLink) {
26
+ return EmailAuthProvider.credentialWithLink(credential.email, credential.emailLink);
27
+ }
28
+ throw new Error("One of: password or emailLink must be provided");
29
+ }, []);
30
+ };
@@ -0,0 +1,38 @@
1
+ import { EmailAuthProvider, FirebaseAuthTypes } from "@react-native-firebase/auth";
2
+ import { useCallback } from "react";
3
+
4
+ type Credential = {
5
+ email: string;
6
+ password?: string;
7
+ emailLink?: string;
8
+ };
9
+
10
+ /**
11
+ * A custom hook that returns an auth credential for email.
12
+ *
13
+ * @group Hook
14
+ * @param {AuthProvider} provider alas of a provider
15
+ *
16
+ * @returns {AuthCredential}
17
+ *
18
+ * @example
19
+ * ```jsx
20
+ * export const MyComponent = () => {
21
+ * const getCredential = useEmailAuthProviderCredential();
22
+ * // ...
23
+ * getCredential({email, password})
24
+ * };
25
+ * ```
26
+ */
27
+
28
+ export const useEmailAuthProviderCredential = () => {
29
+ return useCallback((credential: Credential): FirebaseAuthTypes.AuthCredential => {
30
+ if (credential.password) {
31
+ return EmailAuthProvider.credential(credential.email, credential.password);
32
+ }
33
+ if (credential.emailLink) {
34
+ return EmailAuthProvider.credentialWithLink(credential.email, credential.emailLink);
35
+ }
36
+ throw new Error("One of: password or emailLink must be provided");
37
+ }, []);
38
+ };
@@ -0,0 +1,24 @@
1
+ import { FirebaseAuthTypes } from "@react-native-firebase/auth";
2
+ type Credential = {
3
+ token: string;
4
+ nonce: string;
5
+ };
6
+ /**
7
+ * A custom hook that returns an auth credential for facebook.
8
+ *
9
+ * @group Hook
10
+ * @param {AuthProvider} provider alas of a provider
11
+ *
12
+ * @returns {AuthCredential}
13
+ *
14
+ * @example
15
+ * ```jsx
16
+ * export const MyComponent = () => {
17
+ * const getCredential = useFacebookAuthProviderCredential();
18
+ * // ...
19
+ * getCredential({token, nonce})
20
+ * };
21
+ * ```
22
+ */
23
+ export declare const useFacebookAuthProviderCredential: () => (credential: Credential) => FirebaseAuthTypes.AuthCredential;
24
+ export {};
@@ -0,0 +1,24 @@
1
+ import { FacebookAuthProvider } from "@react-native-firebase/auth";
2
+ import { useCallback } from "react";
3
+ /**
4
+ * A custom hook that returns an auth credential for facebook.
5
+ *
6
+ * @group Hook
7
+ * @param {AuthProvider} provider alas of a provider
8
+ *
9
+ * @returns {AuthCredential}
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * export const MyComponent = () => {
14
+ * const getCredential = useFacebookAuthProviderCredential();
15
+ * // ...
16
+ * getCredential({token, nonce})
17
+ * };
18
+ * ```
19
+ */
20
+ export const useFacebookAuthProviderCredential = () => {
21
+ return useCallback((credential) => {
22
+ return FacebookAuthProvider.credential(credential.token, credential.nonce);
23
+ }, []);
24
+ };
@@ -0,0 +1,31 @@
1
+ import { FacebookAuthProvider, FirebaseAuthTypes } from "@react-native-firebase/auth";
2
+ import { useCallback } from "react";
3
+
4
+ type Credential = {
5
+ token: string;
6
+ nonce: string;
7
+ };
8
+
9
+ /**
10
+ * A custom hook that returns an auth credential for facebook.
11
+ *
12
+ * @group Hook
13
+ * @param {AuthProvider} provider alas of a provider
14
+ *
15
+ * @returns {AuthCredential}
16
+ *
17
+ * @example
18
+ * ```jsx
19
+ * export const MyComponent = () => {
20
+ * const getCredential = useFacebookAuthProviderCredential();
21
+ * // ...
22
+ * getCredential({token, nonce})
23
+ * };
24
+ * ```
25
+ */
26
+
27
+ export const useFacebookAuthProviderCredential = () => {
28
+ return useCallback((credential: Credential): FirebaseAuthTypes.AuthCredential => {
29
+ return FacebookAuthProvider.credential(credential.token, credential.nonce);
30
+ }, []);
31
+ };
@@ -0,0 +1,14 @@
1
+ import { UseMutationOptions } from "@tanstack/react-query";
2
+ import { FirebaseAuthTypes } from "@react-native-firebase/auth";
3
+ import { ReactNativeFirebase } from "@react-native-firebase/app";
4
+ export type UseLinkWitRedirectMutationVariables = {
5
+ user: FirebaseAuthTypes.User;
6
+ credential: FirebaseAuthTypes.AuthCredential;
7
+ };
8
+ /**
9
+ * Custom hook for handling linking of Firebase account to auth provider using credential
10
+ * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
11
+ * @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
12
+ * @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
13
+ */
14
+ export declare const useLinkWithCredentialMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>;
@@ -0,0 +1,16 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+ import { linkWithCredential } from "@react-native-firebase/auth";
3
+ import { LINK_WITH_CREDENTIAL_MUTATION_KEY } from "./mutation-keys";
4
+ /**
5
+ * Custom hook for handling linking of Firebase account to auth provider using credential
6
+ * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
7
+ * @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
8
+ * @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
9
+ */
10
+ export const useLinkWithCredentialMutation = (options = {}) => {
11
+ return useMutation({
12
+ ...options,
13
+ mutationFn: async ({ user, credential }) => linkWithCredential(user, credential),
14
+ mutationKey: LINK_WITH_CREDENTIAL_MUTATION_KEY
15
+ });
16
+ };
@@ -0,0 +1,35 @@
1
+ import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
+ import { linkWithCredential, FirebaseAuthTypes } from "@react-native-firebase/auth";
3
+
4
+ import { LINK_WITH_CREDENTIAL_MUTATION_KEY } from "./mutation-keys";
5
+ import { ReactNativeFirebase } from "@react-native-firebase/app";
6
+
7
+ export type UseLinkWitRedirectMutationVariables = {
8
+ user: FirebaseAuthTypes.User;
9
+ credential: FirebaseAuthTypes.AuthCredential;
10
+ };
11
+
12
+ /**
13
+ * Custom hook for handling linking of Firebase account to auth provider using credential
14
+ * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
15
+ * @param {Omit<UseMutationOptions<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
16
+ * @returns {UseMutationResult<FirebaseAuthTypes.UserCredential, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
17
+ */
18
+ export const useLinkWithCredentialMutation = <TContext = unknown>(
19
+ options: Omit<
20
+ UseMutationOptions<
21
+ FirebaseAuthTypes.UserCredential,
22
+ ReactNativeFirebase.NativeFirebaseError,
23
+ UseLinkWitRedirectMutationVariables,
24
+ TContext
25
+ >,
26
+ "mutationKey" | "mutationFn"
27
+ > = {}
28
+ ) => {
29
+ return useMutation({
30
+ ...options,
31
+ mutationFn: async ({ user, credential }: UseLinkWitRedirectMutationVariables) =>
32
+ linkWithCredential(user, credential),
33
+ mutationKey: LINK_WITH_CREDENTIAL_MUTATION_KEY
34
+ });
35
+ };
@@ -72,9 +72,9 @@ export const useAddDocMutation = <AppModelType extends AppModel = AppModel, TCon
72
72
  mutationKey,
73
73
  ...options,
74
74
  mutationFn: async ({ data }) => {
75
- const docRef = await addDoc<AppModelType>(collectionReference, data);
75
+ const docRef = await addDoc<AppModelType, AppModelType>(collectionReference, data);
76
76
  const docSnap = await getDoc(docRef);
77
- return { ...docSnap.data(), uid: docRef.id } as AppModelType;
77
+ return { ...(docSnap.data() as AppModelType), uid: docRef.id } as AppModelType;
78
78
  }
79
79
  });
80
80
  };
@@ -73,7 +73,7 @@ export const useCountQuery = <AppModelType extends AppModel = AppModel>({
73
73
  queryFn: async () => {
74
74
  const queryToExecute = compositeFilter
75
75
  ? query(collectionReference, compositeFilter, ...(queryConstraints as QueryNonFilterConstraint[]))
76
- : query(collectionReference, ...queryConstraints);
76
+ : query(collectionReference, ...(queryConstraints as QueryConstraint[]));
77
77
 
78
78
  const querySnapshot = await getCountFromServer(queryToExecute);
79
79
  if (querySnapshot) {
@@ -96,9 +96,12 @@ export const useInfiniteQuery = <AppModelType extends AppModel = AppModel, TQuer
96
96
  const allQueryConstraints = [...queryConstraints, ...(pageParam ? [pageParam] : [])];
97
97
  const queryToExecute = compositeFilter
98
98
  ? query(collectionReference, compositeFilter, ...(allQueryConstraints as QueryNonFilterConstraint[]))
99
- : query(collectionReference, ...allQueryConstraints);
99
+ : query(collectionReference, ...(allQueryConstraints as QueryConstraint[]));
100
100
 
101
- const querySnapshot = await getDocs(queryToExecute);
101
+ const querySnapshot: FirebaseFirestoreTypes.QuerySnapshot<AppModelType> = await getDocs<
102
+ AppModelType,
103
+ AppModelType
104
+ >(queryToExecute);
102
105
  const docs: AppModelType[] = [];
103
106
 
104
107
  if (querySnapshot) {
@@ -73,9 +73,9 @@ export const useQuery = <AppModelType extends AppModel = AppModel>({
73
73
  queryFn: async () => {
74
74
  const queryToExecute = compositeFilter
75
75
  ? query(collectionReference, compositeFilter, ...(queryConstraints as QueryNonFilterConstraint[]))
76
- : query(collectionReference, ...queryConstraints);
76
+ : query(collectionReference, ...(queryConstraints as QueryConstraint[]));
77
77
 
78
- const querySnapshot = await getDocs(queryToExecute);
78
+ const querySnapshot: FirebaseFirestoreTypes.QuerySnapshot<AppModelType> = await getDocs(queryToExecute);
79
79
  const docs: AppModelType[] = [];
80
80
 
81
81
  if (querySnapshot) {
@@ -12,5 +12,7 @@ export * from "./useIdToken";
12
12
  export * from "./useReauthenticateWitCredentialMutation";
13
13
  export * from "./useReauthenticateWitRedirectMutation";
14
14
  export * from "./useSignInAnonymouslyMutation";
15
- export * from "./useAuthProvider";
16
- export * from "./useLinkWithRedirect";
15
+ export * from "./useEmailAuthProviderCredential";
16
+ export * from "./useFacebookAuthProviderCredential";
17
+ export * from "./useAppleAuthProviderCredential";
18
+ export * from "./useLinkWithCredentialMutation";
package/web/auth/index.js CHANGED
@@ -12,5 +12,7 @@ export * from "./useIdToken";
12
12
  export * from "./useReauthenticateWitCredentialMutation";
13
13
  export * from "./useReauthenticateWitRedirectMutation";
14
14
  export * from "./useSignInAnonymouslyMutation";
15
- export * from "./useAuthProvider";
16
- export * from "./useLinkWithRedirect";
15
+ export * from "./useEmailAuthProviderCredential";
16
+ export * from "./useFacebookAuthProviderCredential";
17
+ export * from "./useAppleAuthProviderCredential";
18
+ export * from "./useLinkWithCredentialMutation";
package/web/auth/index.ts CHANGED
@@ -12,5 +12,7 @@ export * from "./useIdToken";
12
12
  export * from "./useReauthenticateWitCredentialMutation";
13
13
  export * from "./useReauthenticateWitRedirectMutation";
14
14
  export * from "./useSignInAnonymouslyMutation";
15
- export * from "./useAuthProvider";
16
- export * from "./useLinkWithRedirect";
15
+ export * from "./useEmailAuthProviderCredential";
16
+ export * from "./useFacebookAuthProviderCredential";
17
+ export * from "./useAppleAuthProviderCredential";
18
+ export * from "./useLinkWithCredentialMutation";
@@ -3,7 +3,7 @@ export declare const SEND_EMAIL_VERIFICATION_MUTATION_KEY: readonly ["FIREBASE",
3
3
  export declare const SIGN_IN_ANONYMOUSLY_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_ANONYMOUSLY_MUTATION"];
4
4
  export declare const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"];
5
5
  export declare const SIGN_IN_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
6
- export declare const LINK_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "LINK_WITH_REDIRECT_MUTATION"];
6
+ export declare const LINK_WITH_CREDENTIAL_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "LINK_WITH_CREDENTIAL_MUTATION"];
7
7
  export declare const SIGN_OUT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_OUT"];
8
8
  export declare const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
9
9
  export declare const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_CREDENTIAL"];
@@ -11,7 +11,7 @@ export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
11
11
  "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"
12
12
  ];
13
13
  export const SIGN_IN_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"];
14
- export const LINK_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "LINK_WITH_REDIRECT_MUTATION"];
14
+ export const LINK_WITH_CREDENTIAL_MUTATION_KEY = ["FIREBASE", "AUTH", "LINK_WITH_CREDENTIAL_MUTATION"];
15
15
  export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"];
16
16
  export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
17
17
  export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
@@ -11,7 +11,7 @@ export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
11
11
  "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"
12
12
  ] as const;
13
13
  export const SIGN_IN_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_WITH_REDIRECT_MUTATION"] as const;
14
- export const LINK_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "LINK_WITH_REDIRECT_MUTATION"] as const;
14
+ export const LINK_WITH_CREDENTIAL_MUTATION_KEY = ["FIREBASE", "AUTH", "LINK_WITH_CREDENTIAL_MUTATION"] as const;
15
15
  export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"] as const;
16
16
  export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"] as const;
17
17
  export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
@@ -0,0 +1,24 @@
1
+ import { AuthCredential } from "firebase/auth";
2
+ type Credential = {
3
+ token: string;
4
+ nonce: string;
5
+ };
6
+ /**
7
+ * A custom hook that returns an auth credential for facebook.
8
+ *
9
+ * @group Hook
10
+ * @param {AuthProvider} provider alas of a provider
11
+ *
12
+ * @returns {AuthCredential}
13
+ *
14
+ * @example
15
+ * ```jsx
16
+ * export const MyComponent = () => {
17
+ * const getCredential = useAppleAuthProviderCredential();
18
+ * // ...
19
+ * getCredential({token, nonce: ''})
20
+ * };
21
+ * ```
22
+ */
23
+ export declare const useAppleAuthProviderCredential: () => (credential: Credential) => AuthCredential;
24
+ export {};
@@ -0,0 +1,25 @@
1
+ import { OAuthProvider } from "firebase/auth";
2
+ import { useCallback } from "react";
3
+ /**
4
+ * A custom hook that returns an auth credential for facebook.
5
+ *
6
+ * @group Hook
7
+ * @param {AuthProvider} provider alas of a provider
8
+ *
9
+ * @returns {AuthCredential}
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * export const MyComponent = () => {
14
+ * const getCredential = useAppleAuthProviderCredential();
15
+ * // ...
16
+ * getCredential({token, nonce: ''})
17
+ * };
18
+ * ```
19
+ */
20
+ export const useAppleAuthProviderCredential = () => {
21
+ return useCallback((credential) => {
22
+ const authProvider = new OAuthProvider("apple.com");
23
+ return authProvider.credential({ accessToken: credential.token, rawNonce: credential.nonce });
24
+ }, []);
25
+ };