从 Firebase Auth 迁移到 Supabase
Migrate Firebase auth users to Supabase Auth.
Supabase 提供了几种 工具 来帮助将认证用户从 Firebase 项目迁移到 Supabase 项目。迁移过程分为两个部分:
🌐 Supabase provides several tools to help migrate auth users from a Firebase project to a Supabase project. There are two parts to the migration process:
firestoreusers2json(TypeScript,JavaScript)可以把现有的 Firebase 项目中的用户导出到你本地系统的.json文件中。import_users(TypeScript、JavaScript)可以从已保存的.json文件中导入用户到你的 Supabase 项目(将这些用户插入到Postgres数据库实例的auth.users表中)。
设置迁移工具 #
🌐 Set up the migration tool [#set-up-migration-tool]
-
克隆
firebase-to-supabase仓库:1git clone https://github.com/supabase-community/firebase-to-supabase.git -
在
/auth目录下,创建一个名为supabase-service.json的文件,内容如下:1{2"host": "database.server.com",3"password": "secretpassword",4"user": "postgres",5"database": "postgres",6"port": 54327} -
在你的项目仪表板上,点击 连接
-
在会话池下,点击连接字符串下的“查看参数”。将
Host和User字段替换为显示的值。 -
在
supabase-service.json文件的password项中输入你创建 Supabase 项目时使用的密码。
生成一个 Firebase 私钥 #
🌐 Generate a Firebase private key [#generate-firebase-private-key]
- 登录你的 Firebase 控制台 并打开你的项目。
- 点击侧边栏 项目概览 旁边的齿轮图标,然后选择 项目设置。
- 点击 服务账户,然后选择 Firebase 管理 SDK。
- 点击 生成新的私钥。
- 把下载的文件重命名为
firebase-service.json。
保存你的 Firebase 密码哈希参数 #
🌐 Save your Firebase password hash parameters [#save-firebase-hash-parameters]
- 登录你的 Firebase 控制台 并打开你的项目。
- 在侧边栏中选择 身份验证(构建部分)。
- 在顶部菜单中选择 用户。
- 在用户列表的右上角,打开菜单(三个点),然后点击 密码哈希参数。
- 复制并保存
base64_signer_key、base64_salt_separator、rounds和mem_cost的参数。
1hash_config {2 algorithm: SCRYPT,3 base64_signer_key: XXXX/XXX+XXXXXXXXXXXXXXXXX+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX==,4 base64_salt_separator: Aa==,5 rounds: 8,6 mem_cost: 14,7}命令行选项 #
🌐 Command line options
将 Firestore 用户导出到 JSON 文件 #
🌐 Dump Firestore users to a JSON file [#dump-firestore-users]
node firestoreusers2json.js [<filename.json>] [<batch_size>]
filename.json:(可选) 输出文件名(默认为./users.json)batchSize:(可选) 每批获取的用户数量(默认值为100)
将 JSON 用户文件导入 Supabase Auth(Postgres:auth.users#
🌐 Import JSON users file to Supabase Auth (Postgres: auth.users) [#import-json-users-file]
node import_users.js <path_to_json_file> [<batch_size>]
path_to_json_file:JSON 输入文件(用户)的完整本地路径和文件名batch_size:(可选) 每批处理的用户数量(默认 100)
注释 #
🌐 Notes
对于更高级的迁移,包括使用中间件服务器组件来验证用户现有的 Firebase 密码,并在用户首次登录时在你的 Supabase 项目中更新该密码,请参阅 firebase-to-supabase 仓库。
🌐 For more advanced migrations, including the use of a middleware server component for verifying a user's existing Firebase password and updating that password in your Supabase project the first time a user logs in, see the firebase-to-supabase repo.
资源 #
🌐 Resources
迁移到 Supabase #
🌐 Migrate to Supabase
如果你在迁移项目时需要更多帮助,联系我们。