1
\$\begingroup\$

I have several routes, and I need Facebook authentication only in the routes that start with /admin:

app.get('/admin/dashboard', passport.ensureAuthenticated, .....);
app.get('/admin/dashboard/new/email', passport.ensureAuthenticated, ....);
app.get('/admin/dashboard/new/question', passport.ensureAuthenticated, ....);
app.get('/admin/dashboard/new/answer', passport.ensureAuthenticated, ....);
app.get('/admin/dashboard/new/etc', passport.ensureAuthenticated, ....);

If I can't use the app.use, is there anyone to call passport.ensureAuthenticated repetition in routes that start with /admin?

Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked Feb 2, 2015 at 16:13
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

From Express docs:

Path

// will match paths starting with /abcd
app.use('/abcd', function (req, res, next) {
 next();
})

Path Pattern

// will match paths starting with /abcd and /abd
app.use('/abc?d', function (req, res, next) {
 next();
})
// will match paths starting with /abcd, /abbcd, /abbbbbcd and so on
app.use('/ab+cd', function (req, res, next) {
 next();
})
// will match paths starting with /abcd, /abxcd, /abFOOcd, /abbArcd and so on
app.use('/ab*cd', function (req, res, next) {
 next();
})
// will match paths starting with /ad and /abcd
app.use('/a(bc)?d', function (req, res, next) {
 next();
})

Regular Expression

// will match paths starting with /abc and /xyz
app.use(/\/abc|\/xyz/, function (req, res, next) {
 next();
})

Array

// will match paths starting with /abcd, /xyza, /lmn, and /pqr
app.use(['/abcd', '/xyza', /\/lmn|\/pqr/], function (req, res, next) {
 next();
})
answered Feb 3, 2015 at 17:36
\$\endgroup\$
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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