فهرست منبع

Enable reCaptcha only for production

poeti8 6 سال پیش
والد
کامیت
f41a17a3d8
3فایلهای تغییر یافته به همراه18 افزوده شده و 12 حذف شده
  1. 16 10
      client/components/Footer/ReCaptcha.js
  2. 1 1
      client/components/Shortener/Shortener.js
  3. 1 1
      server/controllers/authController.js

+ 16 - 10
client/components/Footer/ReCaptcha.js

@@ -6,15 +6,21 @@ const Recaptcha = styled.div`
   margin: 54px 0 16px;
   margin: 54px 0 16px;
 `;
 `;
 
 
-const ReCaptcha = () => (
-  <Recaptcha
-    id="g-recaptcha"
-    className="g-recaptcha"
-    data-sitekey={process.env.RECAPTCHA_SITE_KEY}
-    data-callback="recaptchaCallback"
-    data-size="invisible"
-    data-badge="inline"
-  />
-);
+const ReCaptcha = () => {
+  if (process.env.NODE_ENV !== 'production') {
+    return null;
+  }
+
+  return (
+    <Recaptcha
+      id="g-recaptcha"
+      className="g-recaptcha"
+      data-sitekey={process.env.RECAPTCHA_SITE_KEY}
+      data-callback="recaptchaCallback"
+      data-size="invisible"
+      data-badge="inline"
+    />
+  );
+};
 
 
 export default ReCaptcha;
 export default ReCaptcha;

+ 1 - 1
client/components/Shortener/Shortener.js

@@ -81,7 +81,7 @@ class Shortener extends Component {
     const password = pwd && pwd.value;
     const password = pwd && pwd.value;
     const options = isAuthenticated && { customurl, password };
     const options = isAuthenticated && { customurl, password };
     shortenerForm.reset();
     shortenerForm.reset();
-    if (!isAuthenticated) {
+    if (process.env.NODE_ENV === 'production' && !isAuthenticated) {
       window.grecaptcha.execute(window.captchaId);
       window.grecaptcha.execute(window.captchaId);
       const getCaptchaToken = () => {
       const getCaptchaToken = () => {
         setTimeout(() => {
         setTimeout(() => {

+ 1 - 1
server/controllers/authController.js

@@ -75,7 +75,7 @@ exports.authApikey = authenticate('localapikey', 'API key is not correct.', fals
 
 
 /* reCaptcha controller */
 /* reCaptcha controller */
 exports.recaptcha = async (req, res, next) => {
 exports.recaptcha = async (req, res, next) => {
-  if (!req.user) {
+  if (process.env.NODE_ENV === 'production' && !req.user) {
     const isReCaptchaValid = await axios({
     const isReCaptchaValid = await axios({
       method: 'post',
       method: 'post',
       url: 'https://www.google.com/recaptcha/api/siteverify',
       url: 'https://www.google.com/recaptcha/api/siteverify',