pdupavillon / express-recaptcha

Implementation of google recaptcha v2 & V3 solutions for express.js
MIT License
128 stars 21 forks source link

Express recaptcha on several routes #18

Closed sigfriedCub1990 closed 6 years ago

sigfriedCub1990 commented 6 years ago

This may not be an issue with express-recaptcha itself, but this is driving me crazy, I've made some research on stackoverflow and Google but I couldn't find any solutions on how to do this. What I'm trying to do is:

userController.js

app.get('/user/login', recaptcha.middleware.render,this.login);

login: function (req, res) {
    if (req.user) {
        res.redirect('/admin');
    } else {
        res.render('user/login', {title: 'Login', catpcha: res.recaptcha});
    }
}

registerController.js

app.get('/register', recaptcha.middleware.render, this.register)

register: function(req, res) {
   res.render('index', {title: 'Home', captcha: res.recaptcha})
}

But recaptcha is only rendered on the first route, not the second. This is a reduced version of my package.json:

   "express": "^4.13.4",
   "express-recaptcha": "^4.0.2"

I've included the packages I thought were needed.

NOTE: I've excluded Recaptcha constructor on purpose

pdupavillon commented 6 years ago

Hi @sigfriedCub1990, Did you find a way to solve your issue ?

Thanks

sigfriedCub1990 commented 6 years ago

Yes @pdupavillon, I'm really sorry, the error was a typo in the variable name. express-recatpcha works like charm, thank you very much.