@@ -170,8 +170,10 @@ class ParseLiveQueryServer {
170
170
} ;
171
171
const trigger = getTrigger ( className , 'afterEvent' , Parse . applicationId ) ;
172
172
if ( trigger ) {
173
- const auth = await this . getAuthForSessionToken ( res . sessionToken ) ;
174
- res . user = auth . user ;
173
+ const auth = await this . getAuthFromClient ( client , requestId ) ;
174
+ if ( auth && auth . user ) {
175
+ res . user = auth . user ;
176
+ }
175
177
if ( res . object ) {
176
178
res . object = Parse . Object . fromJSON ( res . object ) ;
177
179
}
@@ -317,8 +319,10 @@ class ParseLiveQueryServer {
317
319
if ( res . original ) {
318
320
res . original = Parse . Object . fromJSON ( res . original ) ;
319
321
}
320
- const auth = await this . getAuthForSessionToken ( res . sessionToken ) ;
321
- res . user = auth . user ;
322
+ const auth = await this . getAuthFromClient ( client , requestId ) ;
323
+ if ( auth && auth . user ) {
324
+ res . user = auth . user ;
325
+ }
322
326
await runTrigger ( trigger , `afterEvent.${ className } ` , res , auth ) ;
323
327
}
324
328
if ( ! res . sendEvent ) {
@@ -579,6 +583,24 @@ class ParseLiveQueryServer {
579
583
} ) ;
580
584
}
581
585
586
+ async getAuthFromClient ( client : any , requestId : number , sessionToken : string ) {
587
+ const getSessionFromClient = ( ) => {
588
+ const subscriptionInfo = client . getSubscriptionInfo ( requestId ) ;
589
+ if ( typeof subscriptionInfo === 'undefined' ) {
590
+ return client . sessionToken ;
591
+ }
592
+ return subscriptionInfo . sessionToken || client . sessionToken ;
593
+ } ;
594
+ if ( ! sessionToken ) {
595
+ sessionToken = getSessionFromClient ( ) ;
596
+ }
597
+ if ( ! sessionToken ) {
598
+ return ;
599
+ }
600
+ const { auth } = await this . getAuthForSessionToken ( sessionToken ) ;
601
+ return auth ;
602
+ }
603
+
582
604
async _matchesACL ( acl : any , client : any , requestId : number) : Promise < boolean > {
583
605
// Return true directly if ACL isn't present, ACL is public read, or client has master key
584
606
if ( ! acl || acl . getPublicReadAccess ( ) || client . hasMasterKey ) {
@@ -631,8 +653,10 @@ class ParseLiveQueryServer {
631
653
} ;
632
654
const trigger = getTrigger ( '@Connect' , 'beforeConnect' , Parse . applicationId ) ;
633
655
if ( trigger ) {
634
- const auth = await this . getAuthForSessionToken ( req . sessionToken ) ;
635
- req . user = auth . user ;
656
+ const auth = await this . getAuthFromClient ( client , request . requestId , req . sessionToken ) ;
657
+ if ( auth && auth . user ) {
658
+ req . user = auth . user ;
659
+ }
636
660
await runTrigger ( trigger , `beforeConnect.@Connect` , req , auth ) ;
637
661
}
638
662
parseWebsocket . clientId = clientId ;
@@ -690,8 +714,10 @@ class ParseLiveQueryServer {
690
714
try {
691
715
const trigger = getTrigger ( className , 'beforeSubscribe' , Parse . applicationId ) ;
692
716
if ( trigger ) {
693
- const auth = await this . getAuthForSessionToken ( request . sessionToken ) ;
694
- request . user = auth . user ;
717
+ const auth = await this . getAuthFromClient ( client , request . requestId , request . sessionToken ) ;
718
+ if ( auth && auth . user ) {
719
+ request . user = auth . user ;
720
+ }
695
721
696
722
const parseQuery = new Parse . Query ( className ) ;
697
723
parseQuery . withJSON ( request . query ) ;
0 commit comments