Skip to content

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

@lovelle-cardoso

Description

@lovelle-cardoso

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()),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions