So I have a project that has 4 api keys that I need hidden:
STORYBLOK_API_KEY=
EMAILJS_SERVICE_ID=
EMAILJS_USER_ID=
EMAILJS_TEMPLATE_ID=
All 4 of them I am using with process.env.XXX, the funny thing is that, the storyblok key is working (but it is not used within a component), however the other 3 I am using within a form submission function:
const sendContactForm = async (formData) => {
const data = {
service_id: process.env.EMAILJS_SERVICE_ID,
template_id: process.env.EMAILJS_TEMPLATE_ID,
user_id: process.env.EMAILJS_USER_ID,
template_params: { ...formData, form: "Discover form" },
};
try {
const response = await axios.post("https://api.emailjs.com/api/v1.0/email/send", data);
console.log(response);
} catch (e) {
console.log(e);
}
};
And they are not working here, they are undefined. I have tried:
- dev server
- build and start the production server
- deploy on Vercel and set the environment variables there
All 3 approaches did not work.