generate secret and validate iv position is number

This commit is contained in:
Benjamin Palko 2025-01-08 17:02:58 -05:00
parent bc2be3302a
commit 3d73f9fa95
4 changed files with 29 additions and 3 deletions

View file

@ -0,0 +1,6 @@
import { randomBytes } from 'node:crypto';
console.log('SECRET: ', {
password: randomBytes(16).toString('hex'),
salt: randomBytes(16).toString('hex'),
});

View file

@ -1,5 +1,5 @@
import { PhoneRegex } from '../src/lib/regex/phone';
import { z } from 'zod';
import { PhoneRegex } from '../src/lib/regex/phone';
const ValidateEnvironment = () => {
const { success, error } = z
@ -9,7 +9,22 @@ const ValidateEnvironment = () => {
TWILIO_PHONE_NUMBER: z.string().regex(PhoneRegex),
SECRETS_PASSWORD: z.string().length(32),
SECRETS_SALT: z.string().min(16),
SECRETS_IV_POSITION: z.number().positive(),
SECRETS_IV_POSITION: z.string().transform((val, ctx) => {
const parsed = parseInt(val);
if (isNaN(parsed)) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'Not a number',
});
// This is a special symbol you can use to
// return early from the transform function.
// It has type `never` so it does not affect the
// inferred return type.
return z.NEVER;
}
return parsed;
}),
})
.safeParse(process.env);