Skip to content

Cleaned up auth user types for easier debugging - #1

Merged
jwngr merged 2 commits into
masterfrom
jw-hide-internal-vars
Mar 21, 2017
Merged

Cleaned up auth user types for easier debugging#1
jwngr merged 2 commits into
masterfrom
jw-hide-internal-vars

Conversation

@jwngr

@jwngr jwngr commented Mar 20, 2017

Copy link
Copy Markdown

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: '0aihf8cxahumgybhqe05@example.com',
  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: '0aihf8cxahumgybhqe05@example.com',
       displayNameInternal: 'Random User 0aiHf8cXAhumgYbHqE05',
       emailInternal: '0aihf8cxahumgybhqe05@example.com',
       photoURLInternal: 'http://www.example.com/0aiHf8cXAhumgYbHqE05/photo.png',
       providerIdInternal: 'password' } ] }

New output:

UserRecord {
  uid: '0aiHf8cXAhumgYbHqE05',
  email: '0aihf8cxahumgybhqe05@example.com',
  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: '0aihf8cxahumgybhqe05@example.com',
       displayName: 'Random User 0aiHf8cXAhumgYbHqE05',
       email: '0aihf8cxahumgybhqe05@example.com',
       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
Comment thread src/auth/user-record.ts
export class UserMetadata {
private lastSignedInAtInternal: Date;
private createdAtInternal: Date;
public readonly createdAt: Date;

Copy link
Copy Markdown
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.

Comment thread src/utils/index.ts Outdated
*
* @return {Object} The object that was passed to the function.
*/
export function addGetter(obj: Object, prop: string, value: any): void {

Copy link
Copy Markdown
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
Copy Markdown
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

jwngr commented Mar 21, 2017

Copy link
Copy Markdown
Author

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