mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-14 02:16:19 +01:00
Add session remove
This commit is contained in:
parent
92afe8f615
commit
2e7a36b365
1 changed files with 36 additions and 0 deletions
36
auth/auth.js
36
auth/auth.js
|
@ -39,6 +39,41 @@ function session_converter(session) {
|
|||
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) {
|
||||
const conn = db.connect();
|
||||
let status = new Promise(function (res, rej) {
|
||||
|
@ -64,5 +99,6 @@ function auth_checker(key) {
|
|||
module.exports = {
|
||||
session_decode,
|
||||
session_converter,
|
||||
session_remove,
|
||||
auth_checker
|
||||
};
|
Loading…
Reference in a new issue