@@ -79,6 +79,8 @@ RestWrite.prototype.execute = function() {
79
79
return this . expandFilesForExistingObjects ( ) ;
80
80
} ) . then ( ( ) => {
81
81
return this . runDatabaseOperation ( ) ;
82
+ } ) . then ( ( ) => {
83
+ return this . createSessionTokenIfNeeded ( ) ;
82
84
} ) . then ( ( ) => {
83
85
return this . handleFollowup ( ) ;
84
86
} ) . then ( ( ) => {
@@ -316,35 +318,6 @@ RestWrite.prototype.transformUser = function() {
316
318
317
319
var promise = Promise . resolve ( ) ;
318
320
319
- if ( ! this . query ) {
320
- var token = 'r:' + cryptoUtils . newToken ( ) ;
321
- this . storage [ 'token' ] = token ;
322
- promise = promise . then ( ( ) => {
323
- var expiresAt = this . config . generateSessionExpiresAt ( ) ;
324
- var sessionData = {
325
- sessionToken : token ,
326
- user : {
327
- __type : 'Pointer' ,
328
- className : '_User' ,
329
- objectId : this . objectId ( )
330
- } ,
331
- createdWith : {
332
- 'action' : 'signup' ,
333
- 'authProvider' : this . storage [ 'authProvider' ] || 'password'
334
- } ,
335
- restricted : false ,
336
- installationId : this . auth . installationId ,
337
- expiresAt : Parse . _encode ( expiresAt )
338
- } ;
339
- if ( this . response && this . response . response ) {
340
- this . response . response . sessionToken = token ;
341
- }
342
- var create = new RestWrite ( this . config , Auth . master ( this . config ) ,
343
- '_Session' , null , sessionData ) ;
344
- return create . execute ( ) ;
345
- } ) ;
346
- }
347
-
348
321
// If we're updating a _User object, clear the user cache for the session
349
322
if ( this . query && this . auth . user && this . auth . user . getSessionToken ( ) ) {
350
323
cache . users . remove ( this . auth . user . getSessionToken ( ) ) ;
@@ -412,6 +385,39 @@ RestWrite.prototype.transformUser = function() {
412
385
} ) ;
413
386
} ;
414
387
388
+ RestWrite . prototype . createSessionTokenIfNeeded = function ( ) {
389
+ if ( this . className !== '_User' ) {
390
+ return ;
391
+ }
392
+ if ( this . query ) {
393
+ return ;
394
+ }
395
+ var token = 'r:' + cryptoUtils . newToken ( ) ;
396
+
397
+ var expiresAt = this . config . generateSessionExpiresAt ( ) ;
398
+ var sessionData = {
399
+ sessionToken : token ,
400
+ user : {
401
+ __type : 'Pointer' ,
402
+ className : '_User' ,
403
+ objectId : this . objectId ( )
404
+ } ,
405
+ createdWith : {
406
+ 'action' : 'signup' ,
407
+ 'authProvider' : this . storage [ 'authProvider' ] || 'password'
408
+ } ,
409
+ restricted : false ,
410
+ installationId : this . auth . installationId ,
411
+ expiresAt : Parse . _encode ( expiresAt )
412
+ } ;
413
+ if ( this . response && this . response . response ) {
414
+ this . response . response . sessionToken = token ;
415
+ }
416
+ var create = new RestWrite ( this . config , Auth . master ( this . config ) ,
417
+ '_Session' , null , sessionData ) ;
418
+ return create . execute ( ) ;
419
+ }
420
+
415
421
// Handles any followup logic
416
422
RestWrite . prototype . handleFollowup = function ( ) {
417
423
@@ -775,9 +781,6 @@ RestWrite.prototype.runDatabaseOperation = function() {
775
781
return memo ;
776
782
} , resp ) ;
777
783
}
778
- if ( this . storage [ 'token' ] ) {
779
- resp . sessionToken = this . storage [ 'token' ] ;
780
- }
781
784
this . response = {
782
785
status : 201 ,
783
786
response : resp ,
0 commit comments