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 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongogate

v1.0.0

Published

This library provides an easy solution for user authentication in MongoDB using `mongoose`, `passport`, and `bcryptjs`. It allows flexible configuration of email and password fields, as well as support for hashed passwords.

Downloads

70

Readme

mongogate.js

This library provides an easy solution for user authentication in MongoDB using mongoose, passport, and bcryptjs. It allows flexible configuration of email and password fields, as well as support for hashed passwords.

Features

  • User Authentication: Login and logout using passport and local strategy.
  • Session Management: Store and manage sessions in MongoDB.
  • Flexible Configuration: Customize email and password fields, and define whether the password should be hashed.

Installation

Clone the repository or download the required dependencies with:

npm install mongogate

Usage

Basic Configuration

Usage example with Express:

const MongoGate = require('mongogate');
const express = require('express');

const app = express();

app.use(express.json());

const config = {
    userField: 'Email',
    passwordField: 'Password',
    connectionString: 'mongodb+srv://your-username:[email protected]/Users?retryWrites=true&w=majority',
    dbName: 'UsersDatabase',
    userCollection: 'UsersCollection',
    sessionCollection: 'SessionsCollection',
    hashedPassword: true,
    multipleSessions: true,
    sessionExpiration: 3600000, // 1 hour
    customRoutes: {
        login: '/auth/custom-login',
        logout: '/auth/custom-logout'
    }
};

new MongoGate(app, config, true);

const PORT = process.env.PORT || 3000;

app.listen(PORT, () => {
    console.log(`Server is running on port ${PORT}`);
});

Configuration options

  • userField: The field to be used as the user (example: 'Email').
  • passwordField: The field to be used as the password (example: 'Password').
  • connectionString: Your MongoDB connection string.
  • dbName: The name of the database.
  • userCollection: The name of the user collection.
  • sessionCollection: The name of the session collection.
  • hashedPassword: Set to true to hash the password using bcryptjs.
  • multipleSessions: Allows multiple active sessions for the same user.
  • sessionExpiration: Sets the duration after which a user session will automatically expire if inactive.
  • customRoutes: Customize the login and logout routes.

Default routes

The library provides the following authentication routes:

  • POST /auth/login – Logs in a user.
  • POST /auth/logout – Logs out a user.
  • GET /auth/status – Checks the authentication status.
  • POST /auth/add – Adds a new user.
  • PUT /auth/update – Updates user data.
  • DELETE /auth/delete – Deletes a user.

License

This project is licensed under the MIT License.