datasquirel/dist/package-shared/actions/users/validate-token.js
Benjamin Toby 7e8bb37c09 Updates
2025-07-05 14:59:30 +01:00

60 lines
1.5 KiB
JavaScript

import decrypt from "../../functions/dsql/decrypt";
/**
* Validate Token
* ======================================
* @description This Function takes in a encrypted token and returns a user object
*/
export default function validateToken({ token, encryptionKey, encryptionSalt, }) {
var _a;
try {
/**
* Grab the payload
*
* @description Grab the payload
*/
const key = token;
/**
* Grab the payload
*
* @description Grab the payload
*/
let userPayload = decrypt({
encryptedString: key,
encryptionKey,
encryptionSalt,
});
/**
* Grab the payload
*
* @description Grab the payload
*/
if (!userPayload) {
return null;
}
/**
* Grab the payload
*
* @description Grab the payload
*/
let userObject = JSON.parse(userPayload);
if (!userObject.csrf_k) {
return null;
}
/**
* Return User Object
*
* @description Return User Object
*/
return userObject;
}
catch (error) {
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Validate Token Error`, error);
/**
* Return User Object
*
* @description Return User Object
*/
return null;
}
}