Mail sender is working

This commit is contained in:
2025-06-09 20:38:13 +02:00
parent 7fc1312ddc
commit 14bd178f84
2 changed files with 104 additions and 17 deletions

View File

@@ -0,0 +1,30 @@
import { useAuthStore } from "@/store/authStore";
const API_URL = "https://hopp.zikor.pl/api/v1";
export const sendEmail = async (emailData) => {
const token = useAuthStore.getState().token;
try {
const response = await fetch(`${API_URL}/email/send`, {
method: "POST",
headers: {
"Content-Type": "application/json",
...(token && { Authorization: `Bearer ${token}` }),
},
body: JSON.stringify(emailData),
});
if (!response.ok) {
const errorMessage = `HTTP error! Status: ${response.status}`;
console.error("Error sending email:", errorMessage);
return { success: false, error: errorMessage };
}
const result = await response.text();
return { success: true, result };
} catch (error) {
console.error("Error sending email:", error.message);
return { success: false, error: error.message };
}
};