Firebase Admin会在连接到Auth Molulator时提供错误的错误
我正在尝试使用Firebase Admin SDK列出Firebase项目的所有用户。
从云验证服务列出时,列出用户列出的算法正常工作。
const admin = require('firebase-admin');
const serviceAccount = require('./certs/project-cert.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
})
listAllUsers = (nextPageToken) => {
// List batch of users, 1000 at a time.
admin.auth().listUsers(1000, nextPageToken)
.then(function(listUsersResult) {
listUsersResult.users.forEach(function(userRecord) {
console.log(userRecord.toJSON());
});
if (listUsersResult.pageToken) {
// List next batch of users.
listAllUsers(listUsersResult.pageToken);
}
})
.catch(function(error) {
console.log('Error listing users:', error);
});
}
然后,我将env var设置为指向模拟器
export FIREBASE_AUTH_EMULATOR_HOST="localhost:9099"
并运行相同的listallusers
func失败,但有以下错误:
FirebaseAppError: Error while making request: connect ECONNREFUSED ::1:9099. Error code: ECONNREFUSED
at FirebaseAppError.FirebaseError [as constructor] (/Users/<me>/Work/pc/<project>/node_modules/firebase-admin/lib/utils/error.js:44:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/<me>/Work/pc/<project>/node_modules/firebase-admin/lib/utils/error.js:90:28)
at new FirebaseAppError (/Users/<me>/Work/pc/<project>/node_modules/firebase-admin/lib/utils/error.js:125:28)
at /Users/<me>/Work/pc/<project>/node_modules/firebase-admin/lib/utils/api-request.js:211:19
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errorInfo: {
code: 'app/network-error',
message: 'Error while making request: connect ECONNREFUSED ::1:9099. Error code: ECONNREFUSED'
},
codePrefix: 'app'
}
我可以看到模拟器在端口9099上运行,我可以从http:http: // localhost:4000/auth
。
iPhone模拟器本身可以访问auth Mimulator,但是使用Admin SDK
My Env
macOS Monterey 12.3.1
"firebase-admin": "^10.2.0",
firebase-tools 10.9.2
node ver 17.6.0
Firebase.json获得连接错误
...
"emulators": {
"auth": {
"port": 9099
},
...
I am trying to list all users of my Firebase project using Firebase Admin SDK.
The below func to list users works fine when listing from Cloud Auth Service.
const admin = require('firebase-admin');
const serviceAccount = require('./certs/project-cert.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount)
})
listAllUsers = (nextPageToken) => {
// List batch of users, 1000 at a time.
admin.auth().listUsers(1000, nextPageToken)
.then(function(listUsersResult) {
listUsersResult.users.forEach(function(userRecord) {
console.log(userRecord.toJSON());
});
if (listUsersResult.pageToken) {
// List next batch of users.
listAllUsers(listUsersResult.pageToken);
}
})
.catch(function(error) {
console.log('Error listing users:', error);
});
}
Then I set the ENV var to point to Emulator
export FIREBASE_AUTH_EMULATOR_HOST="localhost:9099"
And running the same listAllUsers
func fails with following error:
FirebaseAppError: Error while making request: connect ECONNREFUSED ::1:9099. Error code: ECONNREFUSED
at FirebaseAppError.FirebaseError [as constructor] (/Users/<me>/Work/pc/<project>/node_modules/firebase-admin/lib/utils/error.js:44:28)
at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/<me>/Work/pc/<project>/node_modules/firebase-admin/lib/utils/error.js:90:28)
at new FirebaseAppError (/Users/<me>/Work/pc/<project>/node_modules/firebase-admin/lib/utils/error.js:125:28)
at /Users/<me>/Work/pc/<project>/node_modules/firebase-admin/lib/utils/api-request.js:211:19
at processTicksAndRejections (node:internal/process/task_queues:96:5) {
errorInfo: {
code: 'app/network-error',
message: 'Error while making request: connect ECONNREFUSED ::1:9099. Error code: ECONNREFUSED'
},
codePrefix: 'app'
}
I can see that the Emulator is running on port 9099, I can access it from http://localhost:4000/auth
.
The iPhone emulator itself can access the Auth Emulator fine, but getting the connection error with Admin SDK
My env
macOS Monterey 12.3.1
"firebase-admin": "^10.2.0",
firebase-tools 10.9.2
node ver 17.6.0
firebase.json
...
"emulators": {
"auth": {
"port": 9099
},
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将您的本地主机更改为127.0.0.1.1&nbsp;或类似的(如果您使用像Docker这样的容器服务)
更改以下内容:
对此:
有时候,Localhost和127.0.0.1的行为不同,根据您的平台,
我在安装Docker和所有内容后都会发现它,以及所有内容这取决于
localhost
停止工作Change your localhost to 127.0.0.1 or similar (in case you use container services like docker)
Change this:
To this:
Sometimes localhost and 127.0.0.1 act differently depending on your platform
I figured it out after I installed docker, and everything that depends on
localhost
stopped working我在运行离子 /电容器应用程序时也遇到了这个问题,但仅在尝试从Andriod和iOS测试时。它是从网络上工作的。我发现我需要设置
firebase.json
以指向我的计算机的IP地址192.168.68.22:然后,我确保在调用
conder> connectauthemulator()
时确保使用这些值。或connectfirestoreemulator()
:I ran into this issue as well while running my Ionic / Capacitor app, but only while trying to test from andriod and ios. It was working from web. I found I needed to set the
firebase.json
to point to my computer's IP address of 192.168.68.22:Then, I made sure to use those values when calling
connectAuthEmulator()
orconnectFirestoreEmulator()
: