-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The key controller.current.ctor was not bound to any value. #1144
Comments
@NiklasA It would be helpful if you can either describe steps to reproduce the problem or having a sandbox repo to contain the test app. |
Hi @raymondfeng, I found my issue. The problem was that I integrated Before: async handle(req: ParsedRequest, res: ServerResponse) {
// we define these variable outside of try / catch so that they can be accessed by logger.
let args: any = [];
let result: any;
// this is the important line added to the default sequence implementation.
await this.authenticateRequest(req);
// optionally start timing the sequence using the timer function available via LogFn.
const start = this.logger.startTimer();
try {
const route = this.findRoute(req); After: async handle(req: ParsedRequest, res: ServerResponse) {
// we define these variable outside of try / catch so that they can be accessed by logger.
let args: any = [];
let result: any;
// optionally start timing the sequence using the timer function available via LogFn.
const start = this.logger.startTimer();
try {
const route = this.findRoute(req);
// this is the important line added to the default sequence implementation.
await this.authenticateRequest(req); The second mistake was, that I injected Thank you in advance. |
Please note we use a hierarchy of contexts, for example, a request context is created per http request and it uses the app context as the parent. Binding |
@raymondfeng @dhmlau @NiklasA Hello, what's the status of this issue? What actions are needed before we can closed this as done? |
Hi @bajtos, it can be closed, I made a mistake described in comment above. |
I have the same issue here, and I solved it in other way. The exact error is:
Problem with previous try/catch solution (from @NiklasA #1144 (comment)): It'll fails with static routes (If you use them), because it puts the My final solution: After following this tutorial for authentication, I figured out that the problem only occurs when you try to get a static route. My solution was to check if the requested route is static (or not) before do the This is my final (for now) sequence.ts: import { inject } from '@loopback/context';
import {
FindRoute,
InvokeMethod,
ParseParams,
Reject,
RequestContext,
RestBindings,
Send,
SequenceHandler,
StaticAssetsRoute,
} from '@loopback/rest';
import { AuthenticationBindings, AuthenticateFn } from '@loopback/authentication';
import { VerifyUserRoleBindings, VerifyUserRoleFn, UserRoleData } from './components/verify-user-role';
const SequenceActions = RestBindings.SequenceActions;
export class MySequence implements SequenceHandler {
constructor(
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) public send: Send,
@inject(SequenceActions.REJECT) public reject: Reject,
@inject(AuthenticationBindings.AUTH_ACTION) protected authenticateRequest: AuthenticateFn,
@inject(VerifyUserRoleBindings.ROLE_ACTION) protected verifyUserRole: VerifyUserRoleFn,
) { }
async handle(context: RequestContext) {
try {
const { request, response } = context;
const route = this.findRoute(request);
// !!IMPORTANT: authenticateRequest fails on static routes!
if (!(route instanceof StaticAssetsRoute)) {
// Verify authentication cases
const user = await this.authenticateRequest(request);
// Verify user roles cases
await this.verifyUserRole(<UserRoleData>user)
}
const args = await this.parseParams(request, route);
const result = await this.invoke(route, args);
this.send(response, result);
} catch (err) {
this.reject(context, err);
}
}
} |
Good catch, @NiklasA. I was aware that we may break the applications assuming that 404 is thrown by Perhaps we should improve the documentation on routing and Most importantly, I think we need to fix our reference Is my assessment correct? @dhmlau I am proposing to open new issue(s) for each of the logical change/fix we need to make, and then close this issue again. Having a fine-grained user stories is easier for planning and keeping track of our progress. |
@jormar answer solved my issue too. |
same problem here, @jormar answer solved it. |
it's VERY important the @jormar information about static routes. The code at https://github.com/strongloop/loopback-next/tree/master/packages/authentication worked before the recent update of loopback 4, that now the root is mapped to /public. |
FYI this should be fixed in #2218 Released as @loopback/[email protected] |
I am closing this issue as solved. Feel free to reopen it if you still run into the same problem |
Description / Steps to reproduce / Feature proposal:
Hi everyone,
I added @loopback/authentication to my LoopBack 4 application (like descriped in README.md and I always get the error: "The key controller.current.ctor was not bound to any value.". Does anyone know what I have to do, any hint, where I have to look? Thanks in advance!
Current Behavior:
Every time, when I call my TestController:
curl -u username:password http://localhost:3000/whoami
. I get the following error: Error: The key controller.current.ctor was not bound to any value.The text was updated successfully, but these errors were encountered: