管理配置和密钥
Supabase CLI 使用一个 config.toml 文件来管理本地配置。这个文件位于你项目的 supabase 目录下。
🌐 The Supabase CLI uses a config.toml file to manage local configuration. This file is located in the supabase directory of your project.
配置参考 #
🌐 Config reference
config.toml 文件是在你运行 supabase init 时自动创建的。
🌐 The config.toml file is automatically created when you run supabase init.
有各种各样的选项可以选择,可以在CLI 配置参考中找到。
🌐 There are a wide variety of options available, which can be found in the CLI Config Reference.
例如,要在本地开发中启用“Apple”OAuth提供商,你可以将以下信息添加到config.toml:
🌐 For example, to enable the "Apple" OAuth provider for local development, you can append the following information to config.toml:
1[auth.external.apple]2enabled = false3client_id = ""4secret = ""5redirect_uri = "" # Overrides the default auth redirectUrl.在 config.toml 中使用秘密 #
🌐 Using secrets inside config.toml
你可以在 config.toml 文件中使用 env() 函数来引用环境变量。这会检测存储在项目目录根目录下 .env 文件中的任何值。这对于存储敏感信息(比如 API 密钥)以及你不想提交到版本控制的其他值特别有用。
🌐 You can reference environment variables within the config.toml file using the env() function. This will detect any values stored in an .env file at the root of your project directory. This is particularly useful for storing sensitive information like API keys, and any other values that you don't want to check into version control.
1.2├── .env3├── .env.example4└── supabase5 └── config.toml不要把你的 .env 提交到 git。一定要把你的 .gitignore 配置好,排除这个文件。
🌐 Do NOT commit your .env into git. Be sure to configure your .gitignore to exclude this file.
例如,如果你的 .env 包含以下值:
🌐 For example, if your .env contained the following values:
1GITHUB_CLIENT_ID=""2GITHUB_SECRET=""然后你就可以像这样在我们的 config.toml 里引用它们:
🌐 Then you would reference them inside of our config.toml like this:
1[auth.external.github]2enabled = true3client_id = "env(GITHUB_CLIENT_ID)"4secret = "env(GITHUB_SECRET)"5redirect_uri = "" # Overrides the default auth redirectUrl.更进一步 #
🌐 Going further
对于更高级的秘密管理工作流程,包括:
🌐 For more advanced secrets management workflows, including:
- 使用 dotenvx 管理加密的秘密:了解如何在不同分支和环境中安全地管理环境变量
- 分支特定的秘密:了解如何管理不同部署环境的秘密
- 加密的配置值:直接在你的
config.toml中使用加密值
查看我们分支文档中的分支秘密管理部分,或查阅dotenvx 示例仓库以获得完整实现。
🌐 See the Managing secrets for branches section in our branching documentation, or check out the dotenvx example repository for a complete implementation.