How to use the express-session.Store function in express-session

To help you get started, we’ve selected a few express-session examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FaisalAl-Tameemi / express-api-starter / server / config / express.js View on Github external
import favicon from 'serve-favicon';
import morgan from 'morgan';
import compression from 'compression';
import bodyParser from 'body-parser';
import methodOverride from 'method-override';
import cookieParser from 'cookie-parser';
import errorHandler from 'errorhandler';
import path from 'path';
import config from './environment';
import passport from 'passport';
import session from 'express-session';
import sqldb from '../sqldb';
// import lusca from 'lusca';
import expressSequelizeSession from 'express-sequelize-session';

const Store = expressSequelizeSession(session.Store);

module.exports = function (app) {
  const env = app.get('env');

  app.engine('html', require('ejs').renderFile);
  app.set('view engine', 'html');
  app.use(compression());
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  app.use(methodOverride());
  app.use(cookieParser());
  app.use(passport.initialize());

  // Persist sessions with mongoStore / sequelizeStore
  // We need to enable sessions for passport-twitter because it's an
  // oauth 1.0 strategy, and Lusca depends on sessions
github labzero / lunch / src / server.js View on Github external
app.use((req, res, next) => {
  if (req.hostname === 'lunch.labzero.com') {
    res.redirect(301, generateUrl(req, config.bsHost, path));
  } else {
    next();
  }
});

//
// Session / Flash
// -----------------------------------------------------------------------------
if (__DEV__) {
  app.enable('trust proxy');
}

const SequelizeStore = connectSessionSequelize(session.Store);
app.use(session({
  cookie: {
    domain: config.domain,
    secure: process.env.NODE_ENV === 'production'
  },
  saveUninitialized: false,
  secret: config.auth.session.secret,
  store: new SequelizeStore({
    db: sequelize
  }),
  resave: false,
  proxy: true
}));

app.use(flash());
github LibreTubeApp / LibreTube / src / server.js View on Github external
import { db, User } from './graphql/connectors';
import parseXml from './utils/parseXml';
import startCron from './utils/cron';
import { setupPassport, buildHelmetOptions } from './utils/auth';

const port = parseInt(process.env.PORT, 10) || 3000
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev });
const handle = app.getRequestHandler()
const server = express();

setupPassport();
startCron();

const schema = makeExecutableSchema({ typeDefs, resolvers });
const SequelizeStore = storeBuilder(session.Store);

if (process.env.PROXY === 'true') {
  server.set('trust proxy', 1); // trust first proxy
}

// Middlewares
server.disable('x-powered-by');
server.use(helmet(buildHelmetOptions()));
server.use(bodyParser.json());
server.use(session({
  store: new SequelizeStore({ db }),
  secret: 'dogs',
  name: 'session',
  cookie: {
    secure: process.env.HTTPS === 'true',
    expires: new Date(Date.now() + 48 * 60 * 60 * 1000) // 48 hours
github cobyism / ghost-on-heroku / core / server / bookshelf-session.js View on Github external
options = options || {};
    Store.call(this, options);

    models.Session.findAll()
        .then(function (model) {
            var i,
                now = new Date().getTime();
            for (i = 0; i < model.length; i = i + 1) {
                if (now > model.at(i).get('expires')) {
                    self.destroy(model.at(i).get('id'));
                }
            }
        });
};

BSStore.prototype = new Store();

// store a given session
BSStore.prototype.set = function (sid, sessData, callback) {
    var maxAge = sessData.cookie.maxAge,
        now = new Date().getTime(),
        expires = maxAge ? now + maxAge : now + time12h,
        sessionModel = models.Session;

    sessData = JSON.stringify(sessData);

    //necessary since bookshelf updates models if id is set
    sessionModel.forge({id: sid}).fetch()
        .then(function (model) {
            if (model) {
                return sessionModel.forge({id: sid, expires: expires, sess: sessData }).save();
            }