Skip to content

A small express middleware to check if the user is authenticated. Works best with PassportJS

License

Notifications You must be signed in to change notification settings

0xifis/passport-login-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

passport-login-check

This middleware ensures that a user is logged in. If a request is received where the user is unauthenticated, the request will be redirected to a login page.

Install

$ npm install passport-login-check

Usage

index.js

var l = require('passport-login-check')

//If req is unauthenticated, user will be redirected to this
l.defaultRedirectUrl = '/login'
//If req is unauthenticated, user will be returned to this after authentication
l.defaultReturnUrl = '/'

//Will redirect to defaultRedirectUrl if req is unauthenticated and return to defaultReturnUrl
app.use('/profile', l.loggedIn())
//Will return to /settings after authentication
app.use('/settings', l.loggedIn('/settings'))
//Will redirect to /auth/authentication if req is unauthenticated and return to /profile after authentication
app.use('/user/:id', l.loggedIn('/profile', '/auth/facebook'))

TODO

  1. Return to original URL if returnUrl is not specified
  2. URL Blacklisting
  3. Roles

Credits

License

The MIT License

Copyright (c) 2016 Vishnu R Menon <http://vishnurmenon.com/>

About

A small express middleware to check if the user is authenticated. Works best with PassportJS

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published