Skip to content

Migrating Auth Users Between Supabase Projects

你可以将 auth 模式下的所有表,包括用户及其加密密码,从一个 Supabase 项目迁移到另一个。这意味着用户在迁移后无需重置或重新创建密码。

🌐 You can migrate all tables in the auth schema—including users and their hashed passwords—from one Supabase project to another. This means users do not need to reset or recreate their passwords after migration.

重要:JWT 密钥和令牌有效期 #

🌐 Important: JWT secret and token validity

每个项目都会配置一个独特的 JWT 密钥,用来签名和验证身份认证令牌。这有两个主要影响:

🌐 Each project is provisioned with a unique JWT secret used to sign and verify auth tokens. This has two key implications:

  • 如果新项目里的 JWT 密钥不一样,现有的令牌就会失效,用户需要重新登录才能拿到新的令牌。
  • 如果你在新项目中重用原来的 JWT 密钥,现有的令牌仍然有效,用户无需重新认证。

你可以通过访问以下路径在新项目中配置自定义 JWT 密钥: 设置 > API > JWT 密钥

🌐 You can configure a custom JWT secret in the new project by going to: Settings > API > JWT Secret

注意:更新 JWT 密钥会在新项目中重新生成你的匿名和服务角色 API 密钥。

🌐 Note: Updating the JWT secret will regenerate your anon and service_role API keys in the new project.

如何迁移认证数据 #

🌐 How to migrate Auth data

我们目前没有提供通用的脚本来仅迁移认证架构,但这个过程在我们的通用迁移指南中有介绍。你可以使用以下任意一种方式:

🌐 We don’t currently provide a one-size-fits-all script for migrating only the auth schema, but the process is covered in our general migration guide. You can use either:

  • 来自仪表板的完整 .backup 文件,或
  • 通过 Supabase CLI(例如 pg_dump 和 psql)进行 SQL 导出/导入

查看完整迁移指南