datasquirel/users/logout-user.js

50 lines
1.8 KiB
JavaScript
Raw Normal View History

2023-05-06 11:14:09 +00:00
/**
* ==============================================================================
* Main Function
* ==============================================================================
* @param {Object} response - Http response object
*/
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-05-09 14:30:08 +00:00
const cookiesKeys = Object.keys(request.cookies);
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
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
};
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */