55 lines
2.0 KiB
JavaScript
55 lines
2.0 KiB
JavaScript
const parseCookies = require("../utils/functions/parseCookies");
|
|
|
|
/**
|
|
* Logout user
|
|
* ==============================================================================
|
|
* @param {object} params - Single Param object containing params
|
|
* @param {object} params.request - Http request object
|
|
* @param {object} params.response - Http response object
|
|
*
|
|
* @returns {{success: boolean, payload: string}}
|
|
*/
|
|
module.exports = function ({ request, response }) {
|
|
/**
|
|
* Check Encryption Keys
|
|
*
|
|
* @description Check Encryption Keys
|
|
*/
|
|
try {
|
|
const cookiesKeys = Object.keys(parseCookies({ request }));
|
|
|
|
const authKeyName = cookiesKeys.filter((cookieKey) => cookieKey.match(/datasquirel_.*_auth_key/))[0];
|
|
const csrfName = cookiesKeys.filter((cookieKey) => cookieKey.match(/datasquirel_.*_csrf/))[0];
|
|
|
|
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",
|
|
};
|
|
}
|
|
|
|
/** ********************************************** */
|
|
/** ********************************************** */
|
|
/** ********************************************** */
|
|
};
|
|
|
|
/** ********************************************** */
|
|
/** ********************************************** */
|
|
/** ********************************************** */
|