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

sails-users-mng

v0.1.1

Published

A users management and authentication for sails js

Readme

sailsUsersMng

this library can be integrated in sails projects, in order to help manage and authenticate users, and every read/write action of them. this library uses passport.js

##installation

add to your package.json file, the line:

"sails-users-mng ": ""

run in terminal:

npm install

add the following files to your sails project:

  • .../api/controllers/AuthController.js with the code:
module.exports = require('sails-users-mng/controllers/AuthController');
  • .../api/controllers/UserController.js with the code:
module.exports = require('sails-users-mng/controllers/UserController');
  • .../api/models/Auth.js with the code:
module.exports = require('sails-users-mng/models/Auth');
  • .../api/models/Passport.js with the code:
module.exports = require('sails-users-mng/models/Passport');
  • .../api/policies/passport.js with the code:
module.exports = function (req, res, next) {
	require('sails-users-mng/policies/passport')(req, res, next);
    passport.initialize()(req, res, function () {
        passport.session()(req, res, function () {
	        res.isAuth = false;
	        if (req.user) {
		        User.findOne({id: req.user.id}).exec(function(err, user) {
			        if (err) {
				        return res.serverError("Server Error");
			        }

					req.user = user;
					next();
		        });
	        } else {
		        next();
	        }
        });
    });
};
  • .../api/policies/result.js with the code:
module.exports = function (req, res, next) {
	var trivial = {
		superAdmin: ['admin', 'curUser', 'public', 'user'],
		admin: ['curUser', 'public', 'user'],
		curUser: ['public', 'user'],
		user: ['public']
	}
	require('sails-users-mng/policies/result')(req, res, next, trivial);
};
  • .../api/services/auth.js with the code:
var auth = require('sails-users-mng/services/auth');
auth.policy = function(allowedArr, req, res, callback, ids, isFailSend) {
  ...
}
module.exports = auth;
  • .../api/services/passport.js with the code:
module.exports = require('sails-users-mng/services/passport');

add the following code to your sails files:

  • .../config/bootstrap.js with the code:
module.exports.bootstrap = function (cb) {
	sails.services.passport.loadStrategies();
	cb();
};
  • .../config/local.js with the code:
module.exports = {
	proxyHost: 'YOUR_SERVER_URL'
};
  • .../config/passport.js with the code:
module.exports.passport = {
  local: {
    strategy: require('passport-local').Strategy
  },

  twitter: {
    name: 'Twitter',
    protocol: 'oauth',
    strategy: require('passport-twitter').Strategy,
    options: {
      consumerKey: '...',
      consumerSecret: '...'
    }
  },

  facebook: {
    name: 'Facebook',
    protocol: 'oauth2',
    strategy: require('passport-facebook').Strategy,
    options: {
      clientID: '...',
      clientSecret: '...'
    },
    scope: ['email', 'public_profile']
  },

  google: {
    name: 'Google',
    protocol: 'oauth2',
    strategy: require('passport-google-oauth').OAuth2Strategy,
    options: {
      clientID: '...',
      clientSecret: '...'
    },
    scope: ['https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/plus.me']
  }
};
  • .../config/policies.js with the code:
module.exports.policies = {
	'*': ['passport', 'superAdmin', 'result'],
	SOMEController: {
		find: ['passport', 'superAdmin', 'SOME_POLICY', 'result'],
		findOne: ['passport', 'superAdmin', 'result'],
		create: ['passport', 'superAdmin', 'result'],
		update: ['passport', 'superAdmin', 'ANOTHER_POLICY', 'result'],
		destroy: ['passport', 'superAdmin', 'result'],
		populate: ['passport', 'superAdmin', 'result'],
		add: ['passport', 'superAdmin', 'result'],
		remove: ['passport', 'superAdmin', 'result']
	}
};
  • .../config/routes.js with the code:
module.exports.routes = {
	'post /auth/local': 'AuthController.callback',
    'post /auth/local/:action': 'AuthController.callback',

    'get /auth/logout': 'AuthController.logout',
    'get /auth/:provider': 'AuthController.provider',
    'get /auth/:provider/callback': 'AuthController.callback',
    'get /auth/:provider/:action': 'AuthController.callback'
};

TODO

  • explain the required configuration needed in policies folder
  • explain the required configuration needed in every model

##Contact if you want to get more information, explanation or help, please contact me

thanks.