29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import type { AuthResponseData, LoginPayload, MeResponse, PermissionResponse } from '@/types';
|
|
import axiosClient, { axiosAuth } from '../axios/axios';
|
|
|
|
export const authService = {
|
|
login: async (payload: LoginPayload): Promise<AuthResponseData> => {
|
|
const response = await axiosAuth.post<AuthResponseData>('api/auth/login', payload, {
|
|
withCredentials: true,
|
|
});
|
|
return response.data;
|
|
},
|
|
refresh: async (): Promise<AuthResponseData> => {
|
|
const response = await axiosAuth.post<AuthResponseData>('api/auth/refresh', {}, {
|
|
withCredentials: true,
|
|
});
|
|
return response.data;
|
|
},
|
|
logout: async (): Promise<void> => {
|
|
await axiosAuth.post('api/auth/logout', {}, { withCredentials: true });
|
|
},
|
|
me: async (): Promise<MeResponse> => {
|
|
const response = await axiosClient.get<MeResponse>('api/auth/me');
|
|
return response.data;
|
|
},
|
|
permissions: async (): Promise<PermissionResponse> => {
|
|
const response = await axiosClient.get<PermissionResponse>('api/permissions/my-permissions');
|
|
return response.data;
|
|
},
|
|
};
|