diff --git a/auth/auth.js b/auth/auth.js index b061761..569f4d5 100644 --- a/auth/auth.js +++ b/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 }; \ No newline at end of file