firebaseAuthEmulatorHost is ignored and requests to live servers are made
borisyordanov opened this issue · 7 comments
When filing a bug report, please confirm you've done the following:
- Have you set
onVerifyTokenError
andonTokenRefreshError
in your config and checked for any helpful errors? Yes - Have you set
debug: true
in your config and read through server-side and client-side debug logs for any helpful messages? Yes - Have you tried the example app with your own Firebase credentials? Yes
- Have you read through the troubleshooting Q&A? Yes
Describe the bug
A clear and concise description of the bug.
Versions
next-firebase-auth
version: 1.0.0-beta.0
Firebase JS SDK: 12.4.2
Next.js: 13.2.1
To Reproduce
Steps to reproduce the behavior:
- Open network tab
- navigate a page protected by withUser HOC on localhost with firebaseAuthEmulatorHost set
- you will find requests made to a remote auth server along with
Expected behavior
Only requests to firebase auth emulators should be made
Debug and error logs
blender:dev: next-firebase-auth: [withUser] Calling "withUser".
blender:dev: i18next: languageChanged bg
blender:dev: i18next: languageChanged bg
blender:dev: next-firebase-auth: [withUser] Set user to: {
blender:dev: id: null,
blender:dev: email: null,
blender:dev: emailVerified: false,
blender:dev: tenantId: null,
blender:dev: phoneNumber: null,
blender:dev: displayName: null,
blender:dev: photoURL: null,
blender:dev: claims: {},
blender:dev: getIdToken: [Function: S],
blender:dev: clientInitialized: false,
blender:dev: firebaseUser: null,
blender:dev: signOut: [Function: x],
blender:dev: serialize: [Function: serialize]
blender:dev: }
blender:dev: next-firebase-auth: [setAuthCookies] Attempting to set auth cookies.
blender:dev: next-firebase-auth: [setAuthCookies] Attempting to set auth cookies.
blender:dev: onVerifyTokenError {
blender:dev: err: FirebaseAppError: Error while making request: connect ECONNREFUSED ::1:9099. Error code: ECONNREFUSED // unclear where this error code comes from. Both requests are valid and complete
blender:dev: at C:\Users\boris\Desktop\Projects\apps\node_modules\firebase-admin\lib\utils\api-request.js:178:19
blender:dev: at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
blender:dev: errorInfo: {
blender:dev: code: 'app/network-error',
blender:dev: message: 'Error while making request: connect ECONNREFUSED ::1:9099. Error code: ECONNREFUSED'
blender:dev: },
blender:dev: codePrefix: 'app'
blender:dev: }
blender:dev: }
blender:dev: next-firebase-auth: [verifyIdToken] Error verifying the ID token: app/network-error. The user will be unauthenticated.
blender:dev: next-firebase-auth: [setAuthCookies] Failed to verify the ID token. Cannot authenticate the user or get a refresh token.
blender:dev: next-firebase-auth: [setAuthCookies] Set auth cookies. The user is not authenticated.
blender:dev: log in success
blender:dev: onVerifyTokenError {
blender:dev: err: FirebaseAppError: Error while making request: connect ECONNREFUSED ::1:9099. Error code: ECONNREFUSED // unclear why this happens a second time
blender:dev: at C:\Users\boris\Desktop\Projects\apps\node_modules\firebase-admin\lib\utils\api-request.js:178:19
blender:dev: at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
blender:dev: errorInfo: {
blender:dev: code: 'app/network-error',
blender:dev: message: 'Error while making request: connect ECONNREFUSED ::1:9099. Error code: ECONNREFUSED'
blender:dev: },
blender:dev: codePrefix: 'app'
blender:dev: }
blender:dev: next-firebase-auth: [verifyIdToken] Error verifying the ID token: app/network-error. The user will be unauthenticated. //This kicks out the users since the remote server couldn't validate the token
blender:dev: next-firebase-auth: [setAuthCookies] Failed to verify the ID token. Cannot authenticate the user or get a refresh token.
blender:dev: next-firebase-auth: [setAuthCookies] Set auth cookies. The user is not authenticated.
blender:dev: log in success
blender:dev: }
blender:dev: i18next: languageChanged bg
blender:dev: i18next: languageChanged bg
blender:dev: next-firebase-auth: [withUser] Set user to: {
blender:dev: id: null,
blender:dev: email: null,
blender:dev: emailVerified: false,
blender:dev: tenantId: null,
blender:dev: phoneNumber: null,
blender:dev: displayName: null,
blender:dev: photoURL: null,
blender:dev: claims: {},
blender:dev: getIdToken: [Function: S],
blender:dev: clientInitialized: false,
blender:dev: firebaseUser: null,
blender:dev: signOut: [Function: x],
blender:dev: serialize: [Function: serialize]
blender:dev: }
blender:dev: next-firebase-auth: [unsetAuthCookies] Unset auth cookies.
blender:dev: log out success
blender:dev: next-firebase-auth: [unsetAuthCookies] Unset auth cookies.
blender:dev: log out success
blender:dev: i18next: languageChanged bg
blender:dev: i18next: languageChanged bg
blender:dev: next-firebase-auth: [withUser] Set user to: {
blender:dev: id: null,
blender:dev: email: null,
blender:dev: emailVerified: false,
blender:dev: tenantId: null,
blender:dev: phoneNumber: null,
blender:dev: displayName: null,
blender:dev: photoURL: null,
blender:dev: claims: {},
blender:dev: getIdToken: [Function: S],
blender:dev: clientInitialized: false,
blender:dev: firebaseUser: null,
blender:dev: signOut: [Function: x],
blender:dev: serialize: [Function: serialize]
blender:dev: }
blender:dev: next-firebase-auth: [unsetAuthCookies] Unset auth cookies.
blender:dev: log out success
blender:dev: next-firebase-auth: [unsetAuthCookies] Unset auth cookies.
blender:dev: log out success
blender:dev: WARNING: You are using the Auth Emulator, which is intended for local testing only. Do not use with production credentials.
blender:dev: next-firebase-auth: [init] Setting config with provided value: {
blender:dev: appPageURL: '/',
blender:dev: authPageURL: '/login',
blender:dev: cookies: {
blender:dev: httpOnly: true,
blender:dev: keys: [ 'hidden' ],
blender:dev: maxAge: 1036800000,
blender:dev: name: 'Blender',
blender:dev: overwrite: true,
blender:dev: path: '/',
blender:dev: sameSite: 'strict',
blender:dev: secure: true,
blender:dev: signed: true
blender:dev: },
blender:dev: debug: true,
blender:dev: firebaseAdminInitConfig: {
blender:dev: credential: {
blender:dev: clientEmail: 'hidden',
blender:dev: privateKey: 'hidden',
blender:dev: projectId: 'toki-apps-dev'
blender:dev: },
blender:dev: databaseURL: ''
blender:dev: },
blender:dev: firebaseAuthEmulatorHost: 'localhost:9099',
blender:dev: firebaseClientInitConfig: {
blender:dev: apiKey: 'AIzaSyBdEbA4hgOAwieV67TopiYVwk4VQquhXpk',
blender:dev: authDomain: 'toki-apps-dev.firebaseapp.com',
blender:dev: projectId: 'toki-apps-dev'
blender:dev: },
blender:dev: loginAPIEndpoint: '/api/login',
blender:dev: logoutAPIEndpoint: '/api/logout',
blender:dev: onLoginRequestError: [Function: onLoginRequestError],
blender:dev: onLogoutRequestError: [Function: onLogoutRequestError],
blender:dev: onTokenRefreshError: [Function: onTokenRefreshError],
blender:dev: onVerifyTokenError: [Function: onVerifyTokenError]
blender:dev: }
blender:dev: next-firebase-auth: [withUser] Calling "withUser".
Additional context
Valid request to emulators at port 9099
Response
{
"kind": "identitytoolkit#GetAccountInfoResponse",
"users": [
{
"localId": "52FX2KuXuxtZw2R5uhcTVy9rfU5h",
"createdAt": "1683270419368",
"lastLoginAt": "1689580717033",
"displayName": "",
"photoUrl": "",
"passwordHash": "fakeHash:salt=fakeSaltDwqo8sqxqhnXujbioDt3:password=123456",
"salt": "fakeSaltDwqo8sqxqhnXujbioDt3",
"passwordUpdatedAt": 1689579869520,
"providerUserInfo": [
{
"providerId": "password",
"email": "b.yordanov@toki.bg",
"federatedId": "b.yordanov@toki.bg",
"rawId": "b.yordanov@toki.bg",
"displayName": "",
"photoUrl": ""
}
],
"validSince": "1689579869",
"email": "b.yordanov@toki.bg",
"emailVerified": false,
"disabled": false,
"lastRefreshAt": "2023-07-17T07:58:37.033Z"
}
]
}
Invalid request to GCP servers
Response
{
"error": {
"code": 400,
"message": "INVALID_ID_TOKEN",
"errors": [
{
"message": "INVALID_ID_TOKEN",
"domain": "global",
"reason": "invalid"
}
]
}
}
What are your versions of firebase
and firebase-admin
? If firebase
is something other than version 9.16.0, could you try 9.16.0 to see if the problem still occurs?
@kmjennison These are the used versions:
- firebase@9.23.0
- firebase-admin@11.9.0
Please try with Firebase v9.16.0 to see if the problem still occurs. I'm wondering if this is related to #614.
@kmjennison No change after downgrading to 9.16.0
I think I have hit this issue as well, I have tried with 9.16.0.
@borisyordanov did you fix it on your side ?
Our setup worked previously but stopped working after a few dependencies upgrades, but we are not sure which one was responsible of the issue.
We rolled back the changes, reinstall everything but the issue still occurs. This is really odd.
We are using firebase emulators in docker (using https://github.com/AndreySenov/firebase-tools-docker), I don't know if this can be related...
@fabienheureux We didn't fix this. We stopped using this package
Please try initializing the Firebase JS SDK yourself prior to initializing next-firebase-auth
. Let me know if the problem persists after that, and I'll reopen.