Giter VIP home page Giter VIP logo

passport-local-sequelize's Introduction

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

passport-local-sequelize's People

Contributors

brookinc avatar chrishubinger avatar clinejj avatar gibu avatar jgable avatar lefnire avatar madhurjain avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.