2025-01-21 20:33:05 +03:00
|
|
|
import { queryOptions } from '@tanstack/react-query';
|
|
|
|
|
2025-02-03 18:17:07 +03:00
|
|
|
import { axiosGet, axiosPatch, axiosPost } from '@/backend/apiTransport';
|
2025-02-19 19:15:57 +03:00
|
|
|
import { DELAYS, KEYS } from '@/backend/configuration';
|
2025-02-12 20:53:01 +03:00
|
|
|
import { infoMsg } from '@/utils/labels';
|
|
|
|
|
|
|
|
import {
|
2025-02-20 20:22:05 +03:00
|
|
|
type IChangePasswordDTO,
|
|
|
|
type ICurrentUser,
|
|
|
|
type IPasswordTokenDTO,
|
|
|
|
type IRequestPasswordDTO,
|
|
|
|
type IResetPasswordDTO,
|
|
|
|
type IUserLoginDTO
|
2025-02-12 20:53:01 +03:00
|
|
|
} from './types';
|
2025-01-21 20:33:05 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Authentication API.
|
|
|
|
*/
|
|
|
|
export const authApi = {
|
2025-02-19 19:15:57 +03:00
|
|
|
baseKey: KEYS.auth,
|
2025-01-21 20:33:05 +03:00
|
|
|
|
|
|
|
getAuthQueryOptions: () => {
|
|
|
|
return queryOptions({
|
|
|
|
queryKey: [authApi.baseKey, 'user'],
|
2025-01-23 19:41:31 +03:00
|
|
|
staleTime: DELAYS.staleLong,
|
2025-01-21 20:33:05 +03:00
|
|
|
queryFn: meta =>
|
2025-01-28 19:45:31 +03:00
|
|
|
axiosGet<ICurrentUser>({
|
|
|
|
endpoint: '/users/api/auth',
|
|
|
|
options: { signal: meta.signal }
|
|
|
|
})
|
2025-01-21 20:33:05 +03:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2025-01-28 19:45:31 +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:07 +03:00
|
|
|
axiosPatch({
|
2025-01-28 19:45:31 +03:00
|
|
|
endpoint: '/users/api/change-password',
|
|
|
|
request: {
|
|
|
|
data: data,
|
2025-02-12 01:34:35 +03:00
|
|
|
successMessage: infoMsg.changesSaved
|
2025-01-28 19:45:31 +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-21 20:33:05 +03:00
|
|
|
};
|