2025-01-27 15:03:48 +03:00
|
|
|
import { queryOptions } from '@tanstack/react-query';
|
|
|
|
|
2025-02-03 18:17:44 +03:00
|
|
|
import { axiosGet, axiosPatch, axiosPost } from '@/backend/apiTransport';
|
2025-01-27 15:03:48 +03:00
|
|
|
import { DELAYS } from '@/backend/configuration';
|
2025-02-12 20:53:31 +03:00
|
|
|
import { infoMsg } from '@/utils/labels';
|
|
|
|
|
|
|
|
import {
|
|
|
|
IChangePasswordDTO,
|
|
|
|
ICurrentUser,
|
|
|
|
IPasswordTokenDTO,
|
|
|
|
IRequestPasswordDTO,
|
|
|
|
IResetPasswordDTO,
|
|
|
|
IUserLoginDTO
|
|
|
|
} from './types';
|
2025-01-27 15:03:48 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Authentication API.
|
|
|
|
*/
|
|
|
|
export const authApi = {
|
|
|
|
baseKey: 'auth',
|
|
|
|
|
|
|
|
getAuthQueryOptions: () => {
|
|
|
|
return queryOptions({
|
|
|
|
queryKey: [authApi.baseKey, 'user'],
|
|
|
|
staleTime: DELAYS.staleLong,
|
|
|
|
queryFn: meta =>
|
2025-01-28 19:47:24 +03:00
|
|
|
axiosGet<ICurrentUser>({
|
|
|
|
endpoint: '/users/api/auth',
|
|
|
|
options: { signal: meta.signal }
|
|
|
|
})
|
2025-01-27 15:03:48 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2025-01-28 19:47:24 +03:00
|
|
|
logout: () => axiosPost({ endpoint: '/users/api/logout' }),
|
|
|
|
|
|
|
|
login: (data: IUserLoginDTO) =>
|
|
|
|
axiosPost({
|
|
|
|
endpoint: '/users/api/login',
|
|
|
|
request: { data: data }
|
|
|
|
}),
|
|
|
|
changePassword: (data: IChangePasswordDTO) =>
|
2025-02-03 18:17:44 +03:00
|
|
|
axiosPatch({
|
2025-01-28 19:47:24 +03:00
|
|
|
endpoint: '/users/api/change-password',
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:35:41 +03:00
|
|
|
successMessage: infoMsg.changesSaved
|
2025-01-28 19:47:24 +03:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
requestPasswordReset: (data: IRequestPasswordDTO) =>
|
|
|
|
axiosPost({
|
|
|
|
endpoint: '/users/api/password-reset',
|
|
|
|
request: { data: data }
|
|
|
|
}),
|
|
|
|
validatePasswordToken: (data: IPasswordTokenDTO) =>
|
|
|
|
axiosPost({
|
|
|
|
endpoint: '/users/api/password-reset/validate',
|
|
|
|
request: { data: data }
|
|
|
|
}),
|
|
|
|
resetPassword: (data: IResetPasswordDTO) =>
|
|
|
|
axiosPost({
|
|
|
|
endpoint: '/users/api/password-reset/confirm',
|
|
|
|
request: { data: data }
|
|
|
|
})
|
2025-01-27 15:03:48 +03:00
|
|
|
};
|