import axios from 'axios'; export interface SendEmailOtpResponse { success: boolean; errorCode: number; message: string; validations: { message: string; code: number; property: string; severity: number; }[]; } export interface TokenResponse { access_token: string; expires_in: number; refresh_token: string; } const SEND_EMAIL_OTP_URL = 'https://account.business-harmony.com/api/User/SendEmailOtp'; const TOKEN_URL = 'https://account.business-harmony.com/connect/token'; export async function sendEmailOtp( email: string, ): Promise { const { data } = await axios.post(SEND_EMAIL_OTP_URL, { email, }); return data; } export async function fetchAuthToken( email: string, otpCode: string, ): Promise { await sendEmailOtp(email); const body = new URLSearchParams({ grant_type: 'otp', client_id: 'harmony_identity', phonenumber: '', email, otp_code: otpCode, scope: 'openid profile offline_access harmony_identity', }).toString(); const { data } = await axios.post(TOKEN_URL, body, { headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, }); localStorage.setItem('authToken', data.access_token); return data; }