Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auth Emulator does not work in v9.16.1, v9.16.2 or v9.16.3 because auth_time is null when token is generated #3673

Closed
lovelle-cardoso opened this issue Aug 13, 2021 · 2 comments · Fixed by #3674

Comments

@lovelle-cardoso
Copy link
Contributor

lovelle-cardoso commented Aug 13, 2021

The auth emulator seems to always generate a token where auth_time is null. This causes the auth emulator to throw "auth/internal-error" when calling getIdTokenResult.

This is most likely the bug causing #3671 and #3663

[REQUIRED] Environment info

firebase-tools: 9.16.1, 9.16.2, 9.16.3

Platform: Windows

[REQUIRED] Test case

Try calling getIdTokenResult in a client app that is connected to the latest version of firebase-tools's auth emulator. Notice the error that is thrown.

[REQUIRED] Steps to reproduce

  1. Run npm run serve using firebase-tools 9.16.3
  2. Run a client application that connects to the firebase auth emulator
  3. Signup a new user
  4. Call getIdTokenResult on that new user

[REQUIRED] Expected behavior

You are able to decode the user's token and retrieve their claims.

[REQUIRED] Actual behavior

"auth/internal-error" is thrown


If you breakpoint the line of code where "auth/internal-error" is thrown, you'll see that the error is thrown because auth_time is null in the decoded token.

@yuchenshi This bug may possibly have something to do with the PR I submitted a few weeks ago. Perhaps lastLoginAt is undefined?

#3611

If so, perhaps try changing these lines of code

auth_time:
user.lastLoginAt != null
? toUnixTimestamp(new Date(user.lastLoginAt))
: user.lastRefreshAt != null
? toUnixTimestamp(new Date(user.lastRefreshAt))
: toUnixTimestamp(new Date()),

to

    auth_time:
      user.lastLoginAt != null && user.lastLoginAt != undefined
        ? toUnixTimestamp(new Date(user.lastLoginAt))
        : user.lastRefreshAt != null && user.lastRefreshAt != undefined
        ? toUnixTimestamp(new Date(user.lastRefreshAt))
        : toUnixTimestamp(new Date()),
@lovelle-cardoso lovelle-cardoso changed the title Auth Emulator does not work in v9.16.1 or v9.16.2 because auth_time is null when token is generated Auth Emulator does not work in v9.16.1, v9.16.2 or v9.16.3 because auth_time is null when token is generated Aug 13, 2021
@yuchenshi
Copy link
Member

Thanks for pinning down #3611 as the cause. The fix though was a bit more involved. See #3674.

@lovelle-cardoso
Copy link
Contributor Author

@yuchenshi Apologies for making more work for you! Great job on the fast fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants