cobalt/api/src/util/generate-jwt-secret.js
jj a4e6b49d7f
Some checks failed
Run tests / check lockfile correctness (push) Waiting to run
Run tests / web sanity check (push) Waiting to run
Run tests / api sanity check (push) Waiting to run
Run service tests / test service functionality (push) Has been cancelled
Run service tests / test service: ${{ matrix.service }} (push) Has been cancelled
util/jwt: ensure uniform distribution of characters
2024-10-26 18:28:25 +00:00

23 lines
587 B
JavaScript

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