firebase-admin-node icon indicating copy to clipboard operation
firebase-admin-node copied to clipboard

Firebase Auth wrongly assumes lastSignInTime is not null

Open stx opened this issue 3 years ago • 6 comments

lastSignInTime can be null when a user is created by the Admin SDK.

https://github.com/firebase/firebase-admin-node/blob/94dd7c3efb9ff00b0462cf772b803d6abecc2dcc/src/auth/user-record.ts#L305

stx avatar Mar 21 '22 03:03 stx

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Mar 21 '22 03:03 google-oss-bot

Hi @stx, lastSignInTime is an optional property in the public API interface. https://github.com/firebase/firebase-admin-node/blob/94dd7c3efb9ff00b0462cf772b803d6abecc2dcc/src/auth/user-import-builder.ts#L190

To help me understand the issue could you provide more context, please? Thanks!

lahirumaramba avatar Mar 22 '22 23:03 lahirumaramba

@lahirumaramba Thanks for taking a look! Did you see the code I referenced in the OP?

https://github.com/firebase/firebase-admin-node/blob/94dd7c3efb9ff00b0462cf772b803d6abecc2dcc/src/auth/user-record.ts#L305

stx avatar Mar 22 '22 23:03 stx

The code you linked is used to parse the server response. When parsing the response, parseDate(...) returns null if the field is not available in the response. Are you seeing any errors in your code caused by this? I tested with the following code by creating a new user and the response shows lastSignInTime as null.

getAuth()
  .createUser({
    email: '[email protected]',
    emailVerified: false,
    phoneNumber: '+11234567890',
    password: 'secretPassword',
    displayName: 'John Doe',
    photoURL: 'http://www.example.com/12345678/photo.png',
    disabled: false,
  })
  .then((userRecord) => {
    // See the UserRecord reference doc for the contents of userRecord.
    console.log('Successfully created new user:', userRecord);
  })
  .catch((error) => {
    console.log('Error creating new user:', error);
  });
Successfully created new user: UserRecord {
  uid: 'CloAfjk8ATX2XNFY9vJItl1gYmj1',
  email: '[email protected]',
  emailVerified: false,
  displayName: 'John Doe',
  photoURL: 'http://www.example.com/12345678/photo.png',
  phoneNumber: '+11234567890',
  disabled: false,
  metadata: UserMetadata {
    creationTime: 'Wed, 23 Mar 2022 17:35:32 GMT',
    lastSignInTime: null,
    lastRefreshTime: null
  },
  providerData: [
    UserInfo {
      uid: '+11234567890',
      displayName: undefined,
      email: undefined,
      photoURL: undefined,
      providerId: 'phone',
      phoneNumber: '+11234567890'
    },
    UserInfo {
      uid: '[email protected]',
      displayName: 'John Doe',
      email: '[email protected]',
      photoURL: 'http://www.example.com/12345678/photo.png',
      providerId: 'password',
      phoneNumber: undefined
    }
  ],
  passwordHash: undefined,
  passwordSalt: undefined,
  tokensValidAfterTime: 'Wed, 23 Mar 2022 17:35:32 GMT',
  tenantId: undefined
}

If you are running into any problems in your code, please describe the issue and provide a minimal repo or code samples to help us investigate further.

lahirumaramba avatar Mar 23 '22 17:03 lahirumaramba

Hi @lahirumaramba, everything works just fine, but VSCode shows it as non-nullable when accessing that field and points to that code:

image

stx avatar Mar 30 '22 00:03 stx