@@ -81,6 +81,8 @@ RestWrite.prototype.execute = function() {
81
81
return this . transformUser ( ) ;
82
82
} ) . then ( ( ) => {
83
83
return this . expandFilesForExistingObjects ( ) ;
84
+ } ) . then ( ( ) => {
85
+ return this . destroyDuplicatedSessions ( ) ;
84
86
} ) . then ( ( ) => {
85
87
return this . runDatabaseOperation ( ) ;
86
88
} ) . then ( ( ) => {
@@ -588,17 +590,31 @@ RestWrite.prototype.createSessionToken = function() {
588
590
this . response . response . sessionToken = token ;
589
591
}
590
592
593
+ return new RestWrite ( this . config , Auth . master ( this . config ) , '_Session' , null , sessionData ) . execute ( ) ;
594
+ }
595
+
596
+ RestWrite . prototype . destroyDuplicatedSessions = function ( ) {
597
+ // Only for _Session, and at creation time
598
+ if ( this . className != '_Session' || this . query ) {
599
+ return ;
600
+ }
591
601
// Destroy the sessions in 'Background'
602
+ const {
603
+ user,
604
+ installationId,
605
+ sessionToken,
606
+ } = this . data ;
607
+ if ( ! user || ! installationId ) {
608
+ return ;
609
+ }
610
+ if ( ! user . objectId ) {
611
+ return ;
612
+ }
592
613
this . config . database . destroy ( '_Session' , {
593
- user : {
594
- __type : 'Pointer' ,
595
- className : '_User' ,
596
- objectId : this . objectId ( )
597
- } ,
598
- installationId : this . auth . installationId ,
599
- sessionToken : { '$ne' : token } ,
614
+ user,
615
+ installationId,
616
+ sessionToken : { '$ne' : sessionToken } ,
600
617
} ) ;
601
- return new RestWrite ( this . config , Auth . master ( this . config ) , '_Session' , null , sessionData ) . execute ( ) ;
602
618
}
603
619
604
620
// Handles any followup logic
0 commit comments