jos*_*tit 2 firebase firebase-authentication
在阅读 firebase 模拟器文档时,我看到它提到了一个 REST API,该 API 将公开端点以创建用户。我找到了创建用户的文档,但它们似乎不适用于模拟器。
我尝试使用示例注册请求,但使用身份验证模拟器域 ( localhost:9099
)。我已经尝试专门为身份验证模拟器复制示例请求,但将其更改为模仿注册 api 的样子,但是这些都不起作用,而且他们刚刚抛出了 404。
有人有可以在 firebase 模拟器中创建用户的示例请求吗?或者我们需要为此创建客户端代码吗?
我想我明白了。我跟踪了从模拟器 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,
}),
});
Run Code Online (Sandbox Code Playgroud)
为了完整起见,以下是我清除用户的方法:
await fetch(`http://localhost:9099/emulator/v1/projects/${config.firebase.projectId}/accounts`, {
method: 'DELETE',
});
Run Code Online (Sandbox Code Playgroud)