@@ -77,6 +77,7 @@ class ParseLiveQueryServer {
7777 this . subscriber = ParsePubSub . createSubscriber ( config ) ;
7878 this . subscriber . subscribe ( Parse . applicationId + 'afterSave' ) ;
7979 this . subscriber . subscribe ( Parse . applicationId + 'afterDelete' ) ;
80+ this . subscriber . subscribe ( Parse . applicationId + 'clearCache' ) ;
8081 // Register message handler for subscriber. When publisher get messages, it will publish message
8182 // to the subscribers and the handler will be called.
8283 this . subscriber . on ( 'message' , ( channel , messageStr ) => {
@@ -88,6 +89,10 @@ class ParseLiveQueryServer {
8889 logger . error ( 'unable to parse message' , messageStr , e ) ;
8990 return ;
9091 }
92+ if ( channel === Parse . applicationId + 'clearCache' ) {
93+ this . _clearCachedRoles ( message . userId ) ;
94+ return ;
95+ }
9196 this . _inflateParseObject ( message ) ;
9297 if ( channel === Parse . applicationId + 'afterSave' ) {
9398 this . _onAfterSave ( message ) ;
@@ -474,6 +479,32 @@ class ParseLiveQueryServer {
474479 return matchesQuery ( parseObject , subscription . query ) ;
475480 }
476481
482+ async _clearCachedRoles ( userId : string ) {
483+ try {
484+ const validTokens = await new Parse . Query ( Parse . Session )
485+ . equalTo ( 'user' , Parse . User . createWithoutData ( userId ) )
486+ . find ( { useMasterKey : true } ) ;
487+ await Promise . all (
488+ validTokens . map ( async token => {
489+ const sessionToken = token . get ( 'sessionToken' ) ;
490+ const authPromise = this . authCache . get ( sessionToken ) ;
491+ if ( ! authPromise ) {
492+ return ;
493+ }
494+ const [ auth1 , auth2 ] = await Promise . all ( [
495+ authPromise ,
496+ getAuthForSessionToken ( { cacheController : this . cacheController , sessionToken } ) ,
497+ ] ) ;
498+ auth1 . auth ?. clearRoleCache ( sessionToken ) ;
499+ auth2 . auth ?. clearRoleCache ( sessionToken ) ;
500+ this . authCache . del ( sessionToken ) ;
501+ } )
502+ ) ;
503+ } catch ( e ) {
504+ logger . verbose ( `Could not clear role cache. ${ e } ` ) ;
505+ }
506+ }
507+
477508 getAuthForSessionToken ( sessionToken : ?string ) : Promise < { auth: ?Auth , userId : ?string } > {
478509 if ( ! sessionToken ) {
479510 return Promise . resolve ( { } ) ;
@@ -580,7 +611,6 @@ class ParseLiveQueryServer {
580611 if ( ! acl_has_roles ) {
581612 return false ;
582613 }
583-
584614 const roleNames = await auth . getUserRoles ( ) ;
585615 // Finally, see if any of the user's roles allow them read access
586616 for ( const role of roleNames ) {
0 commit comments