File size: 587 Bytes
2f527a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// 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))}`)