CSRF-X Auth Library - v1.0.3
    Preparing search index...

    Function loadEnv

    • Loads environment variables from the project's .env file and Bun.env.

      Returns EnvVars

      A validated EnvVars object.

      If BASE_URL is missing from both .env and environment.

      If BASE_URL is not a valid HTTP/HTTPS URL.

      If LOGIN_PATH is an empty string or contains ? or #.

      If LOGOUT_PATH is an empty string or contains ? or #.

      If USER_EMAIL is provided but has an invalid format.

      If USER_PASSWORD is explicitly set to an empty string.

      The function looks for a .env file in the project root directory (two levels
      above this file). If the file exists, its variables are parsed and take precedence
      over any pre‑existing environment variables. Then it reads from Bun.env
      (or falls back to process.env when not in Bun).

      The following validation is performed:

      • BASE_URL must be present and be a valid HTTP/HTTPS URL.
      • LOGIN_PATH and LOGOUT_PATH cannot be empty strings and must not contain ? or #.
      • USER_EMAIL must be a valid email format if provided and non‑empty.
      • USER_PASSWORD cannot be an empty string if provided.
      // .env file contains:
      // BASE_URL=http://localhost:3000
      // USER_EMAIL=admin@example.com
      const env = loadEnv();
      console.log(env.BASE_URL); // "http://localhost:3000"
      console.log(env.USER_EMAIL); // "admin@example.com"
      // Environment variables override .env (if any)
      process.env.BASE_URL = "https://prod.example.com";
      const env = loadEnv(); // uses the environment variable

      @0.1.1

      0.1.1