/**
 * Next runs this once, when the server starts.
 *
 * It is the only place the dashboard gets to fail on a bad environment before a
 * visitor does: every other read is lazy on purpose, so a missing secret used to
 * surface as a 500 on somebody's first audit rather than as a server that
 * refused to come up.
 */
export async function register(): Promise<void> {
  // Next compiles this file for the edge runtime as well, where there is no
  // `node:fs` for the check to read `.env` files with. Nothing of ours runs on
  // edge; the import stays behind this guard so it is never pulled in there.
  if (process.env.NEXT_RUNTIME !== "nodejs") return;

  // The build evaluates this too, on a machine that has no secrets and needs
  // none — the same reason the database pool is built lazily.
  if (process.env.NEXT_PHASE === "phase-production-build") return;

  const { assertEnv } = await import("./lib/env");
  assertEnv("dashboard");
}
