62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import type {
|
|
AuthResponseData,
|
|
ForgotPasswordPayload,
|
|
LoginPayload,
|
|
MeResponse,
|
|
PermissionResponse,
|
|
SetPasswordPayload,
|
|
} from '@/types';
|
|
import { API_ROUTES } from '@/constants/apiRoutes';
|
|
import axiosClient, { axiosAuth } from '../axios/axios';
|
|
|
|
export const authService = {
|
|
login: async (payload: LoginPayload): Promise<AuthResponseData> => {
|
|
const response = await axiosAuth.post<AuthResponseData>(
|
|
API_ROUTES.AUTH.LOGIN,
|
|
payload,
|
|
);
|
|
return response.data;
|
|
},
|
|
refresh: async (): Promise<AuthResponseData> => {
|
|
const response = await axiosAuth.post<AuthResponseData>(
|
|
API_ROUTES.AUTH.REFRESH,
|
|
{},
|
|
);
|
|
return response.data;
|
|
},
|
|
logout: async (): Promise<void> => {
|
|
await axiosAuth.post(API_ROUTES.AUTH.LOGOUT, {});
|
|
},
|
|
me: async (): Promise<MeResponse> => {
|
|
const response = await axiosClient.get<MeResponse>(API_ROUTES.AUTH.ME);
|
|
return response.data;
|
|
},
|
|
permissions: async (): Promise<PermissionResponse> => {
|
|
const response = await axiosClient.get<PermissionResponse>(
|
|
API_ROUTES.PERMISSIONS.MY_PERMISSIONS,
|
|
);
|
|
return response.data;
|
|
},
|
|
forgotPassword: async (payload: ForgotPasswordPayload): Promise<unknown> => {
|
|
const response = await axiosAuth.post(
|
|
API_ROUTES.AUTH.FORGOT_PASSWORD,
|
|
payload,
|
|
);
|
|
return response.data;
|
|
},
|
|
resetPassword: async (payload: SetPasswordPayload): Promise<unknown> => {
|
|
const response = await axiosAuth.post(
|
|
API_ROUTES.AUTH.RESET_PASSWORD,
|
|
payload,
|
|
);
|
|
return response.data;
|
|
},
|
|
setPassword: async (payload: SetPasswordPayload): Promise<unknown> => {
|
|
const response = await axiosAuth.post(
|
|
API_ROUTES.AUTH.SET_PASSWORD,
|
|
payload,
|
|
);
|
|
return response.data;
|
|
},
|
|
};
|