Add session remove

This commit is contained in:
Moe Poi ~ 2021-11-21 09:13:51 +07:00
parent 92afe8f615
commit 2e7a36b365

View file

@ -39,6 +39,41 @@ function session_converter(session) {
return key; return key;
} }
function session_remove(key, session_token) {
let data = session_decode(session_token);
const conn = db.connect();
let status = new Promise(function (res, rej) {
conn.query(
"SELECT * FROM users WHERE token = ?",
[key],
async function (error, response, fields) {
if (error) {
rej(error);
} else {
let session_data = JSON.parse(response[0].session);
session_data = session_data.filter( x => {
if (x.session != data.session_token) {
return x;
}
});
conn.query(
'UPDATE users SET ? WHERE token = ?', [{session: JSON.stringify(session_data)}, key],
function (err, result) {
if (err) {
rej(error)
} else {
console.log('sukses');
res(true)
}
}
);
}
}
);
});
return status;
}
function auth_checker(key) { function auth_checker(key) {
const conn = db.connect(); const conn = db.connect();
let status = new Promise(function (res, rej) { let status = new Promise(function (res, rej) {
@ -64,5 +99,6 @@ function auth_checker(key) {
module.exports = { module.exports = {
session_decode, session_decode,
session_converter, session_converter,
session_remove,
auth_checker auth_checker
}; };