@@ -11,21 +11,21 @@ import { inject } from '@loopback/core';
1111import { AuthenticationBindings , AuthenticationMetadata } from '@loopback/authentication' ;
1212import { RequiredPermissions , MyUserProfile } from '../types' ;
1313
14- import { intersection } from 'lodash' ;
14+ import { intersection } from 'lodash' ;
1515import { HttpErrors } from '@loopback/rest' ;
1616
1717/**
1818 * This class will be bound to the application as an `Interceptor` during
1919 * `boot`
2020 */
21- @globalInterceptor ( '' , { tags : { name : 'authorize' } } )
21+ @globalInterceptor ( '' , { tags : { name : 'authorize' } } )
2222export class AuthorizeInterceptor implements Provider < Interceptor > {
2323 constructor (
2424 @inject ( AuthenticationBindings . METADATA )
2525 public metadata : AuthenticationMetadata ,
2626 @inject . getter ( AuthenticationBindings . CURRENT_USER )
2727 public getCurrentUser : Getter < MyUserProfile >
28- ) { }
28+ ) { }
2929
3030 /**
3131 * This method is used by LoopBack context to produce an interceptor function
@@ -56,10 +56,11 @@ export class AuthorizeInterceptor implements Provider<Interceptor> {
5656 const user = await this . getCurrentUser ( ) ;
5757 console . log ( "User Permissions: " , user . permissions )
5858 const results = intersection ( user . permissions , requiredPermissions . required ) . length ;
59- if ( results !== requiredPermissions . required . length ) {
59+ // if (results !== requiredPermissions.required.length) {
60+ if ( ! results ) {
6061 throw new HttpErrors . Forbidden ( 'INVALID ACCESS PERMISSIONS' )
6162 }
62-
63+
6364 return result ;
6465 } catch ( err ) {
6566 // Add error handling logic here
0 commit comments