A simple NodeJS + Express site all set up and ready to go with username+password authentication using Passport and Passport-Local, persistent local cookies using Passport-Remember-Me-Extended, persistent session using Express-Session and MongoDB via Mongoose and view templates using EJS.
The site includes a login page, a signup page and an index page that requires authentication and the pages are styled using Bootstrap.
routes\index.js
:
GET('/')
- Verifies that the user is authenticated (redirects to
/login
on failure). - Renders
views\index.ejs
routes\login.js
:
GET('/login')
- Renders
views\login.ejs
POST('/login')
- Form submission from the login form.
- Redirects to
'/'
on success.
routes\signup.js
GET('/signup')
- Renders
views\signup.ejs
POST('/signup')
- Form submission for the signup form.
- Redirects to
'/'
on success.
The \data\
folder contains:
This represents site-specific data (title
and description
) that is passed on to the view templates.
This file provides the authentication token and methods for generating, saving and consuming tokens.
This file provides the user model that is used (and persisted to MongoDB) for authentication and storing the user's credentials.
- Update the details for your own site in
package.json
, specifically thename
andversion
. - Update the
title
anddescription
of your site in\data\site.js
- Update the
rootURL
for your production site in\config\authentication.js
- Update the connect string for your MongoDB database in
\config\database.js
- Update the session cookie
secret
inapp.js
From here you should be ready to go. Enjoy!