react-query-firebase 2.10.0 → 2.11.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.
package/package.json CHANGED
@@ -74,5 +74,5 @@
74
74
  "docs:build": "vitepress build docs",
75
75
  "docs:preview": "vitepress preview docs"
76
76
  },
77
- "version": "2.10.0"
77
+ "version": "2.11.0"
78
78
  }
@@ -1,3 +1,4 @@
1
+ import { onAuthStateChanged } from "@react-native-firebase/auth";
1
2
  import { useAuth } from "./useAuth";
2
3
  import { useEffect, useState } from "react";
3
4
  /**
@@ -6,15 +7,15 @@ import { useEffect, useState } from "react";
6
7
  * @returns {Object|null} The current authenticated user object or null if no user is authenticated.
7
8
  */
8
9
  export const useCurrentUser = () => {
9
- const { onAuthStateChanged, currentUser: fbCurrentUser } = useAuth();
10
- const [currentUser, setCurrentUser] = useState(fbCurrentUser);
10
+ const firebaseAuth = useAuth();
11
+ const [currentUser, setCurrentUser] = useState(firebaseAuth.currentUser);
11
12
  useEffect(() => {
12
- const unsubscribe = onAuthStateChanged((user) => {
13
+ const unsubscribe = onAuthStateChanged(firebaseAuth, (user) => {
13
14
  setCurrentUser(user);
14
15
  });
15
16
  return () => {
16
17
  unsubscribe();
17
18
  };
18
- }, [currentUser?.uid, onAuthStateChanged]);
19
+ }, [firebaseAuth]);
19
20
  return currentUser;
20
21
  };
@@ -1,3 +1,4 @@
1
+ import { onAuthStateChanged } from "@react-native-firebase/auth";
1
2
  import { useAuth } from "./useAuth";
2
3
  import { useEffect, useState } from "react";
3
4
 
@@ -7,18 +8,19 @@ import { useEffect, useState } from "react";
7
8
  * @returns {Object|null} The current authenticated user object or null if no user is authenticated.
8
9
  */
9
10
  export const useCurrentUser = () => {
10
- const { onAuthStateChanged, currentUser: fbCurrentUser } = useAuth();
11
+ const firebaseAuth = useAuth();
11
12
 
12
- const [currentUser, setCurrentUser] = useState(fbCurrentUser);
13
+ const [currentUser, setCurrentUser] = useState(firebaseAuth.currentUser);
13
14
 
14
15
  useEffect(() => {
15
- const unsubscribe = onAuthStateChanged((user) => {
16
+ const unsubscribe = onAuthStateChanged(firebaseAuth, (user) => {
16
17
  setCurrentUser(user);
17
18
  });
19
+
18
20
  return () => {
19
21
  unsubscribe();
20
22
  };
21
- }, [currentUser?.uid, onAuthStateChanged]);
23
+ }, [firebaseAuth]);
22
24
 
23
25
  return currentUser;
24
26
  };
@@ -17,3 +17,4 @@ export * from "./useFacebookAuthProviderCredential";
17
17
  export * from "./useAppleAuthProviderCredential";
18
18
  export * from "./useLinkWithCredentialMutation";
19
19
  export * from "./useSignInWithCredentialMutation";
20
+ export * from "./useGetRedirectResultMutation";
package/web/auth/index.js CHANGED
@@ -17,3 +17,4 @@ export * from "./useFacebookAuthProviderCredential";
17
17
  export * from "./useAppleAuthProviderCredential";
18
18
  export * from "./useLinkWithCredentialMutation";
19
19
  export * from "./useSignInWithCredentialMutation";
20
+ export * from "./useGetRedirectResultMutation";
package/web/auth/index.ts CHANGED
@@ -17,3 +17,4 @@ export * from "./useFacebookAuthProviderCredential";
17
17
  export * from "./useAppleAuthProviderCredential";
18
18
  export * from "./useLinkWithCredentialMutation";
19
19
  export * from "./useSignInWithCredentialMutation";
20
+ export * from "./useGetRedirectResultMutation";
@@ -1,4 +1,5 @@
1
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 GET_REDIRECT_RESULT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "GET_REDIRECT_RESULT_MUTATION"];
2
3
  export declare const SEND_EMAIL_VERIFICATION_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"];
3
4
  export declare const SIGN_IN_ANONYMOUSLY_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_ANONYMOUSLY_MUTATION"];
4
5
  export declare const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION"];
