Skip to content

runtimeConfig schema validation #3522

@Velka-DEV

Description

@Velka-DEV

Describe the feature

Instead of defining overridable empty values inside the (nitro|nuxt).config.ts file, we should be able to define a schema using a validation library like zod or valibot.

Actual overridable values runtimeConfig

//https://nitro.unjs.io/config
export default defineNitroConfig({
  srcDir: "server",

  runtimeConfig: {
    betterAuth: {
      secret: "",
      url: "",
    },
    turnstile: {
      secretKey: "",
    },
    cronSecret: "",
    upstash: {
      redis: {
        url: "",
        token: "",
      },
    },
    posthog: {
      apiKey: "",
      apiHost: "",
    },
  },
});

Schema based runtimeConfig

import { z } from "zod";

//https://nitro.unjs.io/config
export default defineNitroConfig({
  srcDir: "server",

  runtimeConfig: {
    betterAuth: {
      secret: z.string().min(32).max(32),
      url: z.string().url(),
    },
    turnstile: {
      secretKey: z.string().min(1),
    },
    cronSecret: z.string().min(1),
    upstash: {
      redis: {
        url: z.string().min(1),
        token: z.string().min(1),
      },
    },
    posthog: {
      apiKey: z.string().min(1),
      apiHost: z.string().min(1),
    },
  },
});

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions