From ee8c18a393a2345ef17e531bf82d06d7f6542271 Mon Sep 17 00:00:00 2001 From: Sam Olsen Date: Wed, 26 Jan 2022 13:16:25 -0800 Subject: [PATCH 1/2] Add missing initializer for providerData to UserImpl --- packages/auth/src/core/user/user_impl.test.ts | 16 ++++++++++++++++ packages/auth/src/core/user/user_impl.ts | 9 +++++---- packages/auth/src/model/user.ts | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/packages/auth/src/core/user/user_impl.test.ts b/packages/auth/src/core/user/user_impl.test.ts index c39bd85210f..0657ffb64c3 100644 --- a/packages/auth/src/core/user/user_impl.test.ts +++ b/packages/auth/src/core/user/user_impl.test.ts @@ -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' }); @@ -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' + }]); }); }); }); diff --git a/packages/auth/src/core/user/user_impl.ts b/packages/auth/src/core/user/user_impl.ts index 2d7ab45710a..65130dffe73 100644 --- a/packages/auth/src/core/user/user_impl.ts +++ b/packages/auth/src/core/user/user_impl.ts @@ -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; @@ -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 diff --git a/packages/auth/src/model/user.ts b/packages/auth/src/model/user.ts index 2974fa1777b..fd80b4ad212 100644 --- a/packages/auth/src/model/user.ts +++ b/packages/auth/src/model/user.ts @@ -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; From dfd5ae562cf829631d05a791e30ab7d28e4a15e8 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 26 Jan 2022 13:22:03 -0800 Subject: [PATCH 2/2] Changeset --- .changeset/curvy-brooms-clean.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/curvy-brooms-clean.md diff --git a/.changeset/curvy-brooms-clean.md b/.changeset/curvy-brooms-clean.md new file mode 100644 index 00000000000..874fe35e8ea --- /dev/null +++ b/.changeset/curvy-brooms-clean.md @@ -0,0 +1,5 @@ +--- +"@firebase/auth": patch +--- + +Fix bug where `user.providerData` field was being improperly initialized