2024-11-20 14:22:22 +01:00
|
|
|
import axios from "axios";
|
|
|
|
|
|
2024-11-21 18:01:12 +01:00
|
|
|
export async function getOtpFromSink(key: string): Promise<any> {
|
2024-11-20 14:22:22 +01:00
|
|
|
try {
|
|
|
|
|
const response = await axios.post(
|
2024-11-20 16:03:20 +01:00
|
|
|
process.env.SINK_NOTIFICATION_URL!,
|
2024-11-20 14:22:22 +01:00
|
|
|
{
|
|
|
|
|
recipient: key,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
Authorization: `Bearer ${process.env.ZITADEL_SERVICE_USER_TOKEN}`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (response.status >= 400) {
|
|
|
|
|
const error = `HTTP Error: ${response.status} - ${response.statusText}`;
|
|
|
|
|
console.error(error);
|
|
|
|
|
throw new Error(error);
|
|
|
|
|
}
|
|
|
|
|
return response.data.args.oTP;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error making request:", error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-11-21 18:01:12 +01:00
|
|
|
|
|
|
|
|
export async function getCodeFromSink(key: string): Promise<any> {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios.post(
|
|
|
|
|
process.env.SINK_NOTIFICATION_URL!,
|
|
|
|
|
{
|
|
|
|
|
recipient: key,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
headers: {
|
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
|
Authorization: `Bearer ${process.env.ZITADEL_SERVICE_USER_TOKEN}`,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (response.status >= 400) {
|
|
|
|
|
const error = `HTTP Error: ${response.status} - ${response.statusText}`;
|
|
|
|
|
console.error(error);
|
|
|
|
|
throw new Error(error);
|
|
|
|
|
}
|
|
|
|
|
return response.data.args.code;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error("Error making request:", error);
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
|
|
|
|
}
|