Confirm and password emails sending
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Account } from "@/interface/Account";
|
||||
import { api } from "@/util/AxiosUtil";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
|
||||
export function useSignup(){
|
||||
@@ -18,3 +19,77 @@ export function useSignup(){
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export function useConfirm(){
|
||||
return useMutation({
|
||||
mutationKey: ["confirm"],
|
||||
mutationFn: async (confirmToken: string) => {
|
||||
try{
|
||||
const response = await api.post(`/auth/confirm/${confirmToken}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useForgotPassword(){
|
||||
return useMutation({
|
||||
mutationKey: ["forgotPassword"],
|
||||
mutationFn: async (username: string) => {
|
||||
const params = new URLSearchParams();
|
||||
params.append("username", username);
|
||||
|
||||
|
||||
try{
|
||||
const response = await api.post(`/auth/forgot?${params}`);
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function useForgotResetPassword(forgotToken: string){
|
||||
return useMutation({
|
||||
mutationKey: ["forgotResetPassword"],
|
||||
mutationFn: async (password: string) => {
|
||||
try{
|
||||
const response = await api.post(`/auth/forgot/${forgotToken}`, {password});
|
||||
|
||||
if(response.data.errors){
|
||||
throw new Error(response.data.errors.join(", "));
|
||||
}
|
||||
}
|
||||
catch(error){
|
||||
if(error instanceof AxiosError && error.response?.data.errors){
|
||||
throw new Error(error.response?.data.errors.join(", "));
|
||||
}
|
||||
else{
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user