File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -346,6 +346,9 @@ module.exports = function(User) {
346346 } ;
347347
348348 User . observe ( 'before delete' , function ( ctx , next ) {
349+ // Do nothing when the access control was disabled for this user model.
350+ if ( ! ctx . Model . relations . accessTokens ) return next ( ) ;
351+
349352 var AccessToken = ctx . Model . relations . accessTokens . modelTo ;
350353 var pkName = ctx . Model . definition . idName ( ) || 'id' ;
351354 ctx . Model . find ( { where : ctx . where , fields : [ pkName ] } , function ( err , list ) {
Original file line number Diff line number Diff line change @@ -299,6 +299,23 @@ describe('User', function() {
299299 } ) ;
300300 } ) ;
301301
302+ it ( 'skips token invalidation when the relation is not configured' , ( ) => {
303+ const app = loopback ( { localRegistry : true , loadBuiltinModels : true } ) ;
304+ app . dataSource ( 'db' , { connector : 'memory' } ) ;
305+
306+ const PrivateUser = app . registry . createModel ( {
307+ name : 'PrivateUser' ,
308+ base : 'User' ,
309+ // Speed up the password hashing algorithm for tests
310+ saltWorkFactor : 4 ,
311+ } ) ;
312+ app . model ( PrivateUser , { dataSource : 'db' } ) ;
313+
314+ return PrivateUser . create ( { email : 'private@example.com' , password : 'pass' } )
315+ . then ( u => PrivateUser . deleteById ( u . id ) ) ;
316+ // the test passed when the operation did not crash
317+ } ) ;
318+
302319 it ( 'invalidates the user\'s accessToken when the user is deleted all' , function ( done ) {
303320 var userIds = [ ] ;
304321 var users ;
You can’t perform that action at this time.
0 commit comments