Skip to content

Commit

Permalink
fix: optional auth metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
jannyHou authored and Janny committed Jan 9, 2019
1 parent 5a670ef commit 6145e54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ import {AuthenticationMetadata, getAuthenticateMetadata} from '../decorators';
export class AuthMetadataProvider
implements Provider<AuthenticationMetadata | undefined> {
constructor(
@inject(CoreBindings.CONTROLLER_CLASS)
@inject(CoreBindings.CONTROLLER_CLASS, {optional: true})
private readonly controllerClass: Constructor<{}>,
@inject(CoreBindings.CONTROLLER_METHOD_NAME)
@inject(CoreBindings.CONTROLLER_METHOD_NAME, {optional: true})
private readonly methodName: string,
) {}

/**
* @returns AuthenticationMetadata
*/
value(): AuthenticationMetadata | undefined {
if (!this.controllerClass || !this.methodName) return;
return getAuthenticateMetadata(this.controllerClass, this.methodName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ describe('AuthMetadataProvider', () => {
);
expect(authMetadata).to.be.undefined();
});

it('returns undefined when the class or method is missing', async () => {
const context: Context = new Context();
context
.bind(CoreBindings.CONTROLLER_METHOD_META)
.toProvider(AuthMetadataProvider);
const authMetadata = await context.get(
CoreBindings.CONTROLLER_METHOD_META,
);
expect(authMetadata).to.be.undefined();
});
});
});

Expand Down

0 comments on commit 6145e54

Please sign in to comment.