npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@leonardosarmentocastro/authentication

v2.4.5

Published

authentication

Downloads

95

Readme

authentication

authentication using express mongoose

usage

const mongoose = require('mongoose');
const server = require('@leonardosarmentocastro/server');
const i18n = require('@leonardosarmentocastro/i18n'); // mandatory
const { authentication, authenticationSchema } = require('@leonardosarmentocastro/authentication');

(async () => {
  const api = await server.start(8080, {
    middlewares: (app) => {
      i18n.connect(app); // mandatory
    },
    routes: (app) => {
      const schema = new mongoose.Schema({ authentication: authenticationSchema, name: String });
      const model = new mongoose.model('Customer', schema);

      // creates
      // * "[GET] /authentication/me"
      // * "[POST] /authentication/sign-in"
      // * "[POST] /authentication/sign-out"
      // * "[POST] /authentication/sign-up"
      authentication.connect(app, model);

      // creates
      // * "[POST] /authentication/2FA/cancel"
      // * "[POST] /authentication/2FA/check"
      // * "[POST] /authentication/2FA/verify"
      authentication.twoFactor.connect(app, model);
    },
  });
})();

exposed routes

For authentication

  • [GET] /authentication/me: serves authenticated model data;
  • [POST] /authentication/sign-in: validates token + authenticates an model, saving a JWT Authorization token to the model and attaching it to response's header;
  • [POST] /authentication/sign-up: creates/authenticates an model, saving a JWT Authorization token to the model and attaching it to response's header;
  • [POST] /authentication/sign-out: validates token + remove JWT Authorization token from model and remove it from response's header.

For 2FA verification

  • [POST] /authentication/2FA/cancel: cancel the verification request before the 5 minute duration runs out;
  • [POST] /authentication/2FA/check: checks if the served 4 digit PIN sent by the user, matches the one sent to the given cellphone number;
  • [POST] /authentication/2FA/verify: sends a SMS with a 4 digit PIN code to a given cellphone number.

environment variables

  • AUTHENTICATION_SECRET: secret used to sign jwt tokens when signing tokens;
  • AUTHENTICATION_SMS_2FA_VONAGE_API_KEY: API key for sending 2FA SMS using Vonage;
  • AUTHENTICATION_SMS_2FA_VONAGE_API_SECRET: API secret for sending 2FA SMS using Vonage;
  • AUTHENTICATION_SMS_2FA_SENDER_NAME: The sender name that is going to be written on 2FA SMS messages.

translation keys

For schema validation:

  • AUTHENTICATION_VALIDATOR_ERROR_INVALID_CELLPHONE_NUMBER
  • VALIDATOR_ERROR_PASSWORD_NOT_STRONG
  • VALIDATOR_ERROR_FIELD_IS_REQUIRED

For endpoint resolvers:

  • AUTHENTICATION_ERROR_CELLPHONE_NUMBER_NOT_FOUND
  • AUTHENTICATION_ERROR_PASSWORD_MISMATCH
  • AUTHENTICATION_ERROR_REGISTRY_FOR_TOKEN_NOT_FOUND
  • AUTHENTICATION_ERROR_TOKEN_EXPIRED
  • AUTHENTICATION_ERROR_TOKEN_INVALID
  • AUTHENTICATION_ERROR_TOKEN_NOT_BEFORE

For cellphone 2FA through SMS using Vonage:

  • AUTHENTICATION_SMS_2FA_CANCEL_UNEXPECTED_ERROR
  • AUTHENTICATION_SMS_2FA_CHECK_UNEXPECTED_ERROR
  • AUTHENTICATION_SMS_2FA_CELLPHONE_NUMBER_ALREADY_REGISTERED
  • AUTHENTICATION_SMS_2FA_VERIFICATION_UNEXPECTED_ERROR