This is a starter code for building a simple user authenctication gateway for an application. The code is structured according to the MVC framework.
At the end of this tutorial, you should be able to do the following:
- Server-side validation using
express-validator
- Hashing plain text information like passwords using
bcrypt
- Manage sessions through the use of
express-session
andconnect-mongo
for the storage in a MongoDB database - Error handling and redirection for unauthenticated users (with the help of flash messages using
connect-flash
)
This tutorial assumes you already have pre-existing knowledge on the following libraries:
- Express.js
- MongoDB + mongoose
- Handlebars (specifically
express-handlebars
)
- NodeJS & npm
- MongoDB Community Edition or MongoDB Atlas Cluster
- Any text editor for JavaScript, HTML & CSS (VSCode, Atom, SublimeText, etc.)
- Fork this repository to create a copy on your GitHub account.
- Clone the forked repository to your machine.
git clone https://github.com/YOUR_USERNAME/node-login-starter.git
- Navigate to the directory.
cd node-login-starter
- Install the dependencies in package.json. All needed packages are already included.
npm install
- Run the server using the script defined (using
nodemon
)
npm run dev
- Navigate to http://localhost:9090/register. You should see the registration page.
The application currently does not do anything yet except redirect to the next routes on the assumption that input is valid. Test out the navigation by clicking the buttons and the links.
Since this is quite complex and there are three main aspects to authentication, instructions for each component will be separated to individual files. It will be listed in INSTRUCTIONS.md
.
Markdown is a markup language with wherein you can type things in plain-text but with the right rendering app, it will automatically style the text for you. Kindly open the INSTRUCTIONS.md
and all other .md
files in GitHub or use a Markdown Preview extension with your text editor:
- Visual Studio Code - Already included, simply toggle the preview
- Atom - Package for installation
- Brackets - Package for installation
- SublimeText - Package for installation