cypress-firebase
cypress-firebase copied to clipboard
bug: auth emulator returns invalid custom token error
Describe the bug When I want to login to firebase via this command cy.login(uid), I will get an error which is coming form firebase. Error: Firebase: The custom token format is incorrect. Please check the documentation. (auth/invalid-custom-token).
+1 on this, works when using an actual firebase instance, does not when switching to an emulator
Hello !
I do not have such an error using the emulator but did you set both the code being tested and the test code to use the emulator ? I think I got the auth/invalid-custom-token error when forgetting to set one of them.
I just ran into this same issue today with my unchanged login flow was working for around 2 hours then suddenly stopped working and has been this way for now over an hour - this is the error as shown in the Cypress test runner:
BEFORE ALL (FAILED)
1. logCreating custom token for login...
2. taskcreateCustomToken, Object{3}
(xhr)POST 400 https://www.googleapis.com/identitytoolkit/v3/relyingparty/verifyCustomToken?key=<redacted>
The custom token format is incorrect. Please check the documentation.
Because this error occurred during a before all hook we are skipping the remaining tests in the current suite: Account user tests
In my case we log in once and then store that session so we do not need to constantly log in as we were hitting firebase quotas, but at the start of each spec file we clear the stored sessions prior to logging in.
Any suggestions would be most welcome as we have been using this package for months without issue!
Cypress version 10.3 as well if that makes a difference as later versions have caused us issues with flaky tests - thanks!
I observed the same behavior in my application. My host 127.0.0.1:3000 is connected with the emulator. Even the manual access to the emulators firebase runs:
cy.callFirestore('add', 'test_hello_world', { some: 'value' });
But cy.login() leads to the above error message... So I can't really test my web application.
Haven't retested with the auth emulator recently, so I'll take a look back at this, thanks for the callout.
As mentioned, pointing to a hosted auth instance should work fine with RTDB and Firestore emulators - this is actually what myself and team members are still doing in tests for multiple applications
Seems to be a similar issue here: https://github.com/prescottprue/cypress-firebase/issues/421