1

I want to use the EmailJS service to send info from a contact form. However, I have several issues

  1. In the head section should add the following script

     <script type="text/javascript">
         (function() {
             emailjs.init('my-token');
         })();
     </script>
    

How can I hide that token? I have tried storing it in the .env file and accessing it with

emailjs.init(`${process.env.REACT_APP_INIT_KEY}`);

But that didn't work.

4
  • the only way to store API key is in backend language like nodejs ,php, etc. Commented May 27, 2022 at 9:34
  • 1
    relevant answer for this stackoverflow.com/questions/48699820/… Commented May 27, 2022 at 9:35
  • Hi @RobinHood thanks for sharing the relevant answer, which makes sense. I will look into that. Commented May 27, 2022 at 9:39
  • Does this answer your question? How do I hide an API key in Create React App? Commented Feb 2, 2024 at 3:49

2 Answers 2

1

You shouldn't. Secrets should be kept on the backend.

Using JavaScript obfuscation techniques to hide an API key on the frontend won't protect it.

Sign up to request clarification or add additional context in comments.

Comments

0

Create index.js file at the same level of your html file, and put this statement in it emailjs.init('my-token');, then call this file in your html page.

your code:

<script type="text/javascript">
     (function() {
         emailjs.init('my-token');
     })();
 </script>

the solution:

in index.js file

function() {
         emailjs.init('my-token');
     })();

call it in Html file

  <script type="text/javascript" src="index.js"></script>

1 Comment

This absolutely won't hide the token

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.