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
@@ -0,0 +1,32 @@
1
+ import { AuthCredential, OAuthProvider } from "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): AuthCredential => {
29
+ const authProvider = new OAuthProvider("apple.com");
30
+ return authProvider.credential({ accessToken: credential.token, rawNonce: credential.nonce });
31
+ }, []);
32
+ };
@@ -0,0 +1,25 @@
1
+ import { AuthCredential } from "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) => AuthCredential;
25
+ export {};
@@ -0,0 +1,30 @@
1
+ import { EmailAuthProvider } from "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, AuthCredential } from "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): 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 { 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 = useFacebookAuthProviderCredential();
18
+ * // ...
19
+ * getCredential({token, nonce: ''})
20
+ * };
21
+ * ```
22
+ */
23
+ export declare const useFacebookAuthProviderCredential: () => (credential: Credential) => AuthCredential;
24
+ export {};
@@ -0,0 +1,24 @@
1
+ import { FacebookAuthProvider } 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 = useFacebookAuthProviderCredential();
15
+ * // ...
16
+ * getCredential({token, nonce: ''})
17
+ * };
18
+ * ```
19
+ */
20
+ export const useFacebookAuthProviderCredential = () => {
21
+ return useCallback((credential) => {
22
+ return FacebookAuthProvider.credential(credential.token);
23
+ }, []);
24
+ };
@@ -0,0 +1,31 @@
1
+ import { FacebookAuthProvider, AuthCredential } from "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): AuthCredential => {
29
+ return FacebookAuthProvider.credential(credential.token);
30
+ }, []);
31
+ };
@@ -0,0 +1,14 @@
1
+ import { UseMutationOptions } from "@tanstack/react-query";
2
+ import { User, AuthCredential, UserCredential } from "firebase/auth";
3
+ import { FirebaseError } from "firebase/app";
4
+ export type UseLinkWitRedirectMutationVariables = {
5
+ user: User;
6
+ credential: 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<UserCredential, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
12
+ * @returns {UseMutationResult<UserCredential, FirebaseError, 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<UserCredential, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<UserCredential, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>;
@@ -0,0 +1,16 @@
1
+ import { useMutation } from "@tanstack/react-query";
2
+ import { linkWithCredential } from "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<UserCredential, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
8
+ * @returns {UseMutationResult<UserCredential, FirebaseError, 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,30 @@
1
+ import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
+ import { linkWithCredential, User, AuthCredential, UserCredential } from "firebase/auth";
3
+
4
+ import { LINK_WITH_CREDENTIAL_MUTATION_KEY } from "./mutation-keys";
5
+ import { FirebaseError } from "firebase/app";
6
+
7
+ export type UseLinkWitRedirectMutationVariables = {
8
+ user: User;
9
+ credential: 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<UserCredential, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
16
+ * @returns {UseMutationResult<UserCredential, FirebaseError, 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<UserCredential, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>,
21
+ "mutationKey" | "mutationFn"
22
+ > = {}
23
+ ) => {
24
+ return useMutation({
25
+ ...options,
26
+ mutationFn: async ({ user, credential }: UseLinkWitRedirectMutationVariables) =>
27
+ linkWithCredential(user, credential),
28
+ mutationKey: LINK_WITH_CREDENTIAL_MUTATION_KEY
29
+ });
30
+ };
@@ -1,18 +0,0 @@
1
- type AuthProvider = "google" | "facebook" | "email" | "github" | "twitter";
2
- /**
3
- * A custom hook that returns an auth provider by id.
4
- *
5
- * @group Hook
6
- * @param {AuthProvider} provider alas of a provider
7
- *
8
- * @returns {AuthProvider}
9
- *
10
- * @example
11
- * ```jsx
12
- * export const MyComponent = () => {
13
- * const authProvider = useAuthProvider('email');
14
- * };
15
- * ```
16
- */
17
- export declare const useAuthProvider: (provider: AuthProvider) => any;
18
- export {};
@@ -1,35 +0,0 @@
1
- import { EmailAuthProvider, FacebookAuthProvider, GithubAuthProvider, GoogleAuthProvider, TwitterAuthProvider } from "@react-native-firebase/auth";
2
- import { useMemo } from "react";
3
- /**
4
- * A custom hook that returns an auth provider by id.
5
- *
6
- * @group Hook
7
- * @param {AuthProvider} provider alas of a provider
8
- *
9
- * @returns {AuthProvider}
10
- *
11
- * @example
12
- * ```jsx
13
- * export const MyComponent = () => {
14
- * const authProvider = useAuthProvider('email');
15
- * };
16
- * ```
17
- */
18
- export const useAuthProvider = (provider) => {
19
- return useMemo(() => {
20
- switch (provider) {
21
- case "google":
22
- return new GoogleAuthProvider();
23
- case "email":
24
- return new EmailAuthProvider();
25
- case "facebook":
26
- return new FacebookAuthProvider();
27
- case "github":
28
- return new GithubAuthProvider();
29
- case "twitter":
30
- return new TwitterAuthProvider();
31
- default:
32
- throw new Error(`Auth provider ${provider} is not supported.`);
33
- }
34
- }, [provider]);
35
- };
@@ -1,45 +0,0 @@
1
- import {
2
- EmailAuthProvider,
3
- FacebookAuthProvider,
4
- GithubAuthProvider,
5
- GoogleAuthProvider,
6
- TwitterAuthProvider
7
- } from "@react-native-firebase/auth";
8
- import { useMemo } from "react";
9
-
10
- type AuthProvider = "google" | "facebook" | "email" | "github" | "twitter";
11
-
12
- /**
13
- * A custom hook that returns an auth provider by id.
14
- *
15
- * @group Hook
16
- * @param {AuthProvider} provider alas of a provider
17
- *
18
- * @returns {AuthProvider}
19
- *
20
- * @example
21
- * ```jsx
22
- * export const MyComponent = () => {
23
- * const authProvider = useAuthProvider('email');
24
- * };
25
- * ```
26
- */
27
-
28
- export const useAuthProvider = (provider: AuthProvider) => {
29
- return useMemo(() => {
30
- switch (provider) {
31
- case "google":
32
- return new GoogleAuthProvider();
33
- case "email":
34
- return new EmailAuthProvider();
35
- case "facebook":
36
- return new FacebookAuthProvider();
37
- case "github":
38
- return new GithubAuthProvider();
39
- case "twitter":
40
- return new TwitterAuthProvider();
41
- default:
42
- throw new Error(`Auth provider ${provider} is not supported.`);
43
- }
44
- }, [provider]);
45
- };
@@ -1,15 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { FirebaseAuthTypes, PopupRedirectResolver } from "@react-native-firebase/auth";
3
- import { ReactNativeFirebase } from "@react-native-firebase/app";
4
- export type UseLinkWitRedirectMutationVariables = {
5
- user: FirebaseAuthTypes.User;
6
- authProvider: FirebaseAuthTypes.AuthProvider;
7
- popupRedirectResolver?: PopupRedirectResolver;
8
- };
9
- /**
10
- * Custom hook for handling linking of Firebase account to auth provider
11
- * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
12
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
13
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
14
- */
15
- export declare const useLinkWitRedirectMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>;
@@ -1,16 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { linkWithRedirect } from "@react-native-firebase/auth";
3
- import { LINK_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
4
- /**
5
- * Custom hook for handling linking of Firebase account to auth provider
6
- * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
7
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
8
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
9
- */
10
- export const useLinkWitRedirectMutation = (options = {}) => {
11
- return useMutation({
12
- ...options,
13
- mutationFn: async ({ user, authProvider, popupRedirectResolver }) => linkWithRedirect(user, authProvider, popupRedirectResolver),
14
- mutationKey: LINK_WITH_REDIRECT_MUTATION_KEY
15
- });
16
- };
@@ -1,36 +0,0 @@
1
- import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
- import { linkWithRedirect, FirebaseAuthTypes, PopupRedirectResolver } from "@react-native-firebase/auth";
3
-
4
- import { LINK_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
5
- import { ReactNativeFirebase } from "@react-native-firebase/app";
6
-
7
- export type UseLinkWitRedirectMutationVariables = {
8
- user: FirebaseAuthTypes.User;
9
- authProvider: FirebaseAuthTypes.AuthProvider;
10
- popupRedirectResolver?: PopupRedirectResolver;
11
- };
12
-
13
- /**
14
- * Custom hook for handling linking of Firebase account to auth provider
15
- * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
16
- * @param {Omit<UseMutationOptions<void, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
17
- * @returns {UseMutationResult<void, ReactNativeFirebase.NativeFirebaseError, UseLinkWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
18
- */
19
- export const useLinkWitRedirectMutation = <TContext = unknown>(
20
- options: Omit<
21
- UseMutationOptions<
22
- void,
23
- ReactNativeFirebase.NativeFirebaseError,
24
- UseLinkWitRedirectMutationVariables,
25
- TContext
26
- >,
27
- "mutationKey" | "mutationFn"
28
- > = {}
29
- ) => {
30
- return useMutation({
31
- ...options,
32
- mutationFn: async ({ user, authProvider, popupRedirectResolver }: UseLinkWitRedirectMutationVariables) =>
33
- linkWithRedirect(user, authProvider, popupRedirectResolver),
34
- mutationKey: LINK_WITH_REDIRECT_MUTATION_KEY
35
- });
36
- };
@@ -1,19 +0,0 @@
1
- import { EmailAuthProvider, FacebookAuthProvider, GithubAuthProvider, GoogleAuthProvider, TwitterAuthProvider } from "firebase/auth";
2
- type AuthProvider = "google" | "facebook" | "email" | "github" | "twitter";
3
- /**
4
- * A custom hook that returns an auth provider by id.
5
- *
6
- * @group Hook
7
- * @param {AuthProvider} provider alas of a provider
8
- *
9
- * @returns {AuthProvider}
10
- *
11
- * @example
12
- * ```jsx
13
- * export const MyComponent = () => {
14
- * const authProvider = useAuthProvider('email');
15
- * };
16
- * ```
17
- */
18
- export declare const useAuthProvider: (provider: AuthProvider) => GoogleAuthProvider | EmailAuthProvider | FacebookAuthProvider | GithubAuthProvider | TwitterAuthProvider;
19
- export {};
@@ -1,35 +0,0 @@
1
- import { EmailAuthProvider, FacebookAuthProvider, GithubAuthProvider, GoogleAuthProvider, TwitterAuthProvider } from "firebase/auth";
2
- import { useMemo } from "react";
3
- /**
4
- * A custom hook that returns an auth provider by id.
5
- *
6
- * @group Hook
7
- * @param {AuthProvider} provider alas of a provider
8
- *
9
- * @returns {AuthProvider}
10
- *
11
- * @example
12
- * ```jsx
13
- * export const MyComponent = () => {
14
- * const authProvider = useAuthProvider('email');
15
- * };
16
- * ```
17
- */
18
- export const useAuthProvider = (provider) => {
19
- return useMemo(() => {
20
- switch (provider) {
21
- case "google":
22
- return new GoogleAuthProvider();
23
- case "email":
24
- return new EmailAuthProvider();
25
- case "facebook":
26
- return new FacebookAuthProvider();
27
- case "github":
28
- return new GithubAuthProvider();
29
- case "twitter":
30
- return new TwitterAuthProvider();
31
- default:
32
- throw new Error(`Auth provider ${provider} is not supported.`);
33
- }
34
- }, [provider]);
35
- };
@@ -1,45 +0,0 @@
1
- import {
2
- EmailAuthProvider,
3
- FacebookAuthProvider,
4
- GithubAuthProvider,
5
- GoogleAuthProvider,
6
- TwitterAuthProvider
7
- } from "firebase/auth";
8
- import { useMemo } from "react";
9
-
10
- type AuthProvider = "google" | "facebook" | "email" | "github" | "twitter";
11
-
12
- /**
13
- * A custom hook that returns an auth provider by id.
14
- *
15
- * @group Hook
16
- * @param {AuthProvider} provider alas of a provider
17
- *
18
- * @returns {AuthProvider}
19
- *
20
- * @example
21
- * ```jsx
22
- * export const MyComponent = () => {
23
- * const authProvider = useAuthProvider('email');
24
- * };
25
- * ```
26
- */
27
-
28
- export const useAuthProvider = (provider: AuthProvider) => {
29
- return useMemo(() => {
30
- switch (provider) {
31
- case "google":
32
- return new GoogleAuthProvider();
33
- case "email":
34
- return new EmailAuthProvider();
35
- case "facebook":
36
- return new FacebookAuthProvider();
37
- case "github":
38
- return new GithubAuthProvider();
39
- case "twitter":
40
- return new TwitterAuthProvider();
41
- default:
42
- throw new Error(`Auth provider ${provider} is not supported.`);
43
- }
44
- }, [provider]);
45
- };
@@ -1,15 +0,0 @@
1
- import { UseMutationOptions } from "@tanstack/react-query";
2
- import { AuthProvider, PopupRedirectResolver, User } from "firebase/auth";
3
- import { FirebaseError } from "firebase/app";
4
- export type UseLinkWitRedirectMutationVariables = {
5
- user: User;
6
- authProvider: AuthProvider;
7
- popupRedirectResolver?: PopupRedirectResolver;
8
- };
9
- /**
10
- * Custom hook for handling linking of Firebase account to auth provider
11
- * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
12
- * @param {Omit<UseMutationOptions<void, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
13
- * @returns {UseMutationResult<void, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
14
- */
15
- export declare const useLinkWitRedirectMutation: <TContext = unknown>(options?: Omit<UseMutationOptions<void, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">) => import("@tanstack/react-query").UseMutationResult<void, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>;
@@ -1,16 +0,0 @@
1
- import { useMutation } from "@tanstack/react-query";
2
- import { linkWithRedirect } from "firebase/auth";
3
- import { LINK_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
4
- /**
5
- * Custom hook for handling linking of Firebase account to auth provider
6
- * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
7
- * @param {Omit<UseMutationOptions<void, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
8
- * @returns {UseMutationResult<void, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
9
- */
10
- export const useLinkWitRedirectMutation = (options = {}) => {
11
- return useMutation({
12
- ...options,
13
- mutationFn: async ({ user, authProvider, popupRedirectResolver }) => linkWithRedirect(user, authProvider, popupRedirectResolver),
14
- mutationKey: LINK_WITH_REDIRECT_MUTATION_KEY
15
- });
16
- };
@@ -1,31 +0,0 @@
1
- import { useMutation, UseMutationOptions } from "@tanstack/react-query";
2
- import { AuthProvider, linkWithRedirect, PopupRedirectResolver, User } from "firebase/auth";
3
-
4
- import { LINK_WITH_REDIRECT_MUTATION_KEY } from "./mutation-keys";
5
- import { FirebaseError } from "firebase/app";
6
-
7
- export type UseLinkWitRedirectMutationVariables = {
8
- user: User;
9
- authProvider: AuthProvider;
10
- popupRedirectResolver?: PopupRedirectResolver;
11
- };
12
-
13
- /**
14
- * Custom hook for handling linking of Firebase account to auth provider
15
- * This hook utilizes the `useMutation` mechanism to perform the sign-in operation.
16
- * @param {Omit<UseMutationOptions<void, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>, "mutationKey" | "mutationFn">} options - Optional configurations for the mutation, omitting the mutationKey and mutationFn properties.
17
- * @returns {UseMutationResult<void, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>} The result object from the useMutation hook, containing the mutation function and its current state.
18
- */
19
- export const useLinkWitRedirectMutation = <TContext = unknown>(
20
- options: Omit<
21
- UseMutationOptions<void, FirebaseError, UseLinkWitRedirectMutationVariables, TContext>,
22
- "mutationKey" | "mutationFn"
23
- > = {}
24
- ) => {
25
- return useMutation({
26
- ...options,
27
- mutationFn: async ({ user, authProvider, popupRedirectResolver }: UseLinkWitRedirectMutationVariables) =>
28
- linkWithRedirect(user, authProvider, popupRedirectResolver),
29
- mutationKey: LINK_WITH_REDIRECT_MUTATION_KEY
30
- });
31
- };