Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect after Basic Http Auth Express.js

I want to make a private access to an application using express.js like .htaccess and .htpasswd do in my php project.

I'm using http-auth

Here is my code :

app.get('/', function(req, res) {
  basic.apply(req, res, function(username) {
    res.redirect(routes.index);
  });
});

The problem is I get an error :

500 TypeError: Object function (req, res){ res.render('index', { title: 'Express' }); } has no method 'indexOf'

Without authentication,

app.get('/', routes.index);

works without any troubles.

I think about a middleware to read my index and then use res.send()... May it works? or what did I miss?

like image 784
Jérôme Avatar asked Feb 06 '26 16:02

Jérôme


1 Answers

I think the argument to res.redirect needs to be a URL string, right ? You seem to be passing in a request handler (function (req, res) {...}).

like image 183
lmjohns3 Avatar answered Feb 09 '26 10:02

lmjohns3



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!