Liana.ensureAuthenticated doesn't work for custom route
alexprice1 opened this issue · comments
I am having a problem using Liana.ensureAuthenticated
for a custom route. I followed the directions of putting the route prior to using Liana.init
, which makes sense so we can use next
to allow liana to handle the request, but then it fails since req.user
is not defined yet. My code looks like this:
app.put('/forest/opportunities/:opportunityId', Liana.ensureAuthenticated, saveImageToS3);
app.use(Liana.init({
modelsDir: require('path').join(__dirname, '/models'), // Your models directory.
envSecret: process.env.FOREST_ENV_SECRET,
authSecret: process.env.FOREST_AUTH_SECRET,
mongoose: require('mongoose')
}));
It never gets to saveImageToS3 since it fails at auth.js
Hi @alexprice91 You might want to take a look at our app.js where we implemented different strategies to unlock our custom routes: https://github.com/chez-nestor/backoffice/blob/master/src/app.js
Hey @alexprice1, sorry for the late response.
Can you detail a bit your usecase? Why do you need to define this custom route?
Thanks!
Hey @alexprice1, this is now fixed in the latest express liana versions:
- Express - 2.0.6
- Express-Sequelize - 2.0.4
- Express-Mongoose - 2.0.6
You can override the Admin API like you did:
app.put('/forest/opportunities/:opportunityId', Liana.ensureAuthenticated, saveImageToS3);
Let me know if it is ok for you.
🎄🎄🎄