Skip to content

passport-local-sequelize is a sequelize plugin for building username and password login with passport

License

Notifications You must be signed in to change notification settings

madhurjain/passport-local-sequelize

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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());

About

passport-local-sequelize is a sequelize plugin for building username and password login with passport

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published