🔐 fix: token not using webcrypto (#4005)

* fix: token

* style: auth pages updated `|` color
This commit is contained in:
Marco Beretta 2024-09-11 22:25:14 -04:00 committed by GitHub
parent aea01f0bc5
commit c3dc03b063
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 23 additions and 14 deletions

View file

@ -102,4 +102,14 @@ async function hashToken(str) {
return Buffer.from(hashBuffer).toString('hex');
}
module.exports = { encrypt, decrypt, encryptV2, decryptV2, hashToken };
async function getRandomValues(length) {
if (!Number.isInteger(length) || length <= 0) {
throw new Error('Length must be a positive integer');
}
const randomValues = new Uint8Array(length);
webcrypto.getRandomValues(randomValues);
return Buffer.from(randomValues).toString('hex');
}
module.exports = { encrypt, decrypt, encryptV2, decryptV2, hashToken, getRandomValues };