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: send metadata timestamps as int instead of string #7310

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

valeriangalliat
Copy link

Description

In the auth emulator sign in blocking function, send metadata.last_sign_in_time and metadata.creation_time as numbers and not strings so that firebase-functions can handle them.

This is already implemented for calling Cloud Functions associated with other auth events:

metadata: {
creationTime: user.createdAt
? new Date(parseInt(user.createdAt, 10)).toISOString()
: undefined,
lastSignInTime: user.lastLoginAt
? new Date(parseInt(user.lastLoginAt, 10)).toISOString()
: undefined,
},

But it's missing for the sign in blocking function call.

This results in sending string timestamps in the metadata:

metadata: {
  last_sign_in_time: '1665001706543',
  creation_time: '1697150491509'
}

This is unsupported by the firebase-functions framework on the other side, that expects a number: https://github.com/firebase/firebase-functions/blob/9c818713db511895a33378859ab1b9f2eef99179/src/common/providers/identity.ts#L363-L366

In particular, the way it uses it: https://github.com/firebase/firebase-functions/blob/9c818713db511895a33378859ab1b9f2eef99179/src/common/providers/identity.ts#L516-L521

    const creationTime = metadata?.creation_time
      ? new Date(metadata.creation_time).toUTCString()
      : null;
    const lastSignInTime = metadata?.last_sign_in_time
      ? new Date(metadata.last_sign_in_time).toUTCString()
      : null;

This results in e.g.:

    new Date('1697150491509').toUTCString()
    => 'Invalid Date'

By sending a number, we make sure that the receiving end can process the timestamps.

Scenarios Tested

  • Signing in to the emulator as an existing user

This is already implemented for calling Cloud Functions associated with
other auth events: https://github.com/firebase/firebase-tools/blob/d01da701554ac3c33786dd6486469293e0c93253/src/emulator/auth/cloudFunctions.ts#L77-L84

But it's missing for the sign in blocking function call.

This results in sending string timestamps in the metadata:

    metadata: {
      last_sign_in_time: '1665001706543',
      creation_time: '1697150491509'
    }

This is unsupported by the firebase-functions framework on the other
side, that expects a number: https://github.com/firebase/firebase-functions/blob/9c818713db511895a33378859ab1b9f2eef99179/src/common/providers/identity.ts#L363-L366

In particular, the way it uses it: https://github.com/firebase/firebase-functions/blob/9c818713db511895a33378859ab1b9f2eef99179/src/common/providers/identity.ts#L516-L521

    const creationTime = metadata?.creation_time
      ? new Date(metadata.creation_time).toUTCString()
      : null;
    const lastSignInTime = metadata?.last_sign_in_time
      ? new Date(metadata.last_sign_in_time).toUTCString()
      : null;

This results in e.g.:

    new Date('1697150491509').toUTCString()
    => 'Invalid Date'

By sending a number, we make sure that the receiving end can process the
timestamps.
@joehan joehan requested a review from colerogers June 20, 2024 21:13
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 this pull request may close these issues.

None yet

1 participant