|
import { useMutation } from "@tanstack/react-query"; |
|
import { endpoints } from "@/utils/endpoints"; |
|
import { |
|
ChangePasswordErrorType, |
|
ChangePasswordRequestType, |
|
ChangePasswordResponseType, |
|
LoginSchemaType, |
|
RegisterRequestType, |
|
ResetPasswordCodeErrorType, |
|
ResetPasswordCodeRequestType, |
|
ResetPasswordCodeResponseType, |
|
ResetPasswordEmailRequestType, |
|
ResetPasswordNewPasswordErrorType, |
|
ResetPasswordNewPasswordRequestType, |
|
} from "./auth.types"; |
|
import BaseService from "../base.service"; |
|
|
|
class AuthService extends BaseService { |
|
public useLogin = () => |
|
useMutation({ |
|
mutationFn: async (data: LoginSchemaType) => { |
|
const response = await this.client.post(endpoints.auth.login, { |
|
...data, |
|
}); |
|
|
|
return response; |
|
}, |
|
}); |
|
|
|
public useRegister = () => |
|
useMutation({ |
|
mutationFn: async (data: RegisterRequestType) => { |
|
const response = await this.client.post(endpoints.auth.register, { |
|
...data, |
|
}); |
|
|
|
return response; |
|
}, |
|
}); |
|
|
|
public useResetPasswordEmail = () => |
|
useMutation({ |
|
mutationFn: async (data: ResetPasswordEmailRequestType) => { |
|
const response = await this.client.post( |
|
endpoints.auth.password.reset.email, |
|
data, |
|
); |
|
return response; |
|
}, |
|
}); |
|
|
|
public useResetPasswordCode = () => |
|
this.useMutationRequest< |
|
ResetPasswordCodeRequestType, |
|
ResetPasswordCodeResponseType, |
|
ResetPasswordCodeErrorType |
|
>(endpoints.auth.password.reset.code); |
|
|
|
public useResetPasswordNewPassword = () => |
|
this.useMutationRequest< |
|
ResetPasswordNewPasswordRequestType, |
|
any, |
|
ResetPasswordNewPasswordErrorType |
|
>(endpoints.auth.password.reset.password); |
|
|
|
public useChangePassword = () => |
|
this.useMutationRequest< |
|
ChangePasswordRequestType, |
|
ChangePasswordResponseType, |
|
ChangePasswordErrorType |
|
>(endpoints.auth.password.change); |
|
} |
|
|
|
const authService = new AuthService(); |
|
|
|
export default authService; |