solzimer / session-pouchdb-store Goto Github PK
View Code? Open in Web Editor NEWPouchDB express session store. Can do realtime session data synchronization via PouchDB server
PouchDB express session store. Can do realtime session data synchronization via PouchDB server
The below code works great when using the default MemoryStore
or other stores such as ´memorystore´ or ´session-file-store´session storage but when I set PouchSession
as the session store req.session.passport no longer gets set. I can see that user.user
is getting saved on the server but for ever reason req.session.passport no longer exists/gets created. I don't really have much experience with development so there is a good chance I am doing something wrong but since the other stores work fine I am wondering if something could be up with ´session-pouchdb-store´
const express = require('express');
const session = require('express-session');
const PouchSession = require("session-pouchdb-store");
const app = express();
const nano = require('nano');
const passport = require('passport');
const PORT = 5000;
require('./passport')(passport);
app.use(express.urlencoded({extended: true}));
app.use(session({
secret: 'thisismysecret',
resave: false,
saveUninitialized: false,
cookie: { secure: false},
store : new PouchSession('http://admin:password@localhost:5984/sessions')
}));
app.use(passport.initialize());
app.use(passport.session());
app.use('/', require('./routes/index'));
app.use('/users', require('./routes/users'));
app.listen(PORT, () => console.log('server running...'));
passport.js
const LocalStrategy = require('passport-local').Strategy;
const nano = require('nano')('http://admin:password@localhost:5984');
const users = nano.use('users');
const bcrypt = require('bcrypt');
module.exports = function(passport) {
passport.use(new LocalStrategy(
function(username, password, done) {
users.view('auth', 'auth', {'key': username, 'include_docs': true})
.then(dbresponse => {
if (dbresponse.rows.length === 1) {
const user = dbresponse.rows[0].doc;
bcrypt.compare(password, user.password, function(err, result) {
if(result === true) {
done(null, user)
} else {
done(null, false)
}
});
} else {
done(null, false);
}
})
.catch(err => {
console.log(err);
done(null, false);
})
}
));
passport.serializeUser(function(user, done) {
console.log("serializeUser");
done(null, user.user);
});
passport.deserializeUser(function(id, done) {
console.log("deserializeUser");
done(null, 'test');
});
When calling destroy() on a session it is not destroyed, due to following error:
TypeError: Cannot read property '_id' of undefined
at PouchDB.<anonymous> (/home/tionis/dev/ep/webapp/node_modules/pouchdb/lib/index.js:1884:26)
at PouchDB.<anonymous> (/home/tionis/dev/ep/webapp/node_modules/pouchdb/lib/index.js:288:21)
at PouchDB.<anonymous> (/home/tionis/dev/ep/webapp/node_modules/argsarray/index.js:14:18)
at /home/tionis/dev/ep/webapp/node_modules/pouchdb/lib/index.js:227:21
at new Promise (<anonymous>)
at PouchDB.<anonymous> (/home/tionis/dev/ep/webapp/node_modules/pouchdb/lib/index.js:214:19)
at PouchDB.remove (/home/tionis/dev/ep/webapp/node_modules/argsarray/index.js:14:18)
at SessionStore.destroy (/home/tionis/dev/ep/webapp/node_modules/session-pouchdb-store/lib/store.js:136:21)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
I occasionally see this warning... any idea what's causing it?
running with the path to local directory as the first argument if that makes any difference.
The following code is causing all of the cookie parameters to be removed from the Set-Cookie header when the cookie is initially set by express-sessions.
session-pouchdb-store/lib/store.js
Lines 215 to 217 in 6f9845f
By turning the cookie object into a normal JSON object all of the computed properties on the object are lost. This causes an issue in express-sessions since it uses the computed data
property to fill in the Set-Cookie header.
Ref: the data property
Ref: where the data property is being used
https://github.com/expressjs/session/blob/e18fb51d2d403bf3b5bd4e498f621dee4a52db41/index.js#L243
Is this store meant to purge old DB records? The purge setting doesn't seem to be used at all in the code.
It'd be nice to not have a couch db filled up with expired session tokens. Is support for purging expired records planned?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.