A project aimed to eliminate several architecture decisions. This boilerplate comes with NuxtJS, ExpressJS, Vuetify, Vuex, nodemailer, and jsonwebtoken.
- Register with an email address to be saved in MongoDB.
- If the email is valid, an OTP will be generated and stored in Redis for 5 minutes. The OTP is also sent to the registered email. If it's a match, Express will return a JWT token that Nuxt saves in the browser storage and cookies. Tokens are valid for 30 mins by default.
- JWT logout only happens in the frontend by deleting the stored token in the browser.
- npm, docker, docker-compose
# Clone this repository git clone [email protected]:reiallenramos/nuxtjs-otp-boilerplate.git my_app # Install dependencies cd my_app npm install
The project minimally requires the following to be available:
- a MongoDB database for storing emails
- a Redis server for storing email-OTP mappings
To streamline development, we've configured
docker-compose.yml to fire up three extra services: mongo, mongo-express and redis.
mongo-express provides a UI for managing our database.
Running locally: option 1 (preferred)
- start the three images:
npm run storage-dev
Visit http://localhost:8081/ to manage your database.
Tip: If you also prefer a UI to view redis keys, we recommend using marian/rebrow
- start the app
.env then provide the required environment variables.
npm run nuxt-dev
Running locally: option 2
Run both commands using
npm run docker-dev
Warning about race condition: The
nuxt-devcommand requires MongoDB to be ready. If not, it will fail on startup. We're working on making it resilient but for now, the preferred way to run locally is option 1.
|MONGO_URI||YES||For storing email registrations, ex:
|JWT_DURATION||NO||For how long to keep JWT token alive, ex:
|JWT_SECRET||YES||For generating token, ex:
|EMAIL_STRING||YES||Used by nodemailer as the sender email. Accepts only Gmail for now|
|EMAIL_PASSWORD||YES||Used by nodemailer as the sender password. If the account uses 2FA, you need to generate an App Password. If not, you need to enable Less Secure Apps.|
|REDIS_OTP_URI||NO||For storing email-otp mappings, ex:
|OTP_DURATION||NO||For how long Redis will keep email-otp mapping, ex:
We deployed this project in the demo website by building a docker image then using docker-compose in an AWS Lightsail instance.
# format docker build -t your_image_name:version . # example docker build -t reiallenramos/nuxtjs-otp-boilerplate:latest . docker build -t reiallenramos/nuxtjs-otp-boilerplate:vX.X.X . docker push reiallenramos/nuxtjs-otp-boilerplate:latest docker push reiallenramos/nuxtjs-otp-boilerplate:vX.X.X
- write tests
- create gmail for demo
- gitlab workflow (?)
- resilient MongoDB connection