How to automatically create API keys (non-legacy) for new branches
Hello! We've recently switched over from Legacy API Keys to the new API Keys on our Supabase project, but each time we create a new branch they only have Legacy API Keys generated (same for JWT keys) - we need to manually generate the new API Keys to continue using the branches.
Is there a way to configure our project settings to automatically switch off the legacy API/JWT keys for newly-created branches?
8 Replies
This is strange i just tried on a branch i had lying around and it didn;t see any issues generating the new API keys. Do you not have the option to create new keys in the project settings?
branches are just like any other projects in how you interact with them
We can definitely manually create the keys in the UI - I just wanted to know if there was a way to have new branches have them be generated by default, especially if this seems like the latest best practices for building on Supabase
Ahh okay, yeah i don't think that functionality has rolled out yet and i just had a look at the
config.toml which is probably where something like this exists for branches and couldn't find anything on there either
what is your setup looking like, are you using supabase branching with vercel in which case the keys automatically get added in or something elseWe have a GitHub Action that uses the Supabase CLI to create a new branch, run migrations, etc. when we detect DB schema file changes in our PR.
TBH, we probably could update the action to automatically create the API keys too (if that's exposed via the CLI or some HTTP endpoint)
E.g.,
supabase projects api-keys --project-ref <branch ref here> can list API keys, but I don't see an analogous CLI command to create new (non-legacy) ones for a branch.There are some http requests you can make using the management api if you want to give that a go https://supabase.com/docs/reference/api/v1-create-project-api-key
Management API Reference | Supabase Docs
Management API reference for the Supabase API
you would need to pass in the project ref of the new branch you create i think
Yeah that could definitely work for us - thanks for referring me to it!
Ideally it'd be nice to have new branches start creating them automatically now that we've opted in - but this will work in the meantime. Thanks agian
no worries! if you have any issues circle back round