Nestjs-vue-boilerplate - A boilerplate for a Full-Stack application using NestJS 8 for the backend and Vue 3 for the frontend

Overview

Vue NestJs Boilerplate

Have any questions? Want to get in contact? Hit me up on Twitter 🐦 !

A boilerplate for a Full-Stack application using NestJS 8 for the backend and Vue 3 for the frontend.

It includes:

  • πŸ” Authentication (including oAuth for Google and Twitter, Email verification, password reset etc.)
  • πŸ’Ώ Rich configuration possibilities via environment variables
  • 🐳 A dockerized environment (usage not mandatory but recommended): Backend & frontend server, Postgres, pgadmin, Redis, Mailhog
  • πŸ“§ Sending email + HTML email templates
  • πŸ› Debugging setup for VS Code for the backend
  • ☁️ TailwindCSS integration

Quick start

Install dependencies

After cloning or downloading the repo, you first need to install the dependencies on both the backend and frontend: cd backend; npm install cd ../frontend; npm install

Environment variables

You can configure large parts of the app via environment variables. There are three environment files:

  • ⬅️ Backend environment
  • ➑️ Frontend environment
  • 🐳 Docker environment (optional)

Backend

Execute the following commands:

cd backend && cp .env.example .env

Fill in the values as needed. If you plan to use the dockerized environment provided in this repo, there is no need to change the database and email configuration

Frontend

Navigate into the frontend directory and execute the following commands:

cp .env.local.example .env.local

There is not much to do, actually. Just make sure that you enter the right VUE_APP_API_URL without a trailing slash. By default, NestJS runs on http://localhost:3000, so you probably don't need to change the default value in .env.local.

Docker environment (optional)

πŸ’‘ Not using Docker? You can ignore this section if you don't want to use Docker for your development environment.

First, in the root directory, execute:

cp .env.example .env

Afterwards, you can adjust the values as you wish. They will be used in the docker-compose.ymlfile for configuring your containers. However, you can also stick to the default values as they will get the job done πŸ’ͺ .

⚠️ Docker containers not suited for production The provided Docker configuration is not secure enough for a production environment. It is only supposed to be used during development.

Exploring the app

Once you're set up, you can visit your frontend URL (usually http://localhost:8080). But there won't be too much to see. So let's move on to /register! There, you'll be able to register for an account. Once you finish that, you will be redirected to /dashboard. You can only access this route when you are logged in.

Authentication πŸ”

The app comes with a couple of different ways a user can login/register:

  • The traditional (local) way by providing an email address and a password
  • Google oAuth
  • Twitter oAuth

Authentication backend ⬅️

The authentication on the backend is primarily handled in the /backend/src/auth module. However, it also requires the /backend/src/user and /backend/src/mail module to work properly.

The user module

The user module is solely concerned with the user entity that is stored in the database. This means:

  • Defining the user entity (/backend/src/user/user.entity.ts)
  • Providing a service to query the user table (/backend/src/user/user.service.ts)

The auth module

The auth module handles all the authentication and authorization of users. This means:

  • (oAuth) Login & registration
  • Authorization / protecting routes
  • Email verification
  • Password reset

The module uses Passport under the hood with a session based authenctication approach. It takes advantage of the following strategies:

  • Local strategy
  • Google Passport oAuth 2.0
  • Twitter Passport oAuth

The boilerplate also takes advantage of the thin wrapper packages that NestJS offers for passport. Thus, the authentication/authorization logic primarily happens in /backend/src/auth/controllers, /backend/src/auth/guards and /backend/src/auth/strategies

Sessions Passport offers a variety of different authentication strategies. This boilerplate uses a session based authentication approach, where the sessions are stored in the Postgres database in a sessions table. To achieve this, the app uses the express-session and connect-typeormpackages.

oAuth

πŸ’‘ You must register your apps on Google and Twitter You can only use oAuth if you register your apps on Google and Twitter beforehand and paste the correct values into the /backend/.env file.

OAuth gets kind of tricky when you have a decoupled frontend and backend. Here is how the app handles it:

  • On the frontend, click on a social login button
  • This button redirects you to <backend-domain>/auth/twitter or <backend-domain>/auth/google
  • These domains, in turn, automatically redirect you to the respective authentication page of the OAuth provider
  • After successfully authenticating there, the authentication provider redirects you back to <backend-domain>/auth/twitter/callback or <backend-domain>/auth/google/callback.
  • There, passport does its magic and retrieves the corresponding user information by using the access token from the url to ping the API of the OAuth provider.
  • Next, a user with the corresponding email address will be searched in the database and the user will either be logged in or a new user will be created.
  • Finally, the user gets redirected to <frontend-domain>/auth/twitter/callback or <frontend-domain>/auth/google/callback.

⚠️ The callback matters Please make sure to enter a callback in the form of /auth/{twitter_or_google}/callback in the settings of the respective providers. The boilerplate wont work correctly otherwise.

The mail module

The mail /backend/src/module is required for sending email verification and password reset mails. It leverages the awesome @nestjs-modules/mailer package, which enables the following things:

  • Creating HTML-Email templates with handlebars
  • Dynamically injecting values into these templates
  • A nicely formatted API to actually send the emails

Templates Email templates live under /templates. by default, you'll find two. One email verification/welcome template and a password reset template. They are written in handlebars so that we can later dynamically inject values. The methods for actually sending the emails live in mail.service.ts. So, if you want to create and send additional mails, you need to do the following:

  • Create a new template under /templates
  • Create a new method in mail.service.ts. In the context option, choose the values for the variables you declared in the template file
  • Call the newly created method somewhere else in your code in order so send the mail.
