tools: add hmac variable generator
This commit is contained in:
parent
82f7c0ec9b
commit
b22357bc59
22
tools/hmac.ts
Normal file
22
tools/hmac.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import crypto from 'crypto'
|
||||
import fs from 'fs'
|
||||
|
||||
const hmacKey = crypto.randomBytes(32).toString('hex')
|
||||
|
||||
if (fs.existsSync('.env.local')) {
|
||||
const envFile = fs.readFileSync('.env.local', 'utf8')
|
||||
// Double-check it's not already set
|
||||
if (!envFile.includes('ALTCHA_SECRETKEY')) {
|
||||
fs.appendFileSync('.env.local', `\nALTCHA_SECRETKEY=${hmacKey}`)
|
||||
}
|
||||
console.log(`Successfully wrote ALTCHA_SECRETKEY to .env.local`)
|
||||
} else if (fs.existsSync('.env')) {
|
||||
const envFile = fs.readFileSync('.env', 'utf8')
|
||||
// Double-check it's not already set
|
||||
if (!envFile.includes('ALTCHA_SECRETKEY')) {
|
||||
fs.appendFileSync('.env', `\nALTCHA_SECRETKEY=${hmacKey}`)
|
||||
}
|
||||
console.log(`Successfully wrote ALTCHA_SECRETKEY to .env`)
|
||||
} else {
|
||||
console.error('No .env/.env.local file found, please create one first.')
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user