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
- Run
npm run serve using firebase-tools 9.16.3
- Run a client application that connects to the firebase auth emulator
- Signup a new user
- 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()),
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
npm run serveusing firebase-tools 9.16.3[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
firebase-tools/src/emulator/auth/operations.ts
Lines 1729 to 1734 in 8e8043b
to