You might also like...
Vue-Boilerplate - This boilerplate was made to simplify working with Vue

Vue-Boilerplate This boilerplate was made to simplify working with Vue Packages: - Vite - Vue3 - Vue-Router - TypeScript - altv/types-webviews Does al

Vue3-ts-boilerplate - Packed Vue3 boilerplate with storybook, unit testing, generators, typescript, pinia, vue-router

Vue3 TS Boilerplate This template should help get you started developing with Vue 3 in Vite. Recommended IDE Setup VSCode + Volar (and disable Vetur).

@Django integrated with a full-featured @Webpack + (@vuejs / vue-loader) setup with hot reload, linting, testing & css extraction.
@Django integrated with a full-featured @Webpack + (@vuejs / vue-loader) setup with hot reload, linting, testing & css extraction.

vue-django-webpack-boilerplate @NdagiStanley has mirrored the fork to have this repo here. This starterpack has proved useful to many and I thank you

πŸ’» A full-featured Vuejs + Vuetify + Great structure project template + API Ready
πŸ’» A full-featured Vuejs + Vuetify + Great structure project template + API Ready

A great way to structure and bootstrap VueJS + Vuetify + API projects

A boilerplate to quickly start a Vue project using Vuetify, Vue-i18n, Vuex, Vue-router
A boilerplate to quickly start a Vue project using Vuetify, Vue-i18n, Vuex, Vue-router

Vue, Vuetify, Vuex, Vue-router, i18n boilerplate A good way to quickly start a Vue project with good foundations ! [ Demo ] πŸ“¦ Features Vue 2.x Vuetif

Boilerplate Generator using Command Line Interface.

plate-cli Boilerplate Generator using Command Line Interface. Introduce Many frameworks have create project CLI. However, these projects will not only

A Complete Single Page Application using Vue, Vue Router, Bootstrap-Vue, Vuex and all....
A Complete Single Page Application using Vue, Vue Router, Bootstrap-Vue, Vuex and all....

Vue-CRUD Application A Complete Single Page Application (SPA) or Product CRUD Application using Vue 3, Vue Router, Vue-Pagination, Searching, Sweet Al

A hotel site frontend developed with Vue, Vuetify, and Vuelidate
A hotel site frontend developed with Vue, Vuetify, and Vuelidate

Hotel Site Project Details A hotel site frontend developed with Vue, Vuetify, and Vuelidate. Users can reserve a hotel after selecting check-in and ch

A sample Apache Cordova application using VueJS.
A sample Apache Cordova application using VueJS.

CordoVue A simple apache cordova sample project using Vue, Vuex, Vue-router, ESLint and Webpack. Getting Started Prerequisites To use this you'll need

Comments
  • Refactor auth module code

    Refactor auth module code

    • Remove unused code
    • Split services in multiple
    • Move session entity to auth module
    • Remove interfaces / convert interfaces to types
    • Move all entities to /entities
    opened by niclas-timm 0
Releases(0.10)
Owner
null
Vue, Express, MongoDB full-stack JS Boilerplate

vueapp Vue-express-mongo-boilerplate Vue, Express, MongoDB full-stack JS Boilerplate This is a full stack webapp boilerplate project with VueJS + Expr

HudsonJr 6 Nov 5, 2022
Mohamed Ghoubali 3 Jun 22, 2022
Full stack Nuxt 3 Template starter with Supabase and Tailwindcss

Top Nuxt 3 Starter Template Fastest and most comfortable development experience started template With ?? from @ctwhome, inspired by @antfu vitesse Fea

J. Gonzalez 95 Dec 28, 2022
Nest.js + Prisma + TypeScript + Yarn Workspaces (Monorepo) full-stack project template

Nest.js + Prisma + TypeScript + Yarn Workspaces (Monorepo) full-stack project template

Alireza Zamani 83 Jan 2, 2023
Backend and Frontend Template - Software Architecture Group 35

Backend and Frontend Template - Software Architecture Group 35 Latest version: https://git.ita.chalmers.se/courses/dit341/group-00-web (public Github

Drake Axelrod 28 Mar 10, 2022
A full-fledge Vue 3 + NUI boilerplate to get you developing beautiful and responsive UI's in no time!

A full-fledge Vue 3 + NUI boilerplate to get you developing beautiful and responsive UI's in no time!

Bryce Canyon County Scripts 5 Dec 30, 2022
Vue3 + Vite + WindiCSS (Tailwind) Boilerplate for quick starting your Vue3 app with full support for tailwind

Use this boilerplate to quickly start your Vue3 project with WindiCSS (TailwindCSS), using vite as the build tool. Run the development server git clon

Hasin Hayder 9 Aug 2, 2022
Nuxt3-boilerplate - Boilerplate of TailwindCSS v3, Vue 3, Heroicons & HeadlessUI and Nuxt3

Nuxt 3 Minimal Starter with TailwindCSS, Vue3, HeadlessUI & Heroicons We recommend to look at the documentation. Setup Make sure to install the depend

null 3 May 11, 2022
Yeoman generator for a Vue, Express, Node, and Mongo stack

A somewhat opinionated Yeoman generator for applications built upon the VENM stack.

Joel Felsinger 47 Dec 15, 2022