'Logout All sessions for an account in express-session, postgresql (connect-pg-simple)
I was wondering how one would create a route to logout all sessions (not just the current one) for a user when using express-session and connect-pg-simple as a session store.
I have the sessions table name set as user_sessions and have previously been able to achieve this using the mysql store on a previous project, which went something like this;
const db = require("../db/connection");
exports.logoutAllDevices = async (user_id) => {
// req.logout(); -- I called this in the controller just before, left it here to show its been called
let logoutAllQuery = 'DELETE FROM user_sessions WHERE JSON_EXTRACT(`data`, "$.passport.user") = $1;';
await db.query(logoutAllQuery, [user_id]);
return;
};
which i found before and the idea was to destroy all sessions related to that user as well as calling the req.logout() function.
However, I can't get any solution to work with this postgres store. Help is appreciated.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
