Otoniel Reyes's Blog

My journey as a software developer and entrepreneur

How to automate user auth system creation in NestJS

In this tiny post, I will explain the process I have followed to build a User Authentication System for all of my non yet created NestJS projects.

Let’s dive in the creation of a crazy automation task: Auth System with roles and support for Google auth.

I was in the startup process to start a new project for a client. Then I found myself with a task I’m sick of, auth system. I mean, almost every single MEAN project will need an auth system. In this exact moment, I realized I can be way more productive if I had a script that makes up this configuration for me. Just like Nest, Angular and Rails have their generators, I can create a script for this.

So I got hands on the dirt and (with a little help from Duck.AI to get started, duh!) crafted a single bash script that:

  1. Installs every package I will need for the authentication system
  2. Creates the folders I will use for the authentication system (including user management)
  3. Crafts every file the authentication needs (except for the spec files)
  4. Creates both .env and .env.example files
  5. Prints out the next steps to complete the setup, so you just need to copy and paste within the app.module.ts file

So, wrapping my journey, I would say that:

It literally took more to automate the process than actually do it by hand. But, next time will be a no-brainer to achieve the same, in just 20 seconds.

It is really worth it when you can automate a task or create a system that saves you time. I think it is particularly important when we’re talking about a time-consuming task.

Lastly, of course, I have uploaded it to GitHub (That way I can use it from any place in the world).

Here is the link.

As an addition, if you need some help automating any task is taking you a lot of time, reach me or text me out.

Nothing more to say, this is it. I need to get back to work.

Peace!

EDIT

I’ve created an Angular auth system automation too, check it out here.