Skip to content

Cleaned up auth user types for easier debugging #1

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

Merged
merged 2 commits into from
Mar 21, 2017

Conversation

jwngr
Copy link

@jwngr jwngr commented Mar 20, 2017

Description

I’ve now seen several reports of people getting confused by the fact that when you log UserRecord, you get a bunch of properties which are named <something>Internal. People think those are what they should use instead of just <something>. This change has no functional difference other than cleaning up which these properties display when doing a console.log().

Code sample

Previous output:

UserRecord {
  uidInternal: '0aiHf8cXAhumgYbHqE05',
  emailInternal: '[email protected]',
  emailVerifiedInternal: false,
  displayNameInternal: 'Random User 0aiHf8cXAhumgYbHqE05',
  photoURLInternal: 'http://www.example.com/0aiHf8cXAhumgYbHqE05/photo.png',
  disabledInternal: false,
  metadataInternal: 
   UserMetadata {
     createdAtInternal: 2017-02-02T05:25:35.000Z,
     lastSignedInAtInternal: null },
  providerDataInternal: 
   [ UserInfo {
       uidInternal: '[email protected]',
       displayNameInternal: 'Random User 0aiHf8cXAhumgYbHqE05',
       emailInternal: '[email protected]',
       photoURLInternal: 'http://www.example.com/0aiHf8cXAhumgYbHqE05/photo.png',
       providerIdInternal: 'password' } ] }

New output:

UserRecord {
  uid: '0aiHf8cXAhumgYbHqE05',
  email: '[email protected]',
  emailVerified: false,
  displayName: 'Random User 0aiHf8cXAhumgYbHqE05',
  photoURL: 'http://www.example.com/0aiHf8cXAhumgYbHqE05/photo.png',
  disabled: false,
  metadata: UserMetadata { createdAt: 2017-02-02T05:25:35.000Z, lastSignedInAt: null },
  providerData: 
   [ UserInfo {
       uid: '[email protected]',
       displayName: 'Random User 0aiHf8cXAhumgYbHqE05',
       email: '[email protected]',
       photoURL: 'http://www.example.com/0aiHf8cXAhumgYbHqE05/photo.png',
       providerId: 'password' } ] }

I’ve now seen several reports of people getting confused by the fact
that when you log `UserRecord`, you get a bunch of properties which are
named `<something>Internal`. People think those are what they should
use instead of just `<something>`. This change has no functional
difference other than cleaning up which these properties display when
doing a `console.log()`.

Change-Id: I79d79fa6bf7c0184d9db947031eecca5e9af1d4b
@@ -28,26 +29,16 @@ function parseDate(time: any): Date {
* @constructor
*/
export class UserMetadata {
private lastSignedInAtInternal: Date;
private createdAtInternal: Date;
public readonly createdAt: Date;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that readonly here is a compilation time check only. I think it's useful to have to make sure we don't accidentally set the property in our own codebase, but it does not enforce read-only behavior for end-users. That is why I needed to explicitly use Object.defineProperty() below to enforce the read-only behavior.

*
* @return {Object} The object that was passed to the function.
*/
export function addGetter(obj: Object, prop: string, value: any): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this should be renamed to something like addReadonlyGetter or something of the like since a getter does not necessarily imply the property does not have a setter?

Also would be helpful to a test for this, where you add a readonly property on an object, try to change its value and then check the old value is still there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Change-Id: Iddcd18cfeab45921d55f05232fad6bb1691609b2
@jwngr
Copy link
Author

jwngr commented Mar 21, 2017

Back to you @bojeil-google! Also, in the future, please use the GitHub UI to assign the PR back to me after you are done with your review. That way, you'll get a notification when I've assigned the PR back to you once I'm done, instead of me having to send you a comment like this.

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.

2 participants