From e6d76852a79771fe941841c1dfe5005929b82a69 Mon Sep 17 00:00:00 2001 From: HassanBahati Date: Thu, 26 Dec 2024 15:27:29 +0300 Subject: [PATCH 1/7] docs(useDeleteUserMutation); add docs for useDeleteUserMutation --- .../auth/hooks/useDeleteUserMutation.mdx | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/docs/react/auth/hooks/useDeleteUserMutation.mdx b/docs/react/auth/hooks/useDeleteUserMutation.mdx index 84cdb4b..d91fed4 100644 --- a/docs/react/auth/hooks/useDeleteUserMutation.mdx +++ b/docs/react/auth/hooks/useDeleteUserMutation.mdx @@ -2,4 +2,42 @@ title: useDeleteUserMutation --- -This hook is implemented, but the documentation is a work in progress, check back soon. \ No newline at end of file +The `useDeleteUserMutation` hook simplifies the process of deleting a user from Firebase Authentication. +It provides built-in state management for handling the mutation lifecycle (e.g., loading, success, error) and supports custom behaviors like `onSuccess` or `onError`. + +## Features + +- `Easy Firebase Auth Integration`: Leverages Firebase's `deleteUser` functionality. +- `Built-in State Management`: Handles idle, loading, success, and error states. +- `Customizable Callbacks`: Supports onSuccess, onError, and other React Query mutation options. +- `Optimized for TanStack Query`: Seamlessly integrates with TanStack Query for `caching` and `refetching`. + +## Usage + +```jsx +import { useDeleteUserMutation } from "@tanstack-query-firebase/react/auth"; + +function Component() { + const { mutate, isPending, isSuccess, isError, error } = + useDeleteUserMutation(auth); + + const handleDeleteUser = () => { + const user = auth.currentUser; + if (user) { + mutate(user); + } + }; + + return ( +
+ {isPending &&

Deleting user...

} + {isSuccess &&

User deleted successfully!

} + {isError &&

Error: {error.message}

} + + +
+ ); +} +``` From ed727bc9f9e57c5cca841dce2a2d06539adfeb20 Mon Sep 17 00:00:00 2001 From: HassanBahati Date: Thu, 26 Dec 2024 16:32:30 +0300 Subject: [PATCH 2/7] docs(auth): add docs for react auth hooks --- .../auth/hooks/useDeleteUserMutation.mdx | 58 +++++++++++- docs/react/auth/hooks/useReloadMutation.mdx | 89 +++++++++++++++++- .../hooks/useSignInAnonymouslyMutation.mdx | 87 +++++++++++++++++- .../hooks/useSignInWithCredentialMutation.mdx | 91 ++++++++++++++++++- .../useSignInWithEmailAndPasswordMutation.mdx | 88 +++++++++++++++++- docs/react/auth/hooks/useSignOutMutation.mdx | 86 +++++++++++++++++- .../hooks/useUpdateCurrentUserMutation.mdx | 87 +++++++++++++++++- .../useVerifyPasswordResetCodeMutation.mdx | 90 +++++++++++++++++- 8 files changed, 665 insertions(+), 11 deletions(-) diff --git a/docs/react/auth/hooks/useDeleteUserMutation.mdx b/docs/react/auth/hooks/useDeleteUserMutation.mdx index d91fed4..def422a 100644 --- a/docs/react/auth/hooks/useDeleteUserMutation.mdx +++ b/docs/react/auth/hooks/useDeleteUserMutation.mdx @@ -8,9 +8,17 @@ It provides built-in state management for handling the mutation lifecycle (e.g., ## Features - `Easy Firebase Auth Integration`: Leverages Firebase's `deleteUser` functionality. -- `Built-in State Management`: Handles idle, loading, success, and error states. -- `Customizable Callbacks`: Supports onSuccess, onError, and other React Query mutation options. -- `Optimized for TanStack Query`: Seamlessly integrates with TanStack Query for `caching` and `refetching`. +- `Built-in State Management`: Automatically manages `idle`, `loading`, `success`, and `error` states. +- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- `Optimized for TanStack Query`: Seamlessly integrates with TanStack Query for caching and refetching strategies. + +## Installation + +Ensure you have the necessary Firebase, TanStack Query and TanStack Query Firebase packages installed: + +```bash +npm install firebase @tanstack/react-query @tanstack-query-firebase/react +``` ## Usage @@ -19,7 +27,7 @@ import { useDeleteUserMutation } from "@tanstack-query-firebase/react/auth"; function Component() { const { mutate, isPending, isSuccess, isError, error } = - useDeleteUserMutation(auth); + useDeleteUserMutation(); const handleDeleteUser = () => { const user = auth.currentUser; @@ -41,3 +49,45 @@ function Component() { ); } ``` + +## API Reference + +`useDeleteUserMutation(options?)` + +### Parameters + +- `options` (optional): + Object for customizing mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: + - `onSuccess`: Callback fired when the mutation succeeds. + - `onError`: Callback fired when the mutation fails. + - `onSettled`: Callback fired after the mutation finishes, regardless of success or failure. + +See [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) for more information on mutation options and behavior. + +### Returns + +An object containing the following properties, provided by TanStack Query's [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation): + +- `mutate`: + Function to trigger the mutation. In this case, it deletes the user. + +```ts +mutate(user: User): void; +``` + +- `isPending`: + Boolean indicating if the mutation is in progress (alias for `isLoading`). + +- `isSuccess`: + Boolean indicating if the mutation has successfully completed. + +- `isError`: + Boolean indicating if the mutation has failed. + +- `error`: + The error object, if the mutation failed. + +- `data`: + The result of the mutation (typically `undefined` for delete operations). + +For a complete list of returned properties, see the official TanStack Query [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) documentation. diff --git a/docs/react/auth/hooks/useReloadMutation.mdx b/docs/react/auth/hooks/useReloadMutation.mdx index 8af6f32..64668ed 100644 --- a/docs/react/auth/hooks/useReloadMutation.mdx +++ b/docs/react/auth/hooks/useReloadMutation.mdx @@ -2,4 +2,91 @@ title: useReloadMutation --- -This hook is implemented, but the documentation is a work in progress, check back soon. \ No newline at end of file +The `useReloadMutation` hook provides a simple way to reload user data in Firebase Authentication. +This hook enables re-authenticating users and ensures the latest user state is fetched from Firebase. + +## Features + +- `Seamless Firebase Integration`: Reloads the current Firebase user to fetch updated user state. +- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- `Type-Safe Handling`: Ensures that only valid Firebase user objects can be passed. + +## Installation + +Ensure you have the necessary Firebase, TanStack Query and TanStack Query Firebase packages installed: + +```bash +npm install firebase @tanstack/react-query @tanstack-query-firebase/react +``` + +## Usage + +```jsx +import { useReloadMutation } from "@tanstack-query-firebase/react/auth"; + +function Component() { + const { mutate, isPending, isSuccess, isError, error } = useReloadMutation(); + + const handleReloadUser = () => { + const user = auth.currentUser; + if (user) { + mutate(user); + } + }; + + return ( +
+ {isPending &&

Reloading user data...

} + {isSuccess &&

User data reloaded successfully!

} + {isError &&

Error: {error.message}

} + + +
+ ); +} +``` + +## API Reference + +`useReloadMutation(options?)` + +### Parameters + +- `options` (optional): + An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: + - `onSuccess`: Callback fired when the mutation succeeds. + - `onError`: Callback fired when the mutation fails. + - `onSettled`: Callback fired after the mutation finishes, regardless of success or failure. + +For a full list of supported options, see the TanStack Query [useMutation documentation](https://tanstack.com/query/latest/docs/react/reference/useMutation) + +### Returns + +The hook returns the following properties, provided by TanStack Query's [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation): + +- `mutate`: + Function to trigger the mutation. In this case, it reloads the user data. + +```ts +mutate(user: User): void; +``` + +- `isPending`: + Boolean indicating if the mutation is in progress (alias for `isLoading`). + +- `isSuccess`: + Boolean indicating if the mutation has successfully completed. + +- `isError`: + Boolean indicating if the mutation has failed. + +- `error`: + The error object, if the mutation failed. + +- `data`: + The result of the mutation (typically `undefined` for delete operations). + +For a complete list of returned properties, see the official TanStack Query [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) documentation. diff --git a/docs/react/auth/hooks/useSignInAnonymouslyMutation.mdx b/docs/react/auth/hooks/useSignInAnonymouslyMutation.mdx index 9abff67..4e89121 100644 --- a/docs/react/auth/hooks/useSignInAnonymouslyMutation.mdx +++ b/docs/react/auth/hooks/useSignInAnonymouslyMutation.mdx @@ -2,4 +2,89 @@ title: useSignInAnonymouslyMutation --- -This hook is implemented, but the documentation is a work in progress, check back soon. \ No newline at end of file +The `useSignInAnonymouslyMutation` hook provides a simple way to sign in users anonymously using Firebase Authentication. +This hook integrates Firebase’s `signInAnonymously` method with TanStack Query's mutation lifecycle, allowing seamless state management and error handling. + +## Features + +- `Firebase Authentication Integration`: Allows users to sign in anonymously with Firebase Authentication. +- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- `Type-Safe Handling`: Ensures only valid data is passed and received from Firebase Authentication. + +## Installation + +Ensure you have the necessary Firebase, TanStack Query and TanStack Query Firebase packages installed: + +```bash +npm install firebase @tanstack/react-query @tanstack-query-firebase/react +``` + +## Usage + +```jsx +import { useSignInAnonymouslyMutation } from "@tanstack-query-firebase/react/auth"; + +function Component() { + const { mutate, isPending, isSuccess, isError, error } = useSignInAnonymouslyMutation(auth); + + const handleSignIn = () => { + mutate(); // Trigger anonymous sign-in + }; + + return ( +
+ {isPending &&

Signing in...

} + {isSuccess &&

Signed in anonymously!

} + {isError &&

Error: {error?.message}

} + + +
+ ); +} +``` + +## API Reference + +`useSignInAnonymouslyMutation(auth, options?)` + +### Parameters + +-`auth`: The Firebase `Auth` instance used to manage authentication. +- `options` (optional): + An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: + - `onSuccess`: Callback fired when the mutation succeeds. + - `onError`: Callback fired when the mutation fails. + - `onSettled`: Callback fired after the mutation finishes, regardless of success or failure. + +For a full list of supported options, see the TanStack Query [useMutation documentation](https://tanstack.com/query/latest/docs/react/reference/useMutation) + +### Returns + +The hook returns the following properties, provided by TanStack Query's [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation): + +- `mutate`: + Function to trigger the mutation(signin anonymously). + +```ts +mutate(): void; +``` + +- `isPending`: + Boolean indicating if the mutation is in progress (alias for `isLoading`). + +- `isSuccess`: + Boolean indicating if the mutation has successfully completed. + +- `isError`: + Boolean indicating if the mutation has failed. + +- `error`: + The error object, if the mutation failed. + +- `data`: + The result of the mutation, typically containing the authenticated user data. + +For a complete list of returned properties, see the official TanStack Query [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) documentation. diff --git a/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx b/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx index a69de7d..34acceb 100644 --- a/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx +++ b/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx @@ -2,4 +2,93 @@ title: useSignInWithCredentialMutation --- -This hook is implemented, but the documentation is a work in progress, check back soon. \ No newline at end of file +The `useSignInWithCredentialMutation` hook is designed to handle user sign-ins using Firebase Authentication credentials, such as Google sign-in credentials. +It integrates Firebase's `signInWithCredential` method with TanStack Query’s mutation lifecycle for easy state management and error handling. + +## Features + +- `Firebase Authentication Integration`: Simplifies signing in with any valid Firebase `AuthCredential` (e.g., Google, Facebook, etc.). +- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- `Type-Safe Handling`: Ensures type safety with TanStack Query and Firebase types. + +## Installation + +Ensure you have the necessary Firebase, TanStack Query and TanStack Query Firebase packages installed: + +```bash +npm install firebase @tanstack/react-query @tanstack-query-firebase/react +``` + +## Usage + +```jsx +import { useSignInWithCredentialMutation } from "@tanstack-query-firebase/react/auth"; +import { GoogleAuthProvider } from "firebase/auth"; + +const authCredential = GoogleAuthProvider.credential("your-id-token"); + +function SignInComponent() { + const { mutate, isPending, isSuccess, isError, error, data } = useSignInWithCredentialMutation(auth, authCredential); + + const handleSignIn = () => { + mutate(); // Trigger the sign-in mutation + }; + + return ( +
+ {isPending &&

Signing in...

} + {isSuccess &&

Signed in as {data?.user.email}

} + {isError &&

Error: {error?.message}

} + + +
+ ); +} +``` + +## API Reference + +`useSignInWithCredentialMutation(auth, credential, options?)` + +### Parameters + +-`auth`: The Firebase `Auth` instance used to manage authentication. +- `credential`: An instance of `AuthCredential` (e.g., `GoogleAuthProvider.credential`). +- `options` (optional): + An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: + - `onSuccess`: Callback fired when the mutation succeeds. + - `onError`: Callback fired when the mutation fails. + - `onSettled`: Callback fired after the mutation finishes, regardless of success or failure. + +For a full list of supported options, see the TanStack Query [useMutation documentation](https://tanstack.com/query/latest/docs/react/reference/useMutation) + +### Returns + +The hook returns the following properties, provided by TanStack Query's [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation): + +- `mutate`: + Function to trigger the sign-in mutation with the provided credential. + +```ts +mutate(): void; +``` + +- `isPending`: + Boolean indicating if the mutation is in progress (alias for `isLoading`). + +- `isSuccess`: + Boolean indicating if the mutation has successfully completed. + +- `isError`: + Boolean indicating if the mutation has failed. + +- `error`: + The error object, if the mutation failed. + +- `data`: + The result of the sign-in, typically containing the authenticated `user` object. + +For a complete list of returned properties, see the official TanStack Query [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) documentation. diff --git a/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx b/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx index 1975bdb..1109056 100644 --- a/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx +++ b/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx @@ -2,4 +2,90 @@ title: useSignInWithEmailAndPasswordMutation --- -This hook is implemented, but the documentation is a work in progress, check back soon. \ No newline at end of file +The `useSignInWithEmailAndPasswordMutation` hook is designed to handle user sign-ins using Firebase Authentication with email and password. +It integrates Firebase's `signInWithEmailAndPassword` method with TanStack Query’s mutation lifecycle for easy state management and error handling. + +## Features + +- `Firebase Authentication Integration`: Simplifies signing in with email and password using Firebase's `signInWithEmailAndPassword` method. +- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- `Type-Safe Handling`: Ensures type safety with TanStack Query and Firebase types. + +## Installation + +Ensure you have the necessary Firebase, TanStack Query and TanStack Query Firebase packages installed: + +```bash +npm install firebase @tanstack/react-query @tanstack-query-firebase/react +``` + +## Usage + +```jsx +import { useSignInWithEmailAndPasswordMutation } from "./useSignInWithEmailAndPasswordMutation"; + +function SignInComponent() { + const { mutate, isPending, isSuccess, isError, error, data } = useSignInWithEmailAndPasswordMutation(auth); + + const handleSignIn = () => { + const email = "user@example.com"; + const password = "password123"; + mutate({ email, password }); // Trigger the sign-in mutation + }; + + return ( +
+ {isPending &&

Signing in...

} + {isSuccess &&

Signed in as {data?.user.email}

} + {isError &&

Error: {error?.message}

} + + +
+ ); +} +``` + +## API Reference + +`useSignInWithEmailAndPasswordMutation(auth, options?)` + +### Parameters + +-`auth`: The Firebase `Auth` instance used to manage authentication. +- `options` (optional): + An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: + - `onSuccess`: Callback fired when the mutation succeeds. + - `onError`: Callback fired when the mutation fails. + - `onSettled`: Callback fired after the mutation finishes, regardless of success or failure. + +For a full list of supported options, see the TanStack Query [useMutation documentation](https://tanstack.com/query/latest/docs/react/reference/useMutation) + +### Returns + +The hook returns the following properties, provided by TanStack Query's [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation): + +- `mutate({ email, password })`: Function to trigger the sign-in mutation with the provided email and password. + +```ts +mutate({ email: string, password: string }): void; +``` + +- `isPending`: + Boolean indicating if the mutation is in progress (alias for `isLoading`). + +- `isSuccess`: + Boolean indicating if the mutation has successfully completed. + +- `isError`: + Boolean indicating if the mutation has failed. + +- `error`: + The error object, if the mutation failed. + +- `data`: + The result of the mutation, which contains the `UserCredential` object if the mutation was successful. + +For a complete list of returned properties, see the official TanStack Query [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) documentation. diff --git a/docs/react/auth/hooks/useSignOutMutation.mdx b/docs/react/auth/hooks/useSignOutMutation.mdx index de9a553..a0bc937 100644 --- a/docs/react/auth/hooks/useSignOutMutation.mdx +++ b/docs/react/auth/hooks/useSignOutMutation.mdx @@ -2,4 +2,88 @@ title: useSignOutMutation --- -This hook is implemented, but the documentation is a work in progress, check back soon. \ No newline at end of file +The `useSignOutMutation` hook is designed to handle user sign-out using Firebase Authentication. +It integrates Firebase's `signOut` method with TanStack Query’s mutation lifecycle for easy state management and error handling. + +## Features + +- `Firebase Authentication Integration`: Simplifies signing out users from Firebase Authentication using Firebase's `signOut` method. +- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- `Type-Safe Handling`: Ensures type safety with TanStack Query and Firebase types. + +## Installation + +Ensure you have the necessary Firebase, TanStack Query and TanStack Query Firebase packages installed: + +```bash +npm install firebase @tanstack/react-query @tanstack-query-firebase/react +``` + +## Usage + +```jsx +import { useSignOutMutation } from "./useSignOutMutation"; + +function SignOutComponent() { + const { mutate, isPending, isSuccess, isError, error } = useSignOutMutation(auth); + + const handleSignOut = () => { + mutate(); // Trigger the sign-out mutation + }; + + return ( +
+ {isPending &&

Signing out...

} + {isSuccess &&

Signed out successfully!

} + {isError &&

Error: {error?.message}

} + + +
+ ); +} +``` + +## API Reference + +`useSignOutMutation(auth, options?)` + +### Parameters + +-`auth`: The Firebase `Auth` instance used to manage authentication. +- `options` (optional): + An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: + - `onSuccess`: Callback fired when the mutation succeeds. + - `onError`: Callback fired when the mutation fails. + - `onSettled`: Callback fired after the mutation finishes, regardless of success or failure. + +For a full list of supported options, see the TanStack Query [useMutation documentation](https://tanstack.com/query/latest/docs/react/reference/useMutation) + +### Returns + +The hook returns the following properties, provided by TanStack Query's [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation): + +- `mutate({ email, password })`: Function to trigger the sign-in mutation with the provided email and password. + +```ts +mutate(): void; +``` + +- `isPending`: + Boolean indicating if the mutation is in progress (alias for `isLoading`). + +- `isSuccess`: + Boolean indicating if the mutation has successfully completed. + +- `isError`: + Boolean indicating if the mutation has failed. + +- `error`: + The error object, if the mutation failed. + +- `data`: + The result of the mutation, which is typically `undefined` for sign-out operations. + +For a complete list of returned properties, see the official TanStack Query [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) documentation. diff --git a/docs/react/auth/hooks/useUpdateCurrentUserMutation.mdx b/docs/react/auth/hooks/useUpdateCurrentUserMutation.mdx index 1a6b3a4..edea49e 100644 --- a/docs/react/auth/hooks/useUpdateCurrentUserMutation.mdx +++ b/docs/react/auth/hooks/useUpdateCurrentUserMutation.mdx @@ -2,4 +2,89 @@ title: useUpdateCurrentUserMutation --- -This hook is implemented, but the documentation is a work in progress, check back soon. \ No newline at end of file +The `useUpdateCurrentUserMutation` hook is designed to update the current authenticated user using Firebase Authentication. +It integrates Firebase's `updateCurrentUser` method with TanStack Query’s mutation lifecycle for easy state management and error handling. + + +## Features + +- **Firebase Authentication Integration**: Simplifies updating the current authenticated user using Firebase's `-zupdateCurrentUser` method. +- **Built-in State Management**: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- **Customizable Callbacks**: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- **Type-Safe Handling**: Ensures type safety with TanStack Query and Firebase types. + +## Installation + +Ensure you have the necessary Firebase, TanStack Query and TanStack Query Firebase packages installed: + +```bash +npm install firebase @tanstack/react-query @tanstack-query-firebase/react +``` + +## Usage + +```jsx +import { useUpdateCurrentUserMutation } from "./useUpdateCurrentUserMutation"; + +function UpdateUserComponent() { + const { mutate, isPending, isSuccess, isError, error } = useUpdateCurrentUserMutation(auth); + + const handleUpdateUser = (newUser) => { + mutate(newUser); // Trigger the user update mutation + }; + + return ( +
+ {isPending &&

Updating user...

} + {isSuccess &&

User updated successfully!

} + {isError &&

Error: {error?.message}

} + + +
+ ); +} +``` + +## API Reference + +`useUpdateCurrentUserMutation(auth, options?)` + +### Parameters + +-`auth`: The Firebase `Auth` instance used to manage authentication. +- `options` (optional): + An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: + - `onSuccess`: Callback fired when the mutation succeeds. + - `onError`: Callback fired when the mutation fails. + - `onSettled`: Callback fired after the mutation finishes, regardless of success or failure. + +For a full list of supported options, see the TanStack Query [useMutation documentation](https://tanstack.com/query/latest/docs/react/reference/useMutation) + +### Returns + +The hook returns the following properties, provided by TanStack Query's [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation): + +- `mutate({ email, password })`: Function to trigger the user update mutation with the provided `user` object. Pass `null` to sign out the user. + +```ts +mutate(user: User | null): void; +``` + +- `isPending`: + Boolean indicating if the mutation is in progress (alias for `isLoading`). + +- `isSuccess`: + Boolean indicating if the mutation has successfully completed. + +- `isError`: + Boolean indicating if the mutation has failed. + +- `error`: + The error object, if the mutation failed. + +- `data`: + The result of the mutation, which is typically `undefined` for user updates. + +For a complete list of returned properties, see the official TanStack Query [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) documentation. diff --git a/docs/react/auth/hooks/useVerifyPasswordResetCodeMutation.mdx b/docs/react/auth/hooks/useVerifyPasswordResetCodeMutation.mdx index e94ba52..b740e37 100644 --- a/docs/react/auth/hooks/useVerifyPasswordResetCodeMutation.mdx +++ b/docs/react/auth/hooks/useVerifyPasswordResetCodeMutation.mdx @@ -2,4 +2,92 @@ title: useVerifyPasswordResetCodeMutation --- -This hook is implemented, but the documentation is a work in progress, check back soon. \ No newline at end of file +The `useVerifyPasswordResetCodeMutation` hook is designed to verify a password reset code sent by Firebase Authentication. +It integrates Firebase's `verifyPasswordResetCode` method with TanStack Query’s mutation lifecycle, providing state management and error handling for the password reset process. + +## Features + +- **Firebase Authentication Integration**: Simplifies verifying a password reset code using Firebase's `verifyPasswordResetCode` method. +- **Built-in State Management**: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- **Customizable Callbacks**: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- **Type-Safe Handling**: Ensures type safety with TanStack Query and Firebase types. + +## Installation + +Ensure you have the necessary Firebase, TanStack Query and TanStack Query Firebase packages installed: + +```bash +npm install firebase @tanstack/react-query @tanstack-query-firebase/react +``` + +## Usage + +```jsx +import { useVerifyPasswordResetCodeMutation } from "./useVerifyPasswordResetCodeMutation"; + +function VerifyResetCodeComponent() { + const { mutate, isPending, isSuccess, isError, error, data } = useVerifyPasswordResetCodeMutation(auth); + + const handleVerifyResetCode = async (code) => { + try { + await mutate(code); // Trigger the verify reset code mutation + } catch (error) { + console.error("Error verifying reset code:", error); + } + }; + + return ( +
+ {isLoading &&

Verifying reset code...

} + {isSuccess &&

Reset code verified! Email: {data}

} + {isError &&

Error: {error?.message}

} + + +
+ ); +} +``` + +## API Reference + +`useVerifyPasswordResetCodeMutation(auth, options?)` + +### Parameters + +-`auth`: The Firebase `Auth` instance used to manage authentication. +- `options` (optional): + An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: + - `onSuccess`: Callback fired when the mutation succeeds. + - `onError`: Callback fired when the mutation fails. + - `onSettled`: Callback fired after the mutation finishes, regardless of success or failure. + +For a full list of supported options, see the TanStack Query [useMutation documentation](https://tanstack.com/query/latest/docs/react/reference/useMutation) + +### Returns + +The hook returns the following properties, provided by TanStack Query's [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation): + +- `mutate(code: string)`: Function to trigger the password reset code verification mutation with the provided `code`. + +```ts +mutate(code: string): Promise; +``` + +- `isPending`: + Boolean indicating if the mutation is in progress (alias for `isLoading`). + +- `isSuccess`: + Boolean indicating if the mutation has successfully completed. + +- `isError`: + Boolean indicating if the mutation has failed. + +- `error`: + The error object, if the mutation failed. + +- `data`: + The result of the mutation, which is typically the user's email after successful verification. + +For a complete list of returned properties, see the official TanStack Query [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) documentation. From f7d31fb20a8298d8120c2e6b923db03ad6e284e7 Mon Sep 17 00:00:00 2001 From: HassanBahati Date: Thu, 26 Dec 2024 16:36:35 +0300 Subject: [PATCH 3/7] docs(auth): add docs for react auth hooks --- docs/react/auth/hooks/useDeleteUserMutation.mdx | 8 ++++---- docs/react/auth/hooks/useReloadMutation.mdx | 8 ++++---- docs/react/auth/hooks/useSignInAnonymouslyMutation.mdx | 8 ++++---- docs/react/auth/hooks/useSignInWithCredentialMutation.mdx | 8 ++++---- .../auth/hooks/useSignInWithEmailAndPasswordMutation.mdx | 8 ++++---- docs/react/auth/hooks/useSignOutMutation.mdx | 8 ++++---- 6 files changed, 24 insertions(+), 24 deletions(-) diff --git a/docs/react/auth/hooks/useDeleteUserMutation.mdx b/docs/react/auth/hooks/useDeleteUserMutation.mdx index def422a..7fad8fa 100644 --- a/docs/react/auth/hooks/useDeleteUserMutation.mdx +++ b/docs/react/auth/hooks/useDeleteUserMutation.mdx @@ -7,10 +7,10 @@ It provides built-in state management for handling the mutation lifecycle (e.g., ## Features -- `Easy Firebase Auth Integration`: Leverages Firebase's `deleteUser` functionality. -- `Built-in State Management`: Automatically manages `idle`, `loading`, `success`, and `error` states. -- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. -- `Optimized for TanStack Query`: Seamlessly integrates with TanStack Query for caching and refetching strategies. +- **Easy Firebase Auth Integration**: Leverages Firebase's `deleteUser` functionality. +- **Built-in State Management**: Automatically manages `idle`, `loading`, `success`, and `error` states. +- **Customizable Callbacks*8: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- **Optimized for TanStack Query**: Seamlessly integrates with TanStack Query for caching and refetching strategies. ## Installation diff --git a/docs/react/auth/hooks/useReloadMutation.mdx b/docs/react/auth/hooks/useReloadMutation.mdx index 64668ed..8ed49a5 100644 --- a/docs/react/auth/hooks/useReloadMutation.mdx +++ b/docs/react/auth/hooks/useReloadMutation.mdx @@ -7,10 +7,10 @@ This hook enables re-authenticating users and ensures the latest user state is f ## Features -- `Seamless Firebase Integration`: Reloads the current Firebase user to fetch updated user state. -- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). -- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. -- `Type-Safe Handling`: Ensures that only valid Firebase user objects can be passed. +- **Seamless Firebase Integration**: Reloads the current Firebase user to fetch updated user state. +- **Built-in State Management**: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- **Customizable Callbacks**: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- **Type-Safe Handling**: Ensures that only valid Firebase user objects can be passed. ## Installation diff --git a/docs/react/auth/hooks/useSignInAnonymouslyMutation.mdx b/docs/react/auth/hooks/useSignInAnonymouslyMutation.mdx index 4e89121..21300e7 100644 --- a/docs/react/auth/hooks/useSignInAnonymouslyMutation.mdx +++ b/docs/react/auth/hooks/useSignInAnonymouslyMutation.mdx @@ -7,10 +7,10 @@ This hook integrates Firebase’s `signInAnonymously` method with TanStack Query ## Features -- `Firebase Authentication Integration`: Allows users to sign in anonymously with Firebase Authentication. -- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). -- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. -- `Type-Safe Handling`: Ensures only valid data is passed and received from Firebase Authentication. +- **Firebase Authentication Integration**: Allows users to sign in anonymously with Firebase Authentication. +- **Built-in State Management**: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- **Customizable Callbacks**: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- **Type-Safe Handling**: Ensures only valid data is passed and received from Firebase Authentication. ## Installation diff --git a/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx b/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx index 34acceb..ad2009c 100644 --- a/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx +++ b/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx @@ -7,10 +7,10 @@ It integrates Firebase's `signInWithCredential` method with TanStack Query’s m ## Features -- `Firebase Authentication Integration`: Simplifies signing in with any valid Firebase `AuthCredential` (e.g., Google, Facebook, etc.). -- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). -- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. -- `Type-Safe Handling`: Ensures type safety with TanStack Query and Firebase types. +- **Firebase Authentication Integration**: Simplifies signing in with any valid Firebase `AuthCredential` (e.g., Google, Facebook, etc.). +- **Built-in State Management**: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- **Customizable Callbacks**: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- **Type-Safe Handling**: Ensures type safety with TanStack Query and Firebase types. ## Installation diff --git a/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx b/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx index 1109056..fcce15b 100644 --- a/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx +++ b/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx @@ -7,10 +7,10 @@ It integrates Firebase's `signInWithEmailAndPassword` method with TanStack Query ## Features -- `Firebase Authentication Integration`: Simplifies signing in with email and password using Firebase's `signInWithEmailAndPassword` method. -- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). -- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. -- `Type-Safe Handling`: Ensures type safety with TanStack Query and Firebase types. +- **Firebase Authentication Integration**: Simplifies signing in with email and password using Firebase's `signInWithEmailAndPassword` method. +- **Built-in State Management**: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- **Customizable Callbacks**: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- **Type-Safe Handling**: Ensures type safety with TanStack Query and Firebase types. ## Installation diff --git a/docs/react/auth/hooks/useSignOutMutation.mdx b/docs/react/auth/hooks/useSignOutMutation.mdx index a0bc937..6ac4625 100644 --- a/docs/react/auth/hooks/useSignOutMutation.mdx +++ b/docs/react/auth/hooks/useSignOutMutation.mdx @@ -7,10 +7,10 @@ It integrates Firebase's `signOut` method with TanStack Query’s mutation lifec ## Features -- `Firebase Authentication Integration`: Simplifies signing out users from Firebase Authentication using Firebase's `signOut` method. -- `Built-in State Management`: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). -- `Customizable Callbacks`: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. -- `Type-Safe Handling`: Ensures type safety with TanStack Query and Firebase types. +- **Firebase Authentication Integration**: Simplifies signing out users from Firebase Authentication using Firebase's `signOut` method. +- **Built-in State Management**: Tracks the mutation lifecycle (`idle`, `loading`, `success`, `error`). +- **Customizable Callbacks**: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- **Type-Safe Handling**: Ensures type safety with TanStack Query and Firebase types. ## Installation From 45f95448658e9fa9d88baa8b340c7ef926bd69b4 Mon Sep 17 00:00:00 2001 From: HassanBahati Date: Thu, 26 Dec 2024 16:38:21 +0300 Subject: [PATCH 4/7] docs(auth): add docs for react auth hooks --- docs/react/auth/hooks/useDeleteUserMutation.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/react/auth/hooks/useDeleteUserMutation.mdx b/docs/react/auth/hooks/useDeleteUserMutation.mdx index 7fad8fa..fd3a0da 100644 --- a/docs/react/auth/hooks/useDeleteUserMutation.mdx +++ b/docs/react/auth/hooks/useDeleteUserMutation.mdx @@ -9,7 +9,7 @@ It provides built-in state management for handling the mutation lifecycle (e.g., - **Easy Firebase Auth Integration**: Leverages Firebase's `deleteUser` functionality. - **Built-in State Management**: Automatically manages `idle`, `loading`, `success`, and `error` states. -- **Customizable Callbacks*8: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. +- **Customizable Callbacks**: Supports `onSuccess`, `onError`, and other TanStack Query mutation options. - **Optimized for TanStack Query**: Seamlessly integrates with TanStack Query for caching and refetching strategies. ## Installation From c139ccde1df5f4d63827aba721370cf018787916 Mon Sep 17 00:00:00 2001 From: HassanBahati Date: Thu, 26 Dec 2024 16:41:01 +0300 Subject: [PATCH 5/7] _ --- docs/react/auth/hooks/useReloadMutation.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/react/auth/hooks/useReloadMutation.mdx b/docs/react/auth/hooks/useReloadMutation.mdx index 8ed49a5..128147d 100644 --- a/docs/react/auth/hooks/useReloadMutation.mdx +++ b/docs/react/auth/hooks/useReloadMutation.mdx @@ -87,6 +87,6 @@ mutate(user: User): void; The error object, if the mutation failed. - `data`: - The result of the mutation (typically `undefined` for delete operations). + The result of the mutation (typically `undefined` for reload operations). For a complete list of returned properties, see the official TanStack Query [useMutation](https://tanstack.com/query/latest/docs/react/reference/useMutation) documentation. From 878234766415a88e776ae849e835946699628be5 Mon Sep 17 00:00:00 2001 From: HassanBahati Date: Thu, 26 Dec 2024 16:44:14 +0300 Subject: [PATCH 6/7] docs(useSignInWithCredentialMutation): fix formatting --- docs/react/auth/hooks/useSignInWithCredentialMutation.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx b/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx index ad2009c..7aa98d9 100644 --- a/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx +++ b/docs/react/auth/hooks/useSignInWithCredentialMutation.mdx @@ -55,7 +55,7 @@ function SignInComponent() { ### Parameters --`auth`: The Firebase `Auth` instance used to manage authentication. +- `auth`: The Firebase `Auth` instance used to manage authentication. - `credential`: An instance of `AuthCredential` (e.g., `GoogleAuthProvider.credential`). - `options` (optional): An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: From 1ccf7758e93175fedb990bd2b2228df7ed9cafc3 Mon Sep 17 00:00:00 2001 From: HassanBahati Date: Thu, 26 Dec 2024 16:46:21 +0300 Subject: [PATCH 7/7] docs(auth): add docs for react auth hooks --- docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx | 2 +- docs/react/auth/hooks/useSignOutMutation.mdx | 2 +- docs/react/auth/hooks/useUpdateCurrentUserMutation.mdx | 2 +- docs/react/auth/hooks/useVerifyPasswordResetCodeMutation.mdx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx b/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx index fcce15b..48309a3 100644 --- a/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx +++ b/docs/react/auth/hooks/useSignInWithEmailAndPasswordMutation.mdx @@ -54,7 +54,7 @@ function SignInComponent() { ### Parameters --`auth`: The Firebase `Auth` instance used to manage authentication. +- `auth`: The Firebase `Auth` instance used to manage authentication. - `options` (optional): An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: - `onSuccess`: Callback fired when the mutation succeeds. diff --git a/docs/react/auth/hooks/useSignOutMutation.mdx b/docs/react/auth/hooks/useSignOutMutation.mdx index 6ac4625..7f8883a 100644 --- a/docs/react/auth/hooks/useSignOutMutation.mdx +++ b/docs/react/auth/hooks/useSignOutMutation.mdx @@ -52,7 +52,7 @@ function SignOutComponent() { ### Parameters --`auth`: The Firebase `Auth` instance used to manage authentication. +- `auth`: The Firebase `Auth` instance used to manage authentication. - `options` (optional): An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: - `onSuccess`: Callback fired when the mutation succeeds. diff --git a/docs/react/auth/hooks/useUpdateCurrentUserMutation.mdx b/docs/react/auth/hooks/useUpdateCurrentUserMutation.mdx index edea49e..2eb8de6 100644 --- a/docs/react/auth/hooks/useUpdateCurrentUserMutation.mdx +++ b/docs/react/auth/hooks/useUpdateCurrentUserMutation.mdx @@ -53,7 +53,7 @@ function UpdateUserComponent() { ### Parameters --`auth`: The Firebase `Auth` instance used to manage authentication. +- `auth`: The Firebase `Auth` instance used to manage authentication. - `options` (optional): An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: - `onSuccess`: Callback fired when the mutation succeeds. diff --git a/docs/react/auth/hooks/useVerifyPasswordResetCodeMutation.mdx b/docs/react/auth/hooks/useVerifyPasswordResetCodeMutation.mdx index b740e37..b5e8f94 100644 --- a/docs/react/auth/hooks/useVerifyPasswordResetCodeMutation.mdx +++ b/docs/react/auth/hooks/useVerifyPasswordResetCodeMutation.mdx @@ -56,7 +56,7 @@ function VerifyResetCodeComponent() { ### Parameters --`auth`: The Firebase `Auth` instance used to manage authentication. +- `auth`: The Firebase `Auth` instance used to manage authentication. - `options` (optional): An object for customizing the mutation behavior. Accepts all options supported by TanStack Query's `useMutation`, such as: - `onSuccess`: Callback fired when the mutation succeeds.