This commit is contained in:
giancarlo
2024-03-24 02:23:22 +08:00
parent 648d77b430
commit bce3479368
589 changed files with 37067 additions and 9596 deletions

View File

@@ -0,0 +1,40 @@
import { useMutation } from '@tanstack/react-query';
import { useSupabase } from './use-supabase';
interface Params {
email: string;
redirectTo: string;
}
/**
* @name useRequestResetPassword
* @description Requests a password reset for a user. This function will
* trigger a password reset email to be sent to the user's email address.
* After the user clicks the link in the email, they will be redirected to
* /password-reset where their password can be updated.
*/
export function useRequestResetPassword() {
const client = useSupabase();
const mutationKey = ['auth', 'reset-password'];
const mutationFn = async (params: Params) => {
const { error, data } = await client.auth.resetPasswordForEmail(
params.email,
{
redirectTo: params.redirectTo,
},
);
if (error) {
throw error;
}
return data;
};
return useMutation({
mutationFn,
mutationKey,
});
}