api/util: add script to generate secure JWT_SECRET

This commit is contained in:
jj 2024-10-20 10:35:05 +00:00
parent 5ce3a941f9
commit c3f3499a42
No known key found for this signature in database
2 changed files with 15 additions and 1 deletions

View file

@ -12,7 +12,8 @@
"start": "node src/cobalt",
"setup": "node src/util/setup",
"test": "node src/util/test",
"token:youtube": "node src/util/generate-youtube-tokens"
"token:youtube": "node src/util/generate-youtube-tokens",
"token:jwt": "node src/util/generate-jwt-secret"
},
"repository": {
"type": "git",

View file

@ -0,0 +1,13 @@
// run with `pnpm -r token:jwt`
const makeSecureString = (length = 64) => {
const alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
const out = [];
for (const byte of crypto.getRandomValues(new Uint8Array(length)))
out.push(alphabet[byte % alphabet.length]);
return out.join('');
}
console.log(`JWT_SECRET: ${JSON.stringify(makeSecureString(64))}`)