58 lines
1.6 KiB
TypeScript
58 lines
1.6 KiB
TypeScript
import {
|
|
type SendEmailOtpPayload,
|
|
type TokenApiResponse,
|
|
type ConfirmEmailOtpPayload,
|
|
type CompleteUserInfoPayload,
|
|
type CompleteUserInfoResponse,
|
|
type GenericApiResponse,
|
|
} from '../types/completionFormApiTypes';
|
|
import axios from 'axios';
|
|
import apiClient from '@/lib/apiClient';
|
|
|
|
const AUTH_API_URL = 'https://accounts.business-harmony.com';
|
|
|
|
export const getTokenApi = async (): Promise<TokenApiResponse> => {
|
|
const body = new URLSearchParams();
|
|
body.set('grant_type', 'password');
|
|
body.set('username', '+989353989651');
|
|
body.set('password', '123@Qweasd');
|
|
body.set('client_id', 'harmony_identity');
|
|
body.set('scope', 'openid harmony_identity profile offline_access');
|
|
|
|
const { data } = await axios.post<TokenApiResponse>(
|
|
`${AUTH_API_URL}/connect/token`,
|
|
body.toString(),
|
|
{
|
|
headers: {
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
},
|
|
},
|
|
);
|
|
localStorage.setItem('authToken', data.access_token);
|
|
return data;
|
|
};
|
|
|
|
export const sendEmailOtpApi = async (
|
|
payload: SendEmailOtpPayload,
|
|
): Promise<GenericApiResponse & { codeSentAnyway?: boolean }> => {
|
|
const { data } = await apiClient.post('/User/SendEmailOtp', payload);
|
|
return data;
|
|
};
|
|
|
|
export const confirmEmailOtpApi = async (
|
|
payload: ConfirmEmailOtpPayload,
|
|
): Promise<GenericApiResponse> => {
|
|
const { data } = await apiClient.post('/User/ConfirmEmailOtp', payload);
|
|
return data;
|
|
};
|
|
|
|
export const completeUserInformationApi = async (
|
|
payload: CompleteUserInfoPayload,
|
|
): Promise<CompleteUserInfoResponse> => {
|
|
const { data } = await apiClient.post(
|
|
'/User/CompleteUserInformation',
|
|
payload,
|
|
);
|
|
return data;
|
|
};
|