Skip to content

Commit

Permalink
Explicitly set createdAt and lastLoginAt when cloning UserImpl (#7066)
Browse files Browse the repository at this point in the history
* Explicilty set createdAt and lastLoginAt when cloning UserImpl

* Use metadata._copy instead of manually setting metadata

* Fix test case for user_imply _clone function

* Create fluffy-seas-behave.md

---------

Co-authored-by: prameshj <pavithrar@google.com>
  • Loading branch information
2 people authored and renkelvin committed Mar 21, 2023
1 parent 927e37c commit 7f12ca1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-seas-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@firebase/auth": patch
---

Explicitly set createdAt and lastLoginAt when cloning UserImpl
5 changes: 4 additions & 1 deletion packages/auth/src/core/user/user_impl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -294,6 +296,7 @@ describe('core/user/user_impl', () => {
uid: 'i-am-uid'
}
]);
expect(copy.metadata.toJSON()).to.eql(user.metadata.toJSON());
});
});
});
4 changes: 3 additions & 1 deletion packages/auth/src/core/user/user_impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<APIUserInfo>): void {
Expand Down

0 comments on commit 7f12ca1

Please sign in to comment.