@@ -11,7 +11,7 @@ import SchemaController from '../Controllers/SchemaController';
11
11
import _ from 'lodash' ;
12
12
import uuid from 'uuid' ;
13
13
import { runLiveQueryEventHandlers } from '../triggers' ;
14
- import { getAuthForSessionToken } from '../Auth' ;
14
+ import { getAuthForSessionToken , Auth } from '../Auth' ;
15
15
import { getCacheController } from '../Controllers' ;
16
16
17
17
class ParseLiveQueryServer {
@@ -333,11 +333,12 @@ class ParseLiveQueryServer {
333
333
return matchesQuery ( parseObject , subscription . query ) ;
334
334
}
335
335
336
- async getUserId ( sessionToken : ?string ) : ? string {
336
+ async getAuthForSessionToken ( sessionToken : ?string ) : { auth: ? Auth , userId : ? string } {
337
337
try {
338
338
const auth = await getAuthForSessionToken ( { cacheController : this . cacheController , sessionToken : sessionToken } ) ;
339
- return auth && auth . user && auth . user . id ; // return the ID of the found user
339
+ return { auth, userId : auth && auth . user && auth . user . id } // return the ID of the found user
340
340
} catch ( e ) { /* ignore errors */ }
341
+ return { } ;
341
342
}
342
343
343
344
async _matchesCLP ( classLevelPermissions : ?any , object : any , client : any , requestId : number , op : string) : any {
@@ -348,7 +349,7 @@ class ParseLiveQueryServer {
348
349
}
349
350
const subscriptionSessionToken = subscriptionInfo . sessionToken ;
350
351
const aclGroup = [ '*' ] ;
351
- const userId = await this . getUserId ( subscriptionSessionToken ) ;
352
+ const { userId } = await this . getAuthForSessionToken ( subscriptionSessionToken ) ;
352
353
if ( userId ) {
353
354
aclGroup . push ( userId ) ;
354
355
}
@@ -391,7 +392,7 @@ class ParseLiveQueryServer {
391
392
392
393
const subscriptionSessionToken = subscriptionInfo . sessionToken ;
393
394
// TODO: get auth there and de-duplicate code below to work with the same Auth obj.
394
- const userId = await this . getUserId ( subscriptionSessionToken ) ;
395
+ const { auth , userId } = await this . getAuthForSessionToken ( subscriptionSessionToken ) ;
395
396
const isSubscriptionSessionTokenMatched = acl . getReadAccess ( userId ) ;
396
397
if ( isSubscriptionSessionTokenMatched ) {
397
398
return Promise . resolve ( true ) ;
@@ -406,7 +407,6 @@ class ParseLiveQueryServer {
406
407
return false ;
407
408
}
408
409
409
- const auth = await getAuthForSessionToken ( { cacheController : this . cacheController , sessionToken : subscriptionSessionToken } ) ;
410
410
const roleNames = await auth . getUserRoles ( ) ;
411
411
// Finally, see if any of the user's roles allow them read access
412
412
for ( const role of roleNames ) {
@@ -425,7 +425,7 @@ class ParseLiveQueryServer {
425
425
// Check client sessionToken matches ACL
426
426
const clientSessionToken = client . sessionToken ;
427
427
if ( clientSessionToken ) {
428
- const userId = await this . getUserId ( clientSessionToken ) ;
428
+ const { userId } = await this . getAuthForSessionToken ( clientSessionToken ) ;
429
429
return acl . getReadAccess ( userId ) ;
430
430
} else {
431
431
return isRoleMatched ;
0 commit comments