我可以在 Firebase 身份验证模拟器中使用 auth:import 和 auth:export 工具吗?

Ale*_*gli 11 firebase firebase-tools firebase-authentication

我想在启动时使用我的测试用户帐户预加载 firebase auth 模拟器,就像我对 Firestore 模拟器及其导入/导出选项所做的一样。我尝试在模拟器运行时使用 auth:import 和 auth:export,但它连接到我们实际的开发 firebase 项目,而不是模拟器。无论如何要针对身份验证模拟器运行 auth:import 和 auth:export 吗?

作为参考,我指的是这些命令 ( https://firebase.google.com/docs/cli/auth ) 和这个模拟器 ( https://firebase.google.com/docs/emulator-suite/connect_auth )。

Sea*_*ton 5

现在,Firebase 工具中已添加执行此操作的功能

旧的答案仍然有效并且可能有用

https://github.com/firebase/firebase-tools/releases/tag/v9.1.0

支持模拟器:Auth Emulator 的导出和导入 (#2955)。

https://github.com/firebase/firebase-tools/pull/2955

firebase help auth:import
Usage: firebase auth:import [options] [dataFile]

import users into your Firebase project from a data file(.csv or .json)

Options:
  --hash-algo <hashAlgo>               specify the hash algorithm used in password for these accounts
  --hash-key <hashKey>                 specify the key used in hash algorithm
  --salt-separator <saltSeparator>     specify the salt separator which will be appended to salt when verifying password. only used by SCRYPT now.
  --rounds <rounds>                    specify how many rounds for hash calculation.
  --mem-cost <memCost>                 specify the memory cost for firebase scrypt, or cpu/memory cost for standard scrypt
  --parallelization <parallelization>  specify the parallelization for standard scrypt.
  --block-size <blockSize>             specify the block size (normally is 8) for standard scrypt.
  --dk-len <dkLen>                     specify derived key length for standard scrypt.
  --hash-input-order <hashInputOrder>  specify the order of password and salt. Possible values are SALT_FIRST and PASSWORD_FIRST. MD5, SHA1, SHA256, SHA512, HMAC_MD5, HMAC_SHA1, HMAC_SHA256, HMAC_SHA512 support this flag.
  -h, --help                           output usage information
Run Code Online (Sandbox Code Playgroud)

  • 既然该功能已经存在,您如何实际将身份验证导入到模拟器中?我似乎找不到任何明确的文档/示例。例如,目前要导入 Firestore DB,我有一个以前的数据库导出,我使用以下命令拉入: `firebase emulators:start --import=./backups/$DB_EN​​V/db` 我会添加什么来拉入,例如 auth导出也存储在文件:`auth.json`中? (4认同)
  • 谢谢肖恩。为了解决我的特定身份验证导入问题,我最终运行了“firebase emulators:export ./backups/emulator”,这会生成模拟器在导入期间查找的新更新的元数据文件和文件夹结构 - 如果您需要,这包括一个“auth_export”文件夹重新使用最新版本。所以现在我只需镜像该文件/文件夹结构,并且可以将实时数据迁移到模拟器中。快乐的时光! (3认同)

yel*_*yed 5

完成此操作的最简单方法是在--export-on-exit运行模拟器时传入 ,例如:firebase emulators:start --export-on-exit .firebase-emulators,这将在退出模拟器时将所有测试数据转储到指定目录中。

然后,如果需要,您可以将其签入源代码(确保模拟器中没有敏感数据),并在firebase emulators:start --import .firebase-emulators每次启动时读取它。