Skip to content

Commit

Permalink
[Auth] Add missing initializer for providerData to UserImpl (#5938)
Browse files Browse the repository at this point in the history
* Add missing initializer for providerData to UserImpl

* Changeset
  • Loading branch information
sam-gc committed Jan 27, 2022
1 parent d612d6f commit af92348
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-brooms-clean.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/auth": patch
---

Fix bug where `user.providerData` field was being improperly initialized
16 changes: 16 additions & 0 deletions packages/auth/src/core/user/user_impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@ describe('core/user/user_impl', () => {
photoURL: 'photo',
emailVerified: false,
isAnonymous: true,
providerData: [{
providerId: 'password',
displayName: null,
photoURL: null,
email: 'test@foo.test',
phoneNumber: null,
uid: 'i-am-uid'
}],
tenantId: 'tenant-id'
});

Expand All @@ -274,6 +282,14 @@ describe('core/user/user_impl', () => {
expect(copy.toJSON()).to.eql(user.toJSON());
expect(copy.auth).to.eq(newAuth);
expect(copy.tenantId).to.eq('tenant-id');
expect(copy.providerData).to.eql([{
providerId: 'password',
displayName: null,
photoURL: null,
email: 'test@foo.test',
phoneNumber: null,
uid: 'i-am-uid'
}]);
});
});
});
9 changes: 5 additions & 4 deletions packages/auth/src/core/user/user_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ export class UserImpl implements UserInternal {

uid: string;
auth: AuthInternal;
emailVerified = false;
isAnonymous = false;
tenantId: string | null = null;
emailVerified: boolean;
isAnonymous: boolean;
tenantId: string | null;
readonly metadata: UserMetadata;
providerData: MutableUserInfo[] = [];
providerData: MutableUserInfo[];

// Optional fields from UserInfo
displayName: string | null;
Expand All @@ -88,6 +88,7 @@ export class UserImpl implements UserInternal {
this.photoURL = opt.photoURL || null;
this.isAnonymous = opt.isAnonymous || false;
this.tenantId = opt.tenantId || null;
this.providerData = opt.providerData ? [...opt.providerData] : [];
this.metadata = new UserMetadata(
opt.createdAt || undefined,
opt.lastLoginAt || undefined
Expand Down
1 change: 1 addition & 0 deletions packages/auth/src/model/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export interface UserParameters {
isAnonymous?: boolean | null;
emailVerified?: boolean | null;
tenantId?: string | null;
providerData?: MutableUserInfo[] | null;

createdAt?: string | null;
lastLoginAt?: string | null;
Expand Down

0 comments on commit af92348

Please sign in to comment.