Skip to content

Commit a861c4e

Browse files
hmoqhimflovilmart
authored andcommitted
Fix issue #2134: creating an anonymous user (#2155)
* fix issue #2134 * username is returned only when generated * fix unit tests * incorporate @flovilmart review
1 parent 2a4fbf7 commit a861c4e

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

spec/RestCreate.spec.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ describe('rest create', () => {
143143
expect(typeof r.response.objectId).toEqual('string');
144144
expect(typeof r.response.createdAt).toEqual('string');
145145
expect(typeof r.response.sessionToken).toEqual('string');
146+
expect(typeof r.response.username).toEqual('string');
146147
return rest.create(config, auth.nobody(config), '_User', data1);
147148
}).then((r) => {
148149
expect(typeof r.response.objectId).toEqual('string');

src/RestWrite.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ RestWrite.prototype.transformUser = function() {
351351
if (!this.data.username) {
352352
if (!this.query) {
353353
this.data.username = cryptoUtils.randomString(25);
354+
this.responseShouldHaveUsername = true;
354355
}
355356
return;
356357
}
@@ -790,6 +791,10 @@ RestWrite.prototype.runDatabaseOperation = function() {
790791
.then(response => {
791792
response.objectId = this.data.objectId;
792793
response.createdAt = this.data.createdAt;
794+
795+
if (this.responseShouldHaveUsername) {
796+
response.username = this.data.username;
797+
}
793798
if (this.storage.changedByTrigger) {
794799
Object.keys(this.data).forEach(fieldName => {
795800
response[fieldName] = response[fieldName] || this.data[fieldName];

0 commit comments

Comments
 (0)