Skip to content

Commit c914d49

Browse files
committed
fixed permissions issue
1 parent 4ee213c commit c914d49

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/interceptors/authorize.interceptor.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ import { inject } from '@loopback/core';
1111
import { AuthenticationBindings, AuthenticationMetadata } from '@loopback/authentication';
1212
import { RequiredPermissions, MyUserProfile } from '../types';
1313

14-
import {intersection} from 'lodash';
14+
import { intersection } from 'lodash';
1515
import { 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' } })
2222
export 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

Comments
 (0)