41 lines
1.5 KiB
TypeScript

import { apiUrls } from '~/driven/utils/configs/appConfig';
import { HttpOptionsType } from '~/driven/boundaries/http-boundary/protocols';
import { HTTPPovider } from '~/driven/boundaries/http-boundary/httpBoundary';
import { IOtpAuthDrivenPort } from '~/business-logic/generic/admin-user/authentication/otp-auth/port';
import { OtpAuthResponse } from '~/business-logic/generic/admin-user/authentication/otp-auth/data/reponse-object/otpAuthRO';
import { OtpAuthDTOReturnType } from '~/business-logic/generic/admin-user/authentication/otp-auth/data/dto/otpAuthDto';
import AdminUserModel from '~/business-logic/generic/admin-user/common/data/model/adminUserModel';
const authAdminLogin = (
userAdmin: AdminUserModel | null,
updateAccessToken: (newAccessToken: string) => void,
navigateToAuth: () => void,
): IOtpAuthDrivenPort => {
const httpProvider = new HTTPPovider(
{
accessToken: userAdmin && userAdmin.adminUserData.accessToken && null,
refreshToken: userAdmin && userAdmin.adminUserData.refreshToken && null,
},
updateAccessToken,
navigateToAuth,
);
const httpHandler = (data: OtpAuthDTOReturnType): Promise<OtpAuthResponse> => {
const url = apiUrls.generic.authLogin;
const options: HttpOptionsType = {
url,
headers: {
'Content-Type': 'application/json',
},
method: 'POST',
data,
};
return httpProvider.request<OtpAuthResponse>(options);
};
return {
httpHandler,
};
};
export default authAdminLogin;