cli icon indicating copy to clipboard operation
cli copied to clipboard

Allow reading config values from .env file

Open amrnn90 opened this issue 2 years ago • 1 comments

Feature request

Hello, I tried looking through the docs for a way to set secret values in config.toml by reading a .env file, but I couldn't find anything.

Searching the issues I found this one #210 which seems related to what I am asking for, but I couldn't understand how to get things working.

I tried doing this in my config.toml file:

[auth.external.github]
client_id = "env(GITHUB_CLIENT_ID)"
enabled = true
secret = "env(GITHUB_SECRET)"

and I created a .env file:

export GITHUB_CLIENT_ID=...
export GITHUB_SECRET=...

and finally started supabase by running this command:

(source .env && supabase start)

Which doesn't seem to work, trying to log in using github causes supabase to create a url that looks like this:

https://github.com/login/oauth/authorize?client_id=env%28GITHUB_CLIENT_ID%29

So it seems to copy the value stored in config.toml literally.

Any help is appreciated, thanks!

amrnn90 avatar Jun 15 '22 16:06 amrnn90

since config.toml is commited to my repository I don't want to expose the google client id and secret.

would be nice if we could reference env vars from .env.development or similar for example.

miglrodri avatar Jul 07 '22 14:07 miglrodri

Here is what I am doing to make it work, I think it should work with github too.

  1. Created .env file in supabase directory with following content
export GOOGLE_CLIENT_ID="google client id"
export GOOGLE_SECRET="google secret"
  1. config.toml
[auth.external.google]
enabled = true
client_id = "env(GOOGLE_CLIENT_ID)"
secret = "env(GOOGLE_SECRET)"
  1. run source ./supabase/.env && supabase start in root of the project

isaif avatar Sep 15 '22 11:09 isaif

Thanks all, seems like this issue is the same as https://github.com/supabase/cli/issues/210#issuecomment-1201213636, which should be fixed by now.

soedirgo avatar Sep 15 '22 11:09 soedirgo

Hi, I use windows and source isn't available in the cmd / powershell. The workaround I found is to use env-cmd - sharing in case someone encounters the same issue. Also happy to hear if there is any better solution.

cohlar avatar Sep 23 '22 10:09 cohlar

UPDATE: It turns out this does work on Windows, just make sure you are using the latest version with either npx or scoop.


To be clear for windows users:

npm i -D env-cmd

then

npx env-cmd npx supabase start

J

jdgamble555 avatar Feb 18 '23 04:02 jdgamble555

I created a feature request for the --env-file flag so that it will work for everyone (Unix and Windows) and we can select .env file we want in local development.

use --env-file on localhost

J

jdgamble555 avatar Sep 23 '23 17:09 jdgamble555

@isaif 's proposal seems to work on mac, but my .env files do not normally need export so I feel there should be a better solution to support .env files

simonh1000 avatar Jan 07 '24 15:01 simonh1000