@@ -3,6 +3,7 @@ export const CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
3
3
  "AUTH",
4
4
  "CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION"
5
5
  ];
6
+ export const GET_REDIRECT_RESULT_MUTATION_KEY = ["FIREBASE", "AUTH", "GET_REDIRECT_RESULT_MUTATION"];
6
7
  export const SEND_EMAIL_VERIFICATION_MUTATION_KEY = ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"];
7
8
  export const SIGN_IN_ANONYMOUSLY_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_ANONYMOUSLY_MUTATION"];
8
9
  export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
@@ -3,6 +3,7 @@ export const CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
3
3
  "AUTH",
4
4
  "CREATE_USER_WITH_EMAIL_AND_PASSWORD_MUTATION"
5
5
  ] as const;
6
+ export const GET_REDIRECT_RESULT_MUTATION_KEY = ["FIREBASE", "AUTH", "GET_REDIRECT_RESULT_MUTATION"] as const;
6
7
  export const SEND_EMAIL_VERIFICATION_MUTATION_KEY = ["FIREBASE", "AUTH", "SEND_EMAIL_VERIFICATION_MUTATION"] as const;
7
8
  export const SIGN_IN_ANONYMOUSLY_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_IN_ANONYMOUSLY_MUTATION"] as const;
8
9
  export const SIGN_IN_WITH_EMAIL_AND_PASSWORD_MUTATION_KEY = [
@@ -0,0 +1,11 @@
1
+ import { UseMutationOptions } from "@tanstack/react-query";
2
+ import { UserCredential } from "firebase/auth";
3
+ import { FirebaseError } from "firebase/app";
4
+ /**
5
+ * Custom hook to retrieve redirect result after sign in with redirect.
6
+ * This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
7
+ *
8
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, void, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
9
+ * @returns {UseMutationResult<UserCredential, FirebaseError, void, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
10
+ */
11
+ export declare const useGetRedirectResultMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<UserCredential | null, FirebaseError, void, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<UserCredential | null, FirebaseError, void, TContext>;
@@ -0,0 +1,19 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+ import { useAuth } from "./useAuth";
3
+ import { GET_REDIRECT_RESULT_MUTATION_KEY } from "./mutation-keys";
4
+ import { getRedirectResult } from "firebase/auth";
5
+ /**
6
+ * Custom hook to retrieve redirect result after sign in with redirect.
7
+ * This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
8
+ *
9
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, void, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
10
+ * @returns {UseMutationResult<UserCredential, FirebaseError, void, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
11
+ */
12
+ export const useGetRedirectResultMutation = (options = {}) => {
13
+ const firebaseAuth = useAuth();
14
+ return useMutation({
15
+ ...options,
16
+ mutationFn: async () => await getRedirectResult(firebaseAuth),
17
+ mutationKey: GET_REDIRECT_RESULT_MUTATION_KEY
18
+ });
19
+ };
@@ -0,0 +1,27 @@
1
+ import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
+ import { useAuth } from "./useAuth";
3
+ import { GET_REDIRECT_RESULT_MUTATION_KEY } from "./mutation-keys";
4
+ import { getRedirectResult, UserCredential } from "firebase/auth";
5
+ import { FirebaseError } from "firebase/app";
6
+
7
+ /**
8
+ * Custom hook to retrieve redirect result after sign in with redirect.
9
+ * This hook utilizes the `useMutation` functionality to support creating new user credentials asynchronously.
10
+ *
11
+ * @param {Omit<UseMutationOptions<UserCredential, FirebaseError, void, TContext>, "mutationKey" | "mutationFn">} options - Optional settings to customize the mutation behavior, excluding `mutationKey` and `mutationFn`.
12
+ * @returns {UseMutationResult<UserCredential, FirebaseError, void, TContext>} The result of the mutation which includes status, user credentials, and error information if any.
13
+ */
14
+ export const useGetRedirectResultMutation = <TContext = unknown>(
15
+ options: Omit<
16
+ UseMutationOptions<UserCredential | null, FirebaseError, void, TContext>,
17
+ "mutationKey" | "mutationFn"
18
+ > = {}
19
+ ) => {
20
+ const firebaseAuth = useAuth();
21
+
22
+ return useMutation({
23
+ ...options,
24
+ mutationFn: async () => await getRedirectResult(firebaseAuth),
25
+ mutationKey: GET_REDIRECT_RESULT_MUTATION_KEY
26
+ });
27
+ };