Socket
Socket
Sign inDemoInstall

passport-local-sequelize

Package Overview
Dependencies
25
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    passport-local-sequelize

Sequelize plugin that simplifies building username and password login with Passport


Version published
Weekly downloads
321
decreased by-33.4%
Maintainers
1
Install size
14.7 MB
Created
Weekly downloads
 

Readme

Source

Passport-Local Sequelize

Passport-Local Sequelize is a Sequelize plugin that simplifies building username and password login with Passport

This plugin is heavily inspired by Passport-Local Mongoose plugin.

Installation

$ npm install passport-local-sequelize

Usage

/* /models/user.js */

// Require all the stuff
var Sequelize = require('sequelize'),
	passportLocalSequelize = require('passport-local-sequelize');

// Setup sequelize db connection
var mydb = new Sequelize('mydb', 'myuser', 'mypass', {
	dialect: 'sqlite',

	storage: 'mydb.sqlite'
});

// A helper to define the User model with username, password fields
var User = passportLocalSequelize.defineUser(mydb, {
	favoriteColor: Sequelize.STRING
});

// --- OR ---

// Define a User yourself and use attachToUser

var User = mydb.define('User', {
	nick: Sequelize.STRING,
	myhash: Sequelize.STRING,
	mysalt: Sequelize.STRING
});

passportLocalSequelize.attachToUser(User, {
	usernameField: 'nick',
	hashField: 'myhash',
	saltField: 'mysalt'
});

module.exports = User;

Here's how to hook it all up to passport in your express app.

var express = require('express'),
	passport = require('passport'),

	bodyParser = require('body-parser'),
	cookieParser = require('cookie-parser'),
	session = require('express-session'),

	User = require('./models/user'),

	app = express();


app.use(bodyParser());
app.use(require('connect-multiparty')());
app.use(cookieParser());
app.use(session({ secret: 'super-secret' }));

app.use(passport.initialize());
app.use(passport.session());

passport.use(User.createStrategy());

passport.serializeUser(User.serializeUser());
passport.deserializeUser(User.deserializeUser());

Keywords

FAQs

Last updated on 25 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc