datasquirel/users/logout-user.js

55 lines
2.0 KiB
JavaScript
Raw Normal View History

2023-06-24 12:09:26 +00:00
const parseCookies = require("../utils/functions/parseCookies");
2023-05-06 11:14:09 +00:00
/**
2023-06-24 12:09:26 +00:00
* Logout user
2023-05-06 11:14:09 +00:00
* ==============================================================================
2023-05-18 11:43:52 +00:00
* @param {object} params - Single Param object containing params
* @param {object} params.request - Http request object
* @param {object} params.response - Http response object
2023-06-24 12:09:26 +00:00
*
* @returns {{success: boolean, payload: string}}
2023-05-06 11:14:09 +00:00
*/
2023-05-09 14:20:53 +00:00
module.exports = function ({ request, response }) {
2023-05-06 11:14:09 +00:00
/**
* Check Encryption Keys
*
* @description Check Encryption Keys
*/
2023-05-09 14:20:53 +00:00
try {
2023-06-24 12:09:26 +00:00
const cookiesKeys = Object.keys(parseCookies({ request }));
2023-05-09 14:30:08 +00:00
const authKeyName = cookiesKeys.filter((cookieKey) => cookieKey.match(/datasquirel_.*_auth_key/))[0];
const csrfName = cookiesKeys.filter((cookieKey) => cookieKey.match(/datasquirel_.*_csrf/))[0];
2023-05-09 14:20:53 +00:00
response.setHeader("Set-Cookie", [`${authKeyName}=null;samesite=strict;path=/;HttpOnly=true;Secure=true`, `${csrfName}=null;samesite=strict;path=/;HttpOnly=true`, `dsqluid=null;samesite=strict;path=/;HttpOnly=true`]);
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
return {
success: true,
payload: "User Logged Out",
};
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
} catch (error) {
console.log(error.message);
return {
success: false,
payload: "Logout Failed",
};
}
2023-05-06 11:14:09 +00:00
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
};
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */