How to propagate the env

I am facing some issues with having only one doppler env for two of my Next.js projects. Next.js has some env variables that cannot be repeated, such as PORT. My solution was to add <PREFIX_>PORT and then removing it later in a script. The solution is working but it’s a bit of hack and ugly

# bash.sh

while read -r line; do
    if [[ $line == PREFIX_* ]]; then
        original_var_name=${line%%=*}
        value=${line#*=}
        new_var_name=${original_var_name#STUDENT_APP_}
        unset "$new_var_name"
        export "$new_var_name"="$value"
        unset "$original_var_name"
    fi
done < <(env)

pnpm run next dev

my package.json is something like:

{
  "next": "next",
  "dev": "doppler run --preserve-env -p DOPPLER_PROJECT -c dev --command=\"./bash.sh\"",
}

is there a way to improve this? how can I move the pnpm run next dev from the end of the file to the package.json script, so it’ll be more reusable?

@Itelo_Filho Could you elaborate a bit on why you need two separate PORT secrets in a single config? Typically, this is exactly what a branch config would be for. Is there a reason that won’t work for your scenario?

I’m build a whitelabel, I want to have everything in one branch config, so it’ll easier to track.

dev-whitelabel (the one I use now)
dev-company-1, a branch where I change variable like database_url etc
dev-company-2

@Itelo_Filho Doppler actually isn’t designed for patterns like that (essentially using us as a datastore). For example, you’re limited to 10 configs per environment on the Developer plan (100 on the Team plan), so that pattern won’t scale at all. Configs are meant to be for things like different deployment environments. So, you might have prd_aws, prd_gcp and prd_azure for example. It’s not meant to be something that scales 1:1 with resources that can grow unbounded in your application. In terms of doing this on a secret level inside a config, that won’t really work either since there’s a 1000 secret limit per config.

I would recommend using a secure datastore to store the information about your customer environments and then use Doppler to store the credentials your application will use to fetch that data.