datasquirel/users/logout-user.js

52 lines
1.9 KiB
JavaScript
Raw Normal View History

2023-05-06 11:14:09 +00:00
/**
* ==============================================================================
* Main Function
* ==============================================================================
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-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-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
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */
};
/** ********************************************** */
/** ********************************************** */
/** ********************************************** */