Confirm and password emails sending

This commit is contained in:
2025-03-22 23:46:27 -04:00
parent 4d7585c770
commit 3b738c337b
5 changed files with 228 additions and 2 deletions

View File

@@ -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;
}
}
}
});
}