节点js会话使用Postgres和表达式会话为每个请求创建不同的cookie

时间:2015-12-16 12:20:02

标签: node.js postgresql session cookies

这是我的代码

var express = require('express');
var router = express.Router();
var path = require('path');
var bodyParser = require('body-parser');
var cookieparser = require('cookie-parser');
var cors = require('cors');
var session = require('express-session');
var PostgreSqlStore = require('connect-pg-simple')(session);

//var mongoose=require('mongoose');

var app = express();
app.use(bodyParser());
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded());
//session starts
app.use(cookieparser());

var sessionOptions = {
    secret: "secret",
    resave: true,
    //cookie :{ maxAge : 30 * 24 * 60 * 60 * 1000},
    cookie: { httpOnly: false },
    saveUninitialized: false,
    store: new PostgreSqlStore({
        conString: "postgres://postgres:password@127.0.0.1:5432/session"
    })
};
app.use(session(sessionOptions));


//session ends

require('./routes/routes.js')(app);


app.listen(4001);
//exports.start = start;
exports.app = app;

登录时插入 req.session('用户ID')=电子邮件;

数据库有一条记录,但是对于下一个请求,它会插入另一条cookie记录。我想只进行一次验证。我想知道使用postgres的简单版权的更好方法。

0 个答案:

没有答案