Set environment variables in an action
I wanted to ask if it’s possible to modify environment variables from actions or cron jobs in Convex? If this is not currently supported, are there alternative approaches to dynamically update and store configuration values at runtime, such as using a dedicated key-value store or similar mechanisms?
Looking forward to your response.
Thanks in advance and best regards,
Jonathan
6 Replies
Thanks for posting in <#1088161997662724167>.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Welcome! It really depends, can you share more about outcomes, what you're trying to accomplish? There isn't an api for changing environment variables from a Convex function currently, but there may be another approach.
in particular, you can make a special table for this key-value store, just with regular
ctx.db.insert
and ctx.db.query
I use Convex Auth and want to regenerate the client secret for Apple with each request. Unfortunately, this variable only accepts a string and not a function, whether async or sync.
So I thought it would be a good idea to at least reset the env variable every x days, since Apple’s servers allow it to be valid for a maximum of 6 months.
@erquhart do you have an idea?
i only can import an env
Apple({
clientSecret:process.env.APPLECLIENTSECRET
})
i want to do this dynamic, because the secret must be rotated every six months
If this is something you're doing every six months, I would personally just do it manually
You could also set up a service separately that uses the cli to do it every so often.
If your project runs on web too and not just native, you could use your deploy provider (eg., Netlify, Vercel) to run a "build" that's actually just generating and setting the secret via cli, since those build commands run in bash.
ok thanks. i thougt i only cans et environment variables trough the cli on development stage and not in the prod stage, but then i would set a github action, thanks.