Spaces:
Paused
Paused
File size: 2,708 Bytes
ecafd26 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | const axios = require('axios');
const OTP_API_BASE_URL = 'https://mail-steel.vercel.app';
class OtpService {
constructor() {
this.axios = axios.create({
baseURL: OTP_API_BASE_URL,
timeout: 10000
});
}
// Send OTP to user email
async sendUserOtp(email) {
try {
const response = await this.axios.post('/send-otp', { email });
return response.data;
} catch (error) {
console.error('Error sending user OTP:', error.response?.data || error.message);
throw new Error(error.response?.data?.error || 'Failed to send OTP');
}
}
// Verify user OTP
async verifyUserOtp(email, otp) {
try {
const response = await this.axios.post('/verify-otp', { email, otp });
return response.data;
} catch (error) {
console.error('Error verifying user OTP:', error.response?.data || error.message);
throw new Error(error.response?.data?.error || 'Failed to verify OTP');
}
}
// Send OTP to admin email
async sendAdminOtp() {
try {
const response = await this.axios.post('/admin/send-otp');
return response.data;
} catch (error) {
console.error('Error sending admin OTP:', error.response?.data || error.message);
throw new Error(error.response?.data?.error || 'Failed to send admin OTP');
}
}
// Verify admin OTP
async verifyAdminOtp(otp) {
try {
const response = await this.axios.post('/admin/verify-otp', { otp });
return response.data;
} catch (error) {
console.error('Error verifying admin OTP:', error.response?.data || error.message);
throw new Error(error.response?.data?.error || 'Failed to verify admin OTP');
}
}
// Check OTP status
async checkOtpStatus() {
try {
const response = await this.axios.get('/otp-status');
return response.data;
} catch (error) {
console.error('Error checking OTP status:', error.response?.data || error.message);
throw new Error(error.response?.data?.error || 'Failed to check OTP status');
}
}
// Check API health
async checkHealth() {
try {
const response = await this.axios.get('/health');
return response.data;
} catch (error) {
console.error('Error checking API health:', error.response?.data || error.message);
throw new Error(error.response?.data?.error || 'Failed to check API health');
}
}
}
module.exports = new OtpService(); |