Skip to content

Commit 49dcd5c

Browse files
committed
Deep copy user's custom claims
1 parent f813f12 commit 49dcd5c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ MockFirebaseUser.msg_tokenIssuedInTheFuture =
3636
MockFirebaseUser.prototype.clone = function () {
3737
var user = new MockFirebaseUser(this._auth, this);
3838
user._idtoken = this._idtoken;
39-
user.customClaims = this.customClaims;
39+
user.customClaims = _.cloneDeep(this.customClaims);
4040
return user;
4141
};
4242

test/unit/user.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ describe('User', function() {
7070
});
7171
});
7272

73+
describe('#clone', function() {
74+
it('deep copies custom claims', () => {
75+
const ogClaims = { claim1: 'value1' };
76+
const claims = _cloneDeep(ogClaims);
77+
const u1 = new User(auth, { customClaims: claims });
78+
const u2 = u1.clone();
79+
u2.customClaims.claim1 = 'value2';
80+
expect(u1.customClaims).to.deep.equal(ogClaims);
81+
});
82+
});
83+
7384
describe('#delete', function() {
7485
it('should delete user', function() {
7586
return auth.createUser({

0 commit comments

Comments
 (0)