jaredhanson/connect-ensure-login — pull request #5 by nmallinar (2013-07-21 01:32:35+00:00)
Title: Require authentication on all paths but allow assets

I found that it was convenient for me to use app.all('*', connect.ensureLoggedIn('/login'), ...) to require authentication on all paths, however I still wanted to allow /login, /signup and /about. I put those three paths above the app.all and it worked except that assets weren't loaded without authentication ('/images/* and /stylesheets/*).

To solve this I used underscore to check an array of strings if req.path is contained and if so next, this allows me to use app.all and require authentication on all paths but still have select assets available to the login, signup, and about pages.

Maybe there's a better way to do this, but I don't know of it and this was the best solution I had so I just wanted to share it with you.