react-query-firebase 2.6.5 → 2.7.1
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 +1 -1
- package/react-native/auth/index.d.ts +2 -0
- package/react-native/auth/index.js +2 -0
- package/react-native/auth/index.ts +2 -0
- package/react-native/auth/mutation-keys.d.ts +1 -0
- package/react-native/auth/mutation-keys.js +1 -0
- package/react-native/auth/mutation-keys.ts +1 -0
- package/react-native/auth/useAuthProvider.d.ts +18 -0
- package/react-native/auth/useAuthProvider.js +35 -0
- package/react-native/auth/useAuthProvider.ts +45 -0
- package/react-native/auth/useLinkWithRedirect.d.ts +15 -0
- package/react-native/auth/useLinkWithRedirect.js +16 -0
- package/react-native/auth/useLinkWithRedirect.ts +36 -0
- package/web/auth/index.d.ts +2 -0
- package/web/auth/index.js +2 -0
- package/web/auth/index.ts +2 -0
- package/web/auth/mutation-keys.d.ts +1 -0
- package/web/auth/mutation-keys.js +1 -0
- package/web/auth/mutation-keys.ts +1 -0
- package/web/auth/useAuthProvider.d.ts +19 -0
- package/web/auth/useAuthProvider.js +35 -0
- package/web/auth/useAuthProvider.ts +45 -0
- package/web/auth/useLinkWithRedirect.d.ts +15 -0
- package/web/auth/useLinkWithRedirect.js +16 -0
- package/web/auth/useLinkWithRedirect.ts +31 -0
package/package.json
CHANGED
|
@@ -12,3 +12,5 @@ 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";
|
|
@@ -12,3 +12,5 @@ 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";
|
|
@@ -12,3 +12,5 @@ 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";
|
|
@@ -3,6 +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
7
|
export declare const SIGN_OUT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_OUT"];
|
|
7
8
|
export declare const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
|
|
8
9
|
export declare const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_CREDENTIAL"];
|
|
@@ -11,6 +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
15
|
export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"];
|
|
15
16
|
export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
|
|
16
17
|
export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
|
|
@@ -11,6 +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
15
|
export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"] as const;
|
|
15
16
|
export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"] as const;
|
|
16
17
|
export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
|
|
@@ -0,0 +1,18 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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>;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
};
|
package/web/auth/index.d.ts
CHANGED
|
@@ -12,3 +12,5 @@ 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";
|
package/web/auth/index.js
CHANGED
|
@@ -12,3 +12,5 @@ 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";
|
package/web/auth/index.ts
CHANGED
|
@@ -12,3 +12,5 @@ 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";
|
|
@@ -3,6 +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
7
|
export declare const SIGN_OUT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "SIGN_OUT"];
|
|
7
8
|
export declare const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
|
|
8
9
|
export declare const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY: readonly ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_CREDENTIAL"];
|
|
@@ -11,6 +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
15
|
export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"];
|
|
15
16
|
export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"];
|
|
16
17
|
export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
|
|
@@ -11,6 +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
15
|
export const SIGN_OUT_MUTATION_KEY = ["FIREBASE", "AUTH", "SIGN_OUT"] as const;
|
|
15
16
|
export const REAUTHENTICATE_WITH_REDIRECT_MUTATION_KEY = ["FIREBASE", "AUTH", "REAUTHENTICATE_WITH_REDIRECT"] as const;
|
|
16
17
|
export const REAUTHENTICATE_WITH_CREDENTIAL_MUTATION_KEY = [
|
|
@@ -0,0 +1,19 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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>;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
};
|