DEV Community

James Perkins
James Perkins

Posted on

A Flexible Node Authentication Boilerplate With Email.

I recently completed a boilerplate for node authentication. I was tired of creating a new authentication for most of my node projects and decided that the community could use boilerplate that is lightweight(minimum amount of node modules) and ready for use for almost any scenario.

How?

Firstly there are two options currently the pure node implementation and then the container version.
Check it out from my GitHub choose docker branch if you want docker and master if you want the pure node.

Please note MongoDB is required for the storing of data. We also need sendgrid API for password resets Sendgrid

Once checked out make sure to make the following changes in the .env

APP_SECRET=somekey
SEND_GRID_EMAIL= your@email.com
SEND_GRID_USER=[sendgriduser]
SEND_GRID_PASS=[sendgridpass]

Node Implementation

  1. npm install
  2. npm run dev

Docker implementation

  1. docker build
  2. docker run image

API Routes

All routes run through the following
/api/auth/

to run register you need to call a post:

/api/auth/register 

 {
  "fullName":"aname",
  "email":"email@email.com",
  "companyName": "name",
  "password": "password"
 }

to run login you need to call a post:

/api/auth/login 

{
  "email":"email@email.com",
  "password": "password"
 }

to run forgot password you need to call a post:

/api/auth/forgot-password 

{
  "email":"email@email.com",
 }

to run reset Password you need to call a post:

/api/auth/reset-password

{
  "password":"newpassword",
  "confirmPassword":"newpassword",
  reset_password_token: "reset_token_from_email"
 }

So that's the basics, I tried to keep it as lightweight as possible and hopefully you can find use for it in your next app, idea to speed up your development. Also feel free to fork and make it your own. If you have a problem submit and issue and I will fix ASAP

Top comments (0)