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

auth-mongo-setup

v1.0.6

Published

Tired of setting up authentication like it's a Rubik's cube? 🧩 Say hello to auth-mongo-setup, your new best friend in the world of user management!

Downloads

8

Readme

πŸš€ auth-mongo-setup: Your MongoDB Authentication Wingman! πŸ¦Έβ€β™‚οΈ

Welcome to the world of MongoDB auth made easy! πŸŽ‰

Tired of setting up authentication like it's a Rubik's cube? 🧩 Say hello to auth-mongo-setup, your new best friend in the world of user management!

What's this magic potion? πŸ§ͺ

auth-mongo-setup is like having a tiny authentication wizard living in your code. It's got all the MongoDB and Express.js authentication spells you need, pre-packaged and ready to cast!

Features that'll make you dance the authentication tango πŸ’ƒπŸ•Ί

  • 🎭 User Registration: Because "Guest12345" is so last season.
  • πŸ” Login: Keep the baddies out and your users cozy.
  • 🧠 Forgot Password: For when your users' memory fails them (happens to the best of us).
  • πŸ›‘οΈ JWT Authentication: Like a forcefield, but for your API.
  • πŸ“§ Email Verification: Make sure your users are real humans, not clever cats with keyboards.

Installation (Easier than installing a new habit) πŸ”§

npm install auth-mongo-setup

Configuration (Customize your magic wand) πŸͺ„

Create a .env file in your project root. Fill it with your arcane secrets:

MONGO_URI=mongodb://localhost:27017/myapp
JWT_SECRET=your_secret_key
CLIENT_URL=http://localhost:3000
SMTP_HOST=smtp.example.com
SMTP_PORT=587
[email protected]
SMTP_PASS=your_email_password
FROM_NAME=Your App Name
[email protected]

Usage (No stack overflow required!) πŸ€“

First, sprinkle some magic dust in your main file:

require('dotenv').config();
const express = require('express');
const authMongoSetup = require('auth-mongo-setup');

const app = express();


// Start your engines!
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => console.log(`Server vrooming on port ${PORT}`));

Now, let's break down the spells... err, functions:

πŸ§™β€β™‚οΈ Registration Spell

javascriptCopy// In your client-side code
fetch('http://localhost:3000/api/auth/register', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email: '[email protected]', password: 'excalibur123' })
})
.then(res => res.json())
.then(data => console.log('New wizard registered!', data));

πŸ”“ Login Incantation

fetch('http://localhost:3000/api/auth/login', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email: '[email protected]', password: 'excalibur123' })
})
.then(res => res.json())
.then(data => {
  console.log('Wizard authenticated!', data);
  localStorage.setItem('authToken', data.token);
});

🧠 Forgot Password Potion

fetch('http://localhost:3000/api/auth/forgot-password', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email: '[email protected]' })
})
.then(res => res.json())
.then(data => console.log('Password reset potion sent!', data));

πŸ›‘οΈ Protected Route Shield

const { auth } = require('auth-mongo-setup');

app.get('/api/secret-spell', auth, (req, res) => {
  res.json({ msg: 'The secret spell is Avada Kedavra... oops, wrong franchise!' });
});

Remember, a good wizard never reveals their secrets! 🀫

Contributing (Join our coven) πŸ§™β€β™€οΈπŸ§™β€β™‚οΈ

Found a bug? Want to add a new spell? Just want to share your favorite potion recipe? We're all ears! πŸ‘‚

Open an issue or submit a PR. Our code of conduct: Be excellent to each other! 🎸

Remember, with auth-mongo-setup, you're never auth-alone. Now go forth and authenticate with confidence! πŸš€βœ¨