-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Open
Labels
DocsIoC/Context@loopback/context: Dependency Injection, Inversion of Control@loopback/context: Dependency Injection, Inversion of Controldeveloper-experienceIssues affecting ease of use and overall experience of LB usersIssues affecting ease of use and overall experience of LB usersgood first issue
Description
In https://loopback.io/doc/en/lb4/Interceptors.html#example-interceptors
there are different examples of interceptors.
To understand the example implementations of these interceptors, let's
also show an example implementation of what they are intercepting.
For example:
/**
* A binding provider class to produce an interceptor that validates the
* `name` argument
*/
class NameValidator implements Provider<Interceptor> {
constructor(@inject('valid-names') private validNames: string[]) {}
value() {
return this.intercept.bind(this);
}
// (doc improvement)
// This interceptor works as an authorizer for certain endpoints,
// which takes in the first argument as the name.
async intercept<T>(
invocationCtx: InvocationContext,
next: () => ValueOrPromise<T>,
) {
const name = invocationCtx.args[0];
if (!this.validNames.includes(name)) {
throw new Error(
`Name '${name}' is not on the list of '${this.validNames}`,
);
}
return next();
}
}It is not clear what this interceptor is attached to. Is it a function, a class, a request?
How do we know that the name we need to validate is in args[0] of the invocation context?
Providing more implementation details would shed some light on how to use them.
See Reporting Issues for more tips on writing good issues
Acceptane Criteria
- Refine the docs to include more details described above.
- For the example snippet, it implies we need to add more details to
InvocationContext's properties, likeargs, see https://loopback.io/doc/en/lb4/apidocs.context.invocationcontext.html#properties
ddsultan
Metadata
Metadata
Assignees
Labels
DocsIoC/Context@loopback/context: Dependency Injection, Inversion of Control@loopback/context: Dependency Injection, Inversion of Controldeveloper-experienceIssues affecting ease of use and overall experience of LB usersIssues affecting ease of use and overall experience of LB usersgood first issue