Comments (5)
@saraginov I actually found the solution lol
I dug into source of req.session.destroy
-> found out that it takes only the fn
argument and later passes it to req.sessionStore.destroy(this.id, fn)
The solution in your case would be just to do
exports.logOut = async function(req, res)
{
const {session, sessionID} = req;
const cb = (err) => {
console.log({err});
}
console.log({sessionID});
console.log(cb);
const deletedSession = req.sessionStore.destroy(sessionID, cb);
res.header('Content-Type', 'application/json;charset=UTF-8');
res.header('Access-Control-Allow-Credentials', true);
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
delete req.session
res.end('Logged Out');
}
Or a little better without using the session.destroy
req.session.destroy(function (err: Error) {
if (err) {
res.status(400)
} else {
res.clearCookie('connect.sid')
res.header('Content-Type', 'application/json;charset=UTF-8');
res.header('Access-Control-Allow-Credentials', true);
res.header(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
res.status(200)
}
})
Bonus
The connect-pg-simple
module just runs a simple SQL query when sessionStore.destroy(x, y)
is called.
this.query(
'DELETE FROM ' + this.quotedTable() + ' WHERE sid = $1',
[sid],
err => { fn && fn(err); }
);
My usecase of this was to log user off on every device using a knex/sql query like this
knex('session').select('sid').whereRaw("sess->'passport'->>'user' = ?", [userId]).delete()
select sess->'passport'->>'user' as userid from session where sess->'passport'->>'user' = 'ID here'
from node-connect-pg-simple.
Glad to help
from node-connect-pg-simple.
Hey @saraginov! How did you manage to solve this?
from node-connect-pg-simple.
@makuga01 I didn't, I closed this because I am overwhelmed with other work and don't have time to address it. Feel free to re-open it if you would like.
from node-connect-pg-simple.
Thank you I appreciate it, I will try it out at some point soon and get back to you.
from node-connect-pg-simple.
Related Issues (20)
- Error thrown when setting a session when connecting to Heroku-hosted PostgreSQL HOT 2
- @types/pg as dev dependency HOT 7
- Use ES6 import HOT 3
- Change `pg` to a peer dependency HOT 2
- db.bit.io issues HOT 8
- 'Failed to prune sessions: con.connect is not a function' when trying to connect PostgreSQL database with session store via Knex.js HOT 1
- error: date/time field value out of range: "1655239143" HOT 4
- Failed to prune sessions: relation "session" does not exist HOT 3
- Two sessions being saved to store HOT 1
- If at the first try to create the session table the database is down, the store fails forever HOT 3
- Getting error "Error: connect ECONNREFUSED ip_address:5432" intermittently when the RDS is restarted.
- Getting error "Error: connect ECONNREFUSED ip_address:5432" intermittently when the RDS is restarted. HOT 2
- Unexpected token in node_module index.js HOT 2
- Using "pruneSessionInterval=false" will unexpectedly disable "createTableIfMissing=true" HOT 3
- Property "replaceAll" does not exist on type "string". HOT 4
- pg-simples tries to access wrong column HOT 1
- createTableIfMissing is not working in version: 9.0.0 HOT 5
- TypeError: (0 , connect_pg_simple_1.default) is not a function HOT 2
- session_id is ignored and a new one is generated instead HOT 5
- Getting "Pool is missing for some Reasons", If not there is no communication between Client and server for more than 24 hours HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-connect-pg-simple.