Skip to content

Instantly share code, notes, and snippets.

@theRemix
Last active August 29, 2015 14:16
Show Gist options
  • Save theRemix/0682da9df82a2f9bd576 to your computer and use it in GitHub Desktop.
Save theRemix/0682da9df82a2f9bd576 to your computer and use it in GitHub Desktop.
Adding Auth to MEH

Adding Auth to Express App

using Passport

Username & Password 'passport-local' strategy

Use these as a guides
http://passportjs.org/guide/configure/
http://passportjs.org/guide/username-password/

The app will need to setup and enable sessions.

The app will need another Mongoose model (and schema) called User.

{
  username : String,
  password : String  // this will be unencrypted for now
}

Manually create your admin user in mongo.

You will need a login page, and a login route.
This is what the new routes would look like:

method path action response
GET /login login_form renders a jade template login form
POST /login login uses passport module to authenticate. On success: redirect to admin On fail: redirect to login_form
GET /logout logout destroys the current session then redirects to /
GET /admin admin gets all [resources] then renders a jade template that lists all items with edit and delete buttons
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment