diff --git a/.changeset/fluffy-seas-behave.md b/.changeset/fluffy-seas-behave.md new file mode 100644 index 00000000000..073429be5d8 --- /dev/null +++ b/.changeset/fluffy-seas-behave.md @@ -0,0 +1,5 @@ +--- +"@firebase/auth": patch +--- + +Explicitly set createdAt and lastLoginAt when cloning UserImpl diff --git a/packages/auth/src/core/user/user_impl.test.ts b/packages/auth/src/core/user/user_impl.test.ts index 839dc104547..fc0361d8f59 100644 --- a/packages/auth/src/core/user/user_impl.test.ts +++ b/packages/auth/src/core/user/user_impl.test.ts @@ -274,7 +274,9 @@ describe('core/user/user_impl', () => { uid: 'i-am-uid' } ], - tenantId: 'tenant-id' + tenantId: 'tenant-id', + createdAt: '2018-01-01 13:02:56.12345678', + lastLoginAt: '2018-01-05 13:02:56.12345678' }); const newAuth = await testAuth(); @@ -294,6 +296,7 @@ describe('core/user/user_impl', () => { uid: 'i-am-uid' } ]); + expect(copy.metadata.toJSON()).to.eql(user.metadata.toJSON()); }); }); }); diff --git a/packages/auth/src/core/user/user_impl.ts b/packages/auth/src/core/user/user_impl.ts index 65130dffe73..44192cc4617 100644 --- a/packages/auth/src/core/user/user_impl.ts +++ b/packages/auth/src/core/user/user_impl.ts @@ -140,11 +140,13 @@ export class UserImpl implements UserInternal { } _clone(auth: AuthInternal): UserInternal { - return new UserImpl({ + const newUser = new UserImpl({ ...this, auth, stsTokenManager: this.stsTokenManager._clone() }); + newUser.metadata._copy(this.metadata); + return newUser; } _onReload(callback: NextFn): void {