在阅读 firebase 模拟器文档时,我看到它 mentioned 一个 REST API 会公开端点以创建用户。我发现 docs 可以创建用户,但它们似乎不适用于模拟器。
我已尝试使用示例注册请求,但使用身份验证模拟器域 (localhost:9099
)。我已经尝试复制专门针对身份验证模拟器的示例请求,但将其更改为模仿注册 api 的样子,但是这些都没有奏效,他们刚刚抛出了 404。
有没有人有可以在 firebase 模拟器中创建用户的示例请求?或者这是我们需要为其创建客户端代码的内容吗?
答案 0 :(得分:1)
我想我明白了。我遵循了从模拟器 Web UI 发出的 HTTP 请求,这对我有用:
await fetch(`http://localhost:9099/identitytoolkit.googleapis.com/v1/accounts:signUp?key=${config.firebase.apiKey}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
email: 'user@test.com',
password: 'pass1234',
returnSecureToken: true,
}),
});
为了完整起见,以下是我清除用户的方法:
await fetch(`http://localhost:9099/emulator/v1/projects/${config.firebase.projectId}/accounts`, {
method: 'DELETE',
});