/**
 * Single source for the JWT signing secret.
 * There is deliberately no fallback value: a secret committed to the repository
 * would let anyone forge sessions. Set JWT_SECRET (32+ characters) in .env.
 */
export const MIN_JWT_SECRET_LENGTH = 32;

export function getJwtSecret(): string {
  const secret = process.env.JWT_SECRET?.trim();
  if (!secret || secret.length < MIN_JWT_SECRET_LENGTH) {
    throw new Error(`JWT_SECRET must be set to a random value of at least ${MIN_JWT_SECRET_LENGTH} characters (see backend/.env.example).`);
  }
  return secret;
